summaryrefslogtreecommitdiff
path: root/gfx/gl/uiShader.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-11-03 19:47:46 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2022-11-03 19:48:31 +0000
commitc3eea71370eb94cff1fd96185458643fab6eb2c5 (patch)
treecb331dd81d9cb36d69e1b659353796ec170a78e4 /gfx/gl/uiShader.cpp
parentRename Shader to SceneShader (diff)
downloadilt-c3eea71370eb94cff1fd96185458643fab6eb2c5.tar.bz2
ilt-c3eea71370eb94cff1fd96185458643fab6eb2c5.tar.xz
ilt-c3eea71370eb94cff1fd96185458643fab6eb2c5.zip
Restructure how shaders are worked with
Needs a tidy-up
Diffstat (limited to 'gfx/gl/uiShader.cpp')
-rw-r--r--gfx/gl/uiShader.cpp31
1 files changed, 11 insertions, 20 deletions
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 <gfx/gl/glSource.h>
-#include <gfx/gl/programHandle.h>
+#include <gfx/gl/program.h>
+#include <gfx/gl/shader.h>
#include <gfx/gl/shaders/fs-uiShader.h>
#include <gfx/gl/shaders/fs-uiShaderFont.h>
#include <gfx/gl/shaders/vs-uiShader.h>
@@ -8,30 +8,21 @@
#include <glm/gtc/type_ptr.hpp>
#include <initializer_list>
-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<float>(0, static_cast<float>(width), 0, static_cast<float>(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<float>(0, static_cast<float>(width), 0, static_cast<float>(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));
}