From f848ad0e672d913c36fcb86533cbc11a9cf9d9ea Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 3 Nov 2022 18:25:28 +0000 Subject: Rename Shader to SceneShader --- gfx/gl/sceneShader.cpp | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++ gfx/gl/sceneShader.h | 27 ++++++++++++++++++ gfx/gl/shader.cpp | 77 -------------------------------------------------- gfx/gl/shader.h | 27 ------------------ gfx/renderable.h | 4 +-- 5 files changed, 106 insertions(+), 106 deletions(-) create mode 100644 gfx/gl/sceneShader.cpp create mode 100644 gfx/gl/sceneShader.h delete mode 100644 gfx/gl/shader.cpp delete mode 100644 gfx/gl/shader.h (limited to 'gfx') diff --git a/gfx/gl/sceneShader.cpp b/gfx/gl/sceneShader.cpp new file mode 100644 index 0000000..48c0f42 --- /dev/null +++ b/gfx/gl/sceneShader.cpp @@ -0,0 +1,77 @@ +#include "sceneShader.h" +#include "gfx/gl/glSource.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +SceneShader::ProgramHandle::ProgramHandle(GLuint vs, GLuint fs) : ProgramHandleBase {vs, fs} +{ + glBindAttribLocation(m_program, 0, "position"); + glBindAttribLocation(m_program, 1, "texCoord"); + glBindAttribLocation(m_program, 2, "normal"); + + viewProjection_uniform = glGetUniformLocation(m_program, "viewProjection"); + model_uniform = glGetUniformLocation(m_program, "model"); +} + +SceneShader::SceneShader() : + programs {{{ + basicShader_vs.compile(), + basicShader_fs.compile(), + }, + { + waterShader_vs.compile(), + waterShader_fs.compile(), + }, + { + landmassShader_vs.compile(), + landmassShader_fs.compile(), + }, + { + landmassShader_vs.compile(), + basicShader_fs.compile(), + }}} +{ +} + +void +SceneShader::setView(glm::mat4 proj) const +{ + for (const auto & prog : programs) { + glUseProgram(prog.m_program); + glUniformMatrix4fv(prog.viewProjection_uniform, 1, GL_FALSE, glm::value_ptr(proj)); + } +} + +void +SceneShader::setUniform(const GLchar * uniform, glm::vec3 v) const +{ + for (const auto & prog : programs) { + if (auto loc = glGetUniformLocation(prog.m_program, uniform); loc >= 0) { + glUseProgram(prog.m_program); + glUniform3fv(loc, 1, glm::value_ptr(v)); + } + } +} + +void +SceneShader::setModel(const Location & loc, Program pid) const +{ + auto & prog = programs[static_cast(pid)]; + glUseProgram(prog.m_program); + if (prog.model_uniform >= 0) { + const auto model {glm::translate(loc.pos) * rotate_ypr(loc.rot)}; + glUniformMatrix4fv(prog.model_uniform, 1, GL_FALSE, glm::value_ptr(model)); + } +} diff --git a/gfx/gl/sceneShader.h b/gfx/gl/sceneShader.h new file mode 100644 index 0000000..61c159b --- /dev/null +++ b/gfx/gl/sceneShader.h @@ -0,0 +1,27 @@ +#pragma once + +#include "programHandle.h" +#include +#include +#include + +class Location; + +class SceneShader { +public: + enum class Program { Basic = 0, Water = 1, LandMass = 2, StaticPos = 3 }; + + SceneShader(); + + void setView(glm::mat4 view) const; + void setModel(const Location &, Program = Program::Basic) const; + void setUniform(const GLchar *, glm::vec3 dir) const; + +private: + class ProgramHandle : public ProgramHandleBase { + public: + ProgramHandle(GLuint, GLuint); + }; + + std::array programs; +}; diff --git a/gfx/gl/shader.cpp b/gfx/gl/shader.cpp deleted file mode 100644 index a196e07..0000000 --- a/gfx/gl/shader.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include "shader.h" -#include "gfx/gl/glSource.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -Shader::ProgramHandle::ProgramHandle(GLuint vs, GLuint fs) : ProgramHandleBase {vs, fs} -{ - glBindAttribLocation(m_program, 0, "position"); - glBindAttribLocation(m_program, 1, "texCoord"); - glBindAttribLocation(m_program, 2, "normal"); - - viewProjection_uniform = glGetUniformLocation(m_program, "viewProjection"); - model_uniform = glGetUniformLocation(m_program, "model"); -} - -Shader::Shader() : - programs {{{ - basicShader_vs.compile(), - basicShader_fs.compile(), - }, - { - waterShader_vs.compile(), - waterShader_fs.compile(), - }, - { - landmassShader_vs.compile(), - landmassShader_fs.compile(), - }, - { - landmassShader_vs.compile(), - basicShader_fs.compile(), - }}} -{ -} - -void -Shader::setView(glm::mat4 proj) const -{ - for (const auto & prog : programs) { - glUseProgram(prog.m_program); - glUniformMatrix4fv(prog.viewProjection_uniform, 1, GL_FALSE, glm::value_ptr(proj)); - } -} - -void -Shader::setUniform(const GLchar * uniform, glm::vec3 v) const -{ - for (const auto & prog : programs) { - if (auto loc = glGetUniformLocation(prog.m_program, uniform); loc >= 0) { - glUseProgram(prog.m_program); - glUniform3fv(loc, 1, glm::value_ptr(v)); - } - } -} - -void -Shader::setModel(const Location & loc, Program pid) const -{ - auto & prog = programs[static_cast(pid)]; - glUseProgram(prog.m_program); - if (prog.model_uniform >= 0) { - const auto model {glm::translate(loc.pos) * rotate_ypr(loc.rot)}; - glUniformMatrix4fv(prog.model_uniform, 1, GL_FALSE, glm::value_ptr(model)); - } -} diff --git a/gfx/gl/shader.h b/gfx/gl/shader.h deleted file mode 100644 index 8411b94..0000000 --- a/gfx/gl/shader.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include "programHandle.h" -#include -#include -#include - -class Location; - -class Shader { -public: - enum class Program { Basic = 0, Water = 1, LandMass = 2, StaticPos = 3 }; - - Shader(); - - void setView(glm::mat4 view) const; - void setModel(const Location &, Program = Program::Basic) const; - void setUniform(const GLchar *, glm::vec3 dir) const; - -private: - class ProgramHandle : public ProgramHandleBase { - public: - ProgramHandle(GLuint, GLuint); - }; - - std::array programs; -}; diff --git a/gfx/renderable.h b/gfx/renderable.h index 565f705..9b25645 100644 --- a/gfx/renderable.h +++ b/gfx/renderable.h @@ -2,7 +2,7 @@ #include -class Shader; +class SceneShader; class Renderable { public: @@ -10,5 +10,5 @@ public: virtual ~Renderable() = default; DEFAULT_MOVE_COPY(Renderable); - virtual void render(const Shader & shader) const = 0; + virtual void render(const SceneShader & shader) const = 0; }; -- cgit v1.2.3