From b95cf46bed86e4d0641f7862cfe550af2bc02d60 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 20 Feb 2021 13:48:31 +0000 Subject: Remove now redundent Shader::Source class Moves compile functionality to GLsource. --- gfx/gl/shader-source.h | 5 +++++ gfx/gl/shader.cpp | 21 ++++++++++++--------- gfx/gl/shader.h | 12 +----------- 3 files changed, 18 insertions(+), 20 deletions(-) (limited to 'gfx') diff --git a/gfx/gl/shader-source.h b/gfx/gl/shader-source.h index 4fbbe5b..9403e80 100644 --- a/gfx/gl/shader-source.h +++ b/gfx/gl/shader-source.h @@ -2,11 +2,16 @@ #define SHADER_SOURCE_H #include +#include struct GLsource { + using ShaderRef = glRef; + const GLchar * text; GLint len; GLuint type; + + [[nodiscard]] ShaderRef compile() const; }; constexpr auto diff --git a/gfx/gl/shader.cpp b/gfx/gl/shader.cpp index badaaef..d4cb747 100644 --- a/gfx/gl/shader.cpp +++ b/gfx/gl/shader.cpp @@ -31,16 +31,16 @@ Shader::ProgramHandle::ProgramHandle(GLuint vs, GLuint fs) : viewProjection_unif Shader::Shader() : programs {{{ - Source {basicShader_vs}.id, - Source {basicShader_fs}.id, + basicShader_vs.compile(), + basicShader_fs.compile(), }, { - Source {waterShader_vs}.id, - Source {waterShader_fs}.id, + waterShader_vs.compile(), + waterShader_fs.compile(), }, { - Source {landmassShader_vs}.id, - Source {landmassShader_fs}.id, + landmassShader_vs.compile(), + landmassShader_fs.compile(), }}} { } @@ -98,10 +98,13 @@ Shader::CheckShaderError(GLuint shader, GLuint flag, bool isProgram, std::string } } -Shader::Source::Source(const GLsource src) : id {src.type} +GLsource::ShaderRef +GLsource::compile() const { - glShaderSource(id, 1, &src.text, &src.len); + ShaderRef id {type}; + glShaderSource(id, 1, &text, &len); glCompileShader(id); - CheckShaderError(id, GL_COMPILE_STATUS, false, "Error compiling shader!"); + Shader::CheckShaderError(id, GL_COMPILE_STATUS, false, "Error compiling shader!"); + return id; } diff --git a/gfx/gl/shader.h b/gfx/gl/shader.h index 293ce9b..e4904ed 100644 --- a/gfx/gl/shader.h +++ b/gfx/gl/shader.h @@ -1,7 +1,6 @@ #ifndef SHADER_INCLUDED_H #define SHADER_INCLUDED_H -#include "shader-source.h" #include #include #include @@ -18,18 +17,9 @@ public: void setModel(glm::mat4 model, Program = Program::Basic) const; void setUniform(const GLchar *, glm::vec3 dir) const; -private: - class Source { - public: - using ShaderRef = glRef; - - explicit Source(const GLsource src); - - ShaderRef id; - }; - static void CheckShaderError(GLuint shader, GLuint flag, bool isProgram, std::string_view errorMessage); +private: class ProgramHandle { public: ProgramHandle(GLuint, GLuint); -- cgit v1.2.3