From dcdff7828e1dc3b5cbfc10a30ee10c2ffec07987 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 12 Dec 2021 15:33:09 +0000 Subject: Move GL shared source into it's own class/file --- gfx/gl/shader.cpp | 41 +++-------------------------------------- 1 file changed, 3 insertions(+), 38 deletions(-) (limited to 'gfx/gl/shader.cpp') diff --git a/gfx/gl/shader.cpp b/gfx/gl/shader.cpp index 771db97..06edc5c 100644 --- a/gfx/gl/shader.cpp +++ b/gfx/gl/shader.cpp @@ -1,5 +1,5 @@ #include "shader.h" -#include "gfx/gl/shader-source.h" +#include "gfx/gl/glSource.h" #include #include #include @@ -26,10 +26,10 @@ Shader::ProgramHandle::ProgramHandle(GLuint vs, GLuint fs) : viewProjection_unif glBindAttribLocation(m_program, 2, "normal"); glLinkProgram(m_program); - CheckShaderError(m_program, GL_LINK_STATUS, true, "Error linking shader program"); + GLsource::CheckShaderError(m_program, GL_LINK_STATUS, true, "Error linking shader program"); glValidateProgram(m_program); - CheckShaderError(m_program, GL_VALIDATE_STATUS, true, "Invalid shader program"); + GLsource::CheckShaderError(m_program, GL_VALIDATE_STATUS, true, "Invalid shader program"); viewProjection_uniform = glGetUniformLocation(m_program, "viewProjection"); model_uniform = glGetUniformLocation(m_program, "model"); @@ -86,38 +86,3 @@ Shader::setModel(const Location & loc, Program pid) const } } -void -Shader::CheckShaderError(GLuint shader, GLuint flag, bool isProgram, std::string_view errorMessage) -{ - GLint success = 0; - std::array error {}; - - if (isProgram) { - glGetProgramiv(shader, flag, &success); - } - else { - glGetShaderiv(shader, flag, &success); - } - - if (success == GL_FALSE) { - if (isProgram) { - glGetProgramInfoLog(shader, error.size(), nullptr, error.data()); - } - else { - glGetShaderInfoLog(shader, error.size(), nullptr, error.data()); - } - - throw std::runtime_error {std::string {errorMessage} + ": '" + std::string {error.data(), error.size()} + "'"}; - } -} - -GLsource::ShaderRef -GLsource::compile() const -{ - ShaderRef id {type}; - glShaderSource(id, 1, &text, &len); - glCompileShader(id); - - Shader::CheckShaderError(id, GL_COMPILE_STATUS, false, "Error compiling shader!"); - return id; -} -- cgit v1.2.3