summaryrefslogtreecommitdiff
path: root/gfx/gl/shader.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-02-18 00:28:36 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-02-18 00:28:36 +0000
commitd5451aa5215bff05eb8f389ff37554dbd88853f8 (patch)
treea86f4f6a7350d64368b8b3b62097818f2feb8639 /gfx/gl/shader.cpp
parentSplit landmass and water textures (diff)
downloadilt-d5451aa5215bff05eb8f389ff37554dbd88853f8.tar.bz2
ilt-d5451aa5215bff05eb8f389ff37554dbd88853f8.tar.xz
ilt-d5451aa5215bff05eb8f389ff37554dbd88853f8.zip
Allow setting any uniform in shaders
Move less commonly used (lightDirection) to a named one
Diffstat (limited to 'gfx/gl/shader.cpp')
-rw-r--r--gfx/gl/shader.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/gfx/gl/shader.cpp b/gfx/gl/shader.cpp
index 979d57e..8c58c39 100644
--- a/gfx/gl/shader.cpp
+++ b/gfx/gl/shader.cpp
@@ -6,8 +6,7 @@
#include <stdexcept>
#include <string>
-Shader::ProgramHandle::ProgramHandle(std::initializer_list<GLuint> srcs) :
- viewProjection_uniform {}, model_uniform {}, lightDir_uniform {}
+Shader::ProgramHandle::ProgramHandle(std::initializer_list<GLuint> srcs) : viewProjection_uniform {}, model_uniform {}
{
for (const auto & srcId : srcs) {
glAttachShader(m_program, srcId);
@@ -25,7 +24,6 @@ Shader::ProgramHandle::ProgramHandle(std::initializer_list<GLuint> srcs) :
viewProjection_uniform = glGetUniformLocation(m_program, "viewProjection");
model_uniform = glGetUniformLocation(m_program, "model");
- lightDir_uniform = glGetUniformLocation(m_program, "lightDirection");
}
Shader::Shader() :
@@ -46,11 +44,13 @@ Shader::setView(glm::mat4 proj) const
}
void
-Shader::setLight(glm::vec3 lightDir) const
+Shader::setUniform(const GLchar * uniform, glm::vec3 v) const
{
for (const auto & prog : programs) {
- glUseProgram(prog.m_program);
- glUniform3fv(prog.lightDir_uniform, 1, &lightDir[0]);
+ if (auto loc = glGetUniformLocation(prog.m_program, uniform); loc >= 0) {
+ glUseProgram(prog.m_program);
+ glUniform3fv(loc, 1, &v[0]);
+ }
}
}