diff options
-rw-r--r-- | gfx/gl/program.h | 2 | ||||
-rw-r--r-- | gfx/gl/shader.cpp | 15 | ||||
-rw-r--r-- | gfx/gl/shader.h | 5 |
3 files changed, 10 insertions, 12 deletions
diff --git a/gfx/gl/program.h b/gfx/gl/program.h index f14b0f3..eb10888 100644 --- a/gfx/gl/program.h +++ b/gfx/gl/program.h @@ -12,7 +12,7 @@ class Program { public: template<typename... S> Program(const S &... srcs) { - (glAttachShader(m_program, srcs), ...); + (glAttachShader(m_program, srcs.compile()), ...); linkAndValidate(); } virtual ~Program() = default; diff --git a/gfx/gl/shader.cpp b/gfx/gl/shader.cpp index 8b0f614..5f83b83 100644 --- a/gfx/gl/shader.cpp +++ b/gfx/gl/shader.cpp @@ -3,16 +3,15 @@ #include <stdexcept> #include <string> -Shader::operator GLuint() const +Shader::ShaderRef +Shader::compile() const { - if (!shader) { - shader.emplace(type); - glShaderSource(*shader, 1, &text, &len); - glCompileShader(*shader); + ShaderRef shader {type}; + glShaderSource(shader, 1, &text, &len); + glCompileShader(shader); - CheckShaderError(*shader, GL_COMPILE_STATUS, false, "Error compiling shader!"); - } - return *shader; + CheckShaderError(shader, GL_COMPILE_STATUS, false, "Error compiling shader!"); + return shader; } void diff --git a/gfx/gl/shader.h b/gfx/gl/shader.h index 1a8ddef..a20636d 100644 --- a/gfx/gl/shader.h +++ b/gfx/gl/shader.h @@ -7,15 +7,14 @@ class Shader { public: + using ShaderRef = glRef<GLuint, &__glewCreateShader, &__glewDeleteShader>; constexpr Shader(const GLchar * text, GLint len, GLuint type) : text {text}, len {len}, type {type} { } - operator GLuint() const; + ShaderRef compile() const; static void CheckShaderError(GLuint shader, GLuint flag, bool isProgram, std::string_view errorMessage); private: - using ShaderRef = glRef<GLuint, &__glewCreateShader, &__glewDeleteShader>; const GLchar * text; GLint len; GLuint type; - mutable std::optional<ShaderRef> shader {}; }; |