From c3eea71370eb94cff1fd96185458643fab6eb2c5 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 3 Nov 2022 19:47:46 +0000 Subject: Restructure how shaders are worked with Needs a tidy-up --- gfx/gl/uiShader.cpp | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) (limited to 'gfx/gl/uiShader.cpp') diff --git a/gfx/gl/uiShader.cpp b/gfx/gl/uiShader.cpp index fbcdd15..78e0064 100644 --- a/gfx/gl/uiShader.cpp +++ b/gfx/gl/uiShader.cpp @@ -1,6 +1,6 @@ #include "uiShader.h" -#include -#include +#include +#include #include #include #include @@ -8,30 +8,21 @@ #include #include -UIShader::UIShader(size_t width, size_t height) : - progDefault {uiShader_vs.compile(), uiShader_fs.compile()}, progText {uiShader_vs.compile(), - uiShaderFont_fs.compile()} +UIShader::IconProgram::IconProgram(const glm::mat4 & vp) : UIProgram {vp, uiShader_vs, uiShader_fs} { } +UIShader::TextProgram::TextProgram(const glm::mat4 & vp) : + UIProgram {vp, uiShader_vs, uiShaderFont_fs}, colorLoc {*this, "colour"} { - for (const auto prog : {&progDefault, &progText}) { - if (auto loc = glGetUniformLocation(prog->m_program, "uiProjection"); loc >= 0) { - glUseProgram(prog->m_program); - const auto uiProjection = glm::ortho(0, static_cast(width), 0, static_cast(height)); - glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(uiProjection)); - } - } } -void -UIShader::useDefault() const +UIShader::UIShader(size_t width, size_t height) : + UIShader {glm::ortho(0, static_cast(width), 0, static_cast(height))} { - glUseProgram(progDefault.m_program); } +UIShader::UIShader(const glm::mat4 & viewProjection) : icon {viewProjection}, text {viewProjection} { } void -UIShader::useText(glm::vec3 colour) const +UIShader::TextProgram::use(const glm::vec3 & colour) const { - glUseProgram(progText.m_program); - if (auto loc = glGetUniformLocation(progText.m_program, "colour"); loc >= 0) { - glUniform3fv(loc, 1, glm::value_ptr(colour)); - } + Program::use(); + glUniform3fv(colorLoc, 1, glm::value_ptr(colour)); } -- cgit v1.2.3