2022-06-30 12:39:10 +02:00
|
|
|
#include "Shader.hpp"
|
2025-05-11 18:36:20 +02:00
|
|
|
#include "render/OpenGL.hpp"
|
2022-06-30 12:39:10 +02:00
|
|
|
|
2025-05-08 00:07:35 +02:00
|
|
|
SShader::~SShader() {
|
2022-12-01 13:36:07 +00:00
|
|
|
destroy();
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-11 18:36:20 +02:00
|
|
|
void SShader::createVao() {
|
|
|
|
|
glGenVertexArrays(1, &shaderVao);
|
|
|
|
|
glBindVertexArray(shaderVao);
|
|
|
|
|
|
|
|
|
|
if (posAttrib != -1) {
|
|
|
|
|
glGenBuffers(1, &shaderVboPos);
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, shaderVboPos);
|
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, sizeof(fullVerts), fullVerts, GL_STATIC_DRAW);
|
|
|
|
|
glEnableVertexAttribArray(posAttrib);
|
|
|
|
|
glVertexAttribPointer(posAttrib, 2, GL_FLOAT, GL_FALSE, 0, (void*)0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// UV VBO (dynamic, may be updated per frame)
|
|
|
|
|
if (texAttrib != -1) {
|
|
|
|
|
glGenBuffers(1, &shaderVboUv);
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, shaderVboUv);
|
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, sizeof(fullVerts), fullVerts, GL_DYNAMIC_DRAW); // Initial dummy UVs
|
|
|
|
|
glEnableVertexAttribArray(texAttrib);
|
|
|
|
|
glVertexAttribPointer(texAttrib, 2, GL_FLOAT, GL_FALSE, 0, (void*)0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glBindVertexArray(0);
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-08 00:07:35 +02:00
|
|
|
void SShader::destroy() {
|
2025-02-08 01:46:26 +01:00
|
|
|
if (program == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2025-05-11 18:36:20 +02:00
|
|
|
if (shaderVao)
|
|
|
|
|
glDeleteVertexArrays(1, &shaderVao);
|
|
|
|
|
|
|
|
|
|
if (shaderVboPos)
|
|
|
|
|
glDeleteBuffers(1, &shaderVboPos);
|
2022-12-03 14:45:05 +00:00
|
|
|
|
2025-05-11 18:36:20 +02:00
|
|
|
if (shaderVboUv)
|
|
|
|
|
glDeleteBuffers(1, &shaderVboUv);
|
|
|
|
|
|
|
|
|
|
glDeleteProgram(program);
|
2022-12-03 14:45:05 +00:00
|
|
|
program = 0;
|
2025-02-08 01:46:26 +01:00
|
|
|
}
|