From 07064efcfecb0f1140f829ee2481079fa02cc587 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 7 Jul 2024 23:21:25 +0100 Subject: Simplify setup of uniform locations and containing programs --- gfx/gl/sceneRenderer.cpp | 8 +------- gfx/gl/sceneRenderer.h | 7 +++++-- gfx/gl/sceneShader.cpp | 14 ++------------ gfx/gl/sceneShader.h | 24 +++++++++++------------- gfx/gl/shadowMapper.cpp | 16 +++------------- gfx/gl/shadowMapper.h | 18 ++++++------------ gfx/gl/uiShader.cpp | 5 +---- gfx/gl/uiShader.h | 2 +- 8 files changed, 30 insertions(+), 64 deletions(-) (limited to 'gfx/gl') diff --git a/gfx/gl/sceneRenderer.cpp b/gfx/gl/sceneRenderer.cpp index 517d51e..e0938f2 100644 --- a/gfx/gl/sceneRenderer.cpp +++ b/gfx/gl/sceneRenderer.cpp @@ -129,13 +129,7 @@ SceneRenderer::renderQuad() const glBindVertexArray(0); } -SceneRenderer::DirectionalLightProgram::DirectionalLightProgram() : - Program {lighting_vs, directionalLight_fs}, directionLoc {*this, "lightDirection"}, - colourLoc {*this, "lightColour"}, lightPointLoc {*this, "lightPoint"}, - lightViewProjectionLoc {*this, "lightViewProjection"}, - lightViewProjectionCountLoc {*this, "lightViewProjectionCount"} -{ -} +SceneRenderer::DirectionalLightProgram::DirectionalLightProgram() : Program {lighting_vs, directionalLight_fs} { } const auto toTextureSpaceMat = glm::translate(glm::identity(), glm::vec3 {0.5F}) * glm::scale(glm::identity(), glm::vec3 {0.5F}); diff --git a/gfx/gl/sceneRenderer.h b/gfx/gl/sceneRenderer.h index 021936f..4195bcf 100644 --- a/gfx/gl/sceneRenderer.h +++ b/gfx/gl/sceneRenderer.h @@ -42,8 +42,11 @@ protected: const RGB &, const Direction3D &, const GlobalPosition3D &, const std::span) const; private: - RequiredUniformLocation directionLoc, colourLoc, lightPointLoc, lightViewProjectionLoc, - lightViewProjectionCountLoc; + RequiredUniformLocation directionLoc {*this, "lightDirection"}; + RequiredUniformLocation colourLoc {*this, "lightColour"}; + RequiredUniformLocation lightPointLoc {*this, "lightPoint"}; + RequiredUniformLocation lightViewProjectionLoc {*this, "lightViewProjection"}; + RequiredUniformLocation lightViewProjectionCountLoc {*this, "lightViewProjectionCount"}; }; DeferredLightProgram lighting; diff --git a/gfx/gl/sceneShader.cpp b/gfx/gl/sceneShader.cpp index 985faa0..4cbccb3 100644 --- a/gfx/gl/sceneShader.cpp +++ b/gfx/gl/sceneShader.cpp @@ -71,10 +71,7 @@ SceneShader::SceneProgram::setViewPort(const ViewPort & viewPort) const } } -SceneShader::BasicProgram::BasicProgram() : - SceneProgram {dynamicPoint_vs, material_fs}, modelLoc {*this, "model"}, modelPosLoc {*this, "modelPos"} -{ -} +SceneShader::BasicProgram::BasicProgram() : SceneProgram {dynamicPoint_vs, material_fs} { } void SceneShader::BasicProgram::setModel(Location const & location) const @@ -90,13 +87,6 @@ SceneShader::BasicProgram::use(Location const & location) const setModel(location); } -template -SceneShader::NetworkProgram::NetworkProgram(S &&... s) : - AbsolutePosProgram {std::forward(s)...}, profileLoc {*this, "profile"}, texturePosLoc {*this, "texturePos"}, - profileLengthLoc {*this, "profileLength"} -{ -} - void SceneShader::NetworkProgram::use( const std::span profile, const std::span texturePos) const @@ -107,7 +97,7 @@ SceneShader::NetworkProgram::use( glUniform(profileLengthLoc, static_cast(profile.size())); } -SceneShader::WaterProgram::WaterProgram() : SceneProgram {water_vs, water_fs}, waveLoc {*this, "waves"} { } +SceneShader::WaterProgram::WaterProgram() : SceneProgram {water_vs, water_fs} { } void SceneShader::WaterProgram::use(float waveCycle) const diff --git a/gfx/gl/sceneShader.h b/gfx/gl/sceneShader.h index 07b0b26..51f0e21 100644 --- a/gfx/gl/sceneShader.h +++ b/gfx/gl/sceneShader.h @@ -10,19 +10,15 @@ class Location; class SceneShader { class SceneProgram : public Program { public: - template - inline explicit SceneProgram(const S &... srcs) : - Program {srcs...}, viewProjectionLoc {*this, "viewProjection"}, viewPointLoc {*this, "viewPoint"}, - viewPortLoc {*this, "viewPort"} - { - } + using Program::Program; void setViewProjection(const GlobalPosition3D &, const glm::mat4 &) const; void setViewPort(const ViewPort &) const; private: - RequiredUniformLocation viewProjectionLoc, viewPointLoc; - UniformLocation viewPortLoc; + RequiredUniformLocation viewProjectionLoc {*this, "viewProjection"}; + RequiredUniformLocation viewPointLoc {*this, "viewPoint"}; + UniformLocation viewPortLoc {*this, "viewPort"}; }; class BasicProgram : public SceneProgram { @@ -32,8 +28,8 @@ class SceneShader { void use(const Location &) const; private: - RequiredUniformLocation modelLoc; - RequiredUniformLocation modelPosLoc; + RequiredUniformLocation modelLoc {*this, "model"}; + RequiredUniformLocation modelPosLoc {*this, "modelPos"}; }; class AbsolutePosProgram : public SceneProgram { @@ -44,12 +40,14 @@ class SceneShader { class NetworkProgram : public AbsolutePosProgram { public: - template explicit NetworkProgram(S &&...); + using AbsolutePosProgram::AbsolutePosProgram; void use(const std::span, const std::span) const; private: - RequiredUniformLocation profileLoc, texturePosLoc, profileLengthLoc; + RequiredUniformLocation profileLoc {*this, "profile"}; + RequiredUniformLocation texturePosLoc {*this, "texturePos"}; + RequiredUniformLocation profileLengthLoc {*this, "profileLength"}; }; class WaterProgram : public SceneProgram { @@ -58,7 +56,7 @@ class SceneShader { void use(float waveCycle) const; private: - RequiredUniformLocation waveLoc; + RequiredUniformLocation waveLoc {*this, "waves"}; }; public: diff --git a/gfx/gl/shadowMapper.cpp b/gfx/gl/shadowMapper.cpp index c537314..a846a3d 100644 --- a/gfx/gl/shadowMapper.cpp +++ b/gfx/gl/shadowMapper.cpp @@ -108,15 +108,10 @@ ShadowMapper::update(const SceneProvider & scene, const Direction3D & dir, const return out; } -ShadowMapper::ShadowProgram::ShadowProgram(const Shader & vs) : - Program {vs, commonShadowPoint_gs}, viewProjectionLoc {*this, "viewProjection"}, - viewProjectionsLoc {*this, "viewProjections"}, viewPointLoc {*this, "viewPoint"} -{ -} +ShadowMapper::ShadowProgram::ShadowProgram(const Shader & vs) : Program {vs, commonShadowPoint_gs} { } ShadowMapper::ShadowProgram::ShadowProgram(const Shader & vs, const Shader & gs, const Shader & fs) : - Program {vs, gs, fs}, viewProjectionLoc {*this, "viewProjection"}, viewProjectionsLoc {*this, "viewProjections"}, - viewPointLoc {*this, "viewPoint"} + Program {vs, gs, fs} { } @@ -136,12 +131,7 @@ ShadowMapper::ShadowProgram::use() const glUseProgram(*this); } -ShadowMapper::FixedPoint::FixedPoint(const Shader & vs) : ShadowProgram {vs} { } - -ShadowMapper::DynamicPoint::DynamicPoint() : - ShadowProgram {shadowDynamicPoint_vs}, modelLoc {*this, "model"}, modelPosLoc {*this, "modelPos"} -{ -} +ShadowMapper::DynamicPoint::DynamicPoint() : ShadowProgram {shadowDynamicPoint_vs} { } void ShadowMapper::DynamicPoint::use(const Location & location) const diff --git a/gfx/gl/shadowMapper.h b/gfx/gl/shadowMapper.h index 967d93b..73dadd0 100644 --- a/gfx/gl/shadowMapper.h +++ b/gfx/gl/shadowMapper.h @@ -30,14 +30,9 @@ public: void use() const; private: - RequiredUniformLocation viewProjectionLoc; - RequiredUniformLocation viewProjectionsLoc; - RequiredUniformLocation viewPointLoc; - }; - - class FixedPoint : public ShadowProgram { - public: - explicit FixedPoint(const Shader & vs); + RequiredUniformLocation viewProjectionLoc {*this, "viewProjection"}; + RequiredUniformLocation viewProjectionsLoc {*this, "viewProjections"}; + RequiredUniformLocation viewPointLoc {*this, "viewPoint"}; }; class DynamicPoint : public ShadowProgram { @@ -47,12 +42,11 @@ public: void setModel(const Location &) const; private: - RequiredUniformLocation modelLoc; - RequiredUniformLocation modelPosLoc; + RequiredUniformLocation modelLoc {*this, "model"}; + RequiredUniformLocation modelPosLoc {*this, "modelPos"}; }; - FixedPoint landmess, dynamicPointInst; - ShadowProgram dynamicPointInstWithTextures; + ShadowProgram landmess, dynamicPointInst, dynamicPointInstWithTextures; DynamicPoint dynamicPoint; // NOLINTNEXTLINE(hicpp-explicit-conversions) diff --git a/gfx/gl/uiShader.cpp b/gfx/gl/uiShader.cpp index bb9570e..23da9dc 100644 --- a/gfx/gl/uiShader.cpp +++ b/gfx/gl/uiShader.cpp @@ -10,10 +10,7 @@ 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"} -{ -} +UIShader::TextProgram::TextProgram(const glm::mat4 & vp) : UIProgram {vp, uiShader_vs, uiShaderFont_fs} { } UIShader::UIShader(size_t width, size_t height) : UIShader {glm::ortho(0, static_cast(width), 0, static_cast(height))} diff --git a/gfx/gl/uiShader.h b/gfx/gl/uiShader.h index 99c5e17..6d00166 100644 --- a/gfx/gl/uiShader.h +++ b/gfx/gl/uiShader.h @@ -38,7 +38,7 @@ private: void use(const RGB & colour) const; private: - RequiredUniformLocation colorLoc; + RequiredUniformLocation colorLoc {*this, "colour"}; }; public: -- cgit v1.2.3