From 08128c14ec49a2b357e830c832ccd0a8e63c175d Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 14 Jan 2024 11:38:09 +0000 Subject: Add traits wrapper for setting uniforms --- gfx/gl/sceneRenderer.cpp | 12 ++++++------ gfx/gl/sceneShader.cpp | 12 ++++++------ gfx/gl/shadowMapper.cpp | 13 +++++++------ gfx/gl/uiShader.cpp | 3 ++- gfx/gl/uiShader.h | 3 ++- 5 files changed, 23 insertions(+), 20 deletions(-) (limited to 'gfx') diff --git a/gfx/gl/sceneRenderer.cpp b/gfx/gl/sceneRenderer.cpp index c856279..4ae4297 100644 --- a/gfx/gl/sceneRenderer.cpp +++ b/gfx/gl/sceneRenderer.cpp @@ -143,11 +143,11 @@ SceneRenderer::DirectionalLightProgram::setDirectionalLight(const RGB & c, const const GlobalPosition3D & p, const std::span lvp, const std::span shadowMapRegions, std::size_t maps) const { - glUniform3fv(colourLoc, 1, glm::value_ptr(c)); + glUniform(colourLoc, c); const auto nd = glm::normalize(d); - glUniform3fv(directionLoc, 1, glm::value_ptr(nd)); - glUniform3iv(lightPointLoc, 1, glm::value_ptr(p)); - glUniform1ui(lightViewProjectionCountLoc, static_cast(maps)); - glUniformMatrix4fv(lightViewProjectionLoc, static_cast(maps), GL_FALSE, glm::value_ptr(lvp.front())); - glUniform4fv(lightViewShadowMapRegionLoc, static_cast(maps), glm::value_ptr(shadowMapRegions.front())); + glUniform(directionLoc, nd); + glUniform(lightPointLoc, p); + glUniform(lightViewProjectionCountLoc, static_cast(maps)); + glUniform(lightViewProjectionLoc, lvp); + glUniform(lightViewShadowMapRegionLoc, shadowMapRegions); } diff --git a/gfx/gl/sceneShader.cpp b/gfx/gl/sceneShader.cpp index dc77793..1b3b27c 100644 --- a/gfx/gl/sceneShader.cpp +++ b/gfx/gl/sceneShader.cpp @@ -47,8 +47,8 @@ void SceneShader::SceneProgram::setViewProjection(const GlobalPosition3D & viewPoint, const glm::mat4 & viewProjection) const { glUseProgram(*this); - glUniformMatrix4fv(viewProjectionLoc, 1, GL_FALSE, glm::value_ptr(viewProjection)); - glUniform3iv(viewPointLoc, 1, glm::value_ptr(viewPoint)); + glUniform(viewProjectionLoc, viewProjection); + glUniform(viewPointLoc, viewPoint); } void @@ -56,7 +56,7 @@ SceneShader::SceneProgram::setViewPort(const ViewPort & viewPort) const { if (viewPortLoc >= 0) { glUseProgram(*this); - glUniform4iv(viewPortLoc, 1, glm::value_ptr(viewPort)); + glUniform(viewPortLoc, viewPort); } } @@ -68,8 +68,8 @@ SceneShader::BasicProgram::BasicProgram() : void SceneShader::BasicProgram::setModel(Location const & location) const { - glUniformMatrix3fv(modelLoc, 1, GL_FALSE, glm::value_ptr(location.getRotationTransform())); - glUniform3iv(modelPosLoc, 1, glm::value_ptr(location.pos)); + glUniform(modelLoc, location.getRotationTransform()); + glUniform(modelPosLoc, location.pos); } void @@ -85,5 +85,5 @@ void SceneShader::WaterProgram::use(float waveCycle) const { Program::use(); - glUniform1f(waveLoc, waveCycle); + glUniform(waveLoc, waveCycle); } diff --git a/gfx/gl/shadowMapper.cpp b/gfx/gl/shadowMapper.cpp index 5dc555a..ae374fe 100644 --- a/gfx/gl/shadowMapper.cpp +++ b/gfx/gl/shadowMapper.cpp @@ -4,6 +4,7 @@ #include "gfx/gl/shaders/vs-shadowDynamicPoint.h" #include "gfx/gl/shaders/vs-shadowDynamicPointInst.h" #include "gfx/gl/shaders/vs-shadowFixedPoint.h" +#include "gl_traits.h" #include "location.h" #include "maths.h" #include "sceneProvider.h" @@ -174,8 +175,8 @@ void ShadowMapper::FixedPoint::setViewProjection(const GlobalPosition3D viewPoint, const glm::mat4 & viewProjection) const { use(); - glUniformMatrix4fv(viewProjectionLoc, 1, GL_FALSE, glm::value_ptr(viewProjection)); - glUniform3iv(viewPointLoc, 1, glm::value_ptr(viewPoint)); + glUniform(viewProjectionLoc, viewProjection); + glUniform(viewPointLoc, viewPoint); } void @@ -194,8 +195,8 @@ void ShadowMapper::DynamicPoint::setViewProjection(const GlobalPosition3D viewPoint, const glm::mat4 & viewProjection) const { glUseProgram(*this); - glUniformMatrix4fv(viewProjectionLoc, 1, GL_FALSE, glm::value_ptr(viewProjection)); - glUniform3iv(viewPointLoc, 1, glm::value_ptr(viewPoint)); + glUniform(viewProjectionLoc, viewProjection); + glUniform(viewPointLoc, viewPoint); } void @@ -208,6 +209,6 @@ ShadowMapper::DynamicPoint::use(const Location & location) const void ShadowMapper::DynamicPoint::setModel(const Location & location) const { - glUniformMatrix3fv(modelLoc, 1, GL_FALSE, glm::value_ptr(location.getRotationTransform())); - glUniform3iv(modelPosLoc, 1, glm::value_ptr(location.pos)); + glUniform(modelLoc, location.getRotationTransform()); + glUniform(modelPosLoc, location.pos); } diff --git a/gfx/gl/uiShader.cpp b/gfx/gl/uiShader.cpp index dc4f4dc..cf53e2c 100644 --- a/gfx/gl/uiShader.cpp +++ b/gfx/gl/uiShader.cpp @@ -1,4 +1,5 @@ #include "uiShader.h" +#include "gl_traits.h" #include #include #include @@ -26,5 +27,5 @@ void UIShader::TextProgram::use(const RGB & colour) const { Program::use(); - glUniform3fv(colorLoc, 1, glm::value_ptr(colour)); + glUniform(colorLoc, colour); } diff --git a/gfx/gl/uiShader.h b/gfx/gl/uiShader.h index 362e90c..99c5e17 100644 --- a/gfx/gl/uiShader.h +++ b/gfx/gl/uiShader.h @@ -1,6 +1,7 @@ #pragma once #include "config/types.h" +#include "gl_traits.h" #include "program.h" #include #include @@ -21,7 +22,7 @@ private: { const RequiredUniformLocation uiProjectionLoc {*this, "uiProjection"}; glUseProgram(*this); - glUniformMatrix4fv(uiProjectionLoc, 1, GL_FALSE, glm::value_ptr(vp)); + glUniform(uiProjectionLoc, vp); } }; -- cgit v1.2.3