From 738754c684a1c2d736bae7940a52a9ee058e83e5 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 24 Jan 2024 02:13:18 +0000 Subject: Single list of all shader programs Pushes common stuff through a helper function --- gfx/gl/sceneShader.cpp | 19 +++++++++++-------- gfx/gl/sceneShader.h | 3 +++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/gfx/gl/sceneShader.cpp b/gfx/gl/sceneShader.cpp index bc64a88..2dd9612 100644 --- a/gfx/gl/sceneShader.cpp +++ b/gfx/gl/sceneShader.cpp @@ -23,6 +23,15 @@ #include #include +inline void +SceneShader::allPrograms(auto member, auto &&... ps) const +{ + for (const auto & prog : std::initializer_list {&basic, &basicInst, &water, &landmass, + &absolute, &pointLightInst, &spotLightInst, &networkStraight, &networkCurve}) { + (prog->*member)(std::forward(ps)...); + } +} + SceneShader::SceneShader() : basicInst {dynamicPointInst_vs, material_fs}, landmass {fixedPoint_vs, landmass_fs}, absolute {fixedPoint_vs, material_fs}, spotLightInst {spotLight_vs, spotLight_gs, spotLight_fs}, @@ -35,19 +44,13 @@ SceneShader::SceneShader() : void SceneShader::setViewProjection(const GlobalPosition3D & viewPoint, const glm::mat4 & viewProjection) const { - for (const auto & prog : std::initializer_list {&basic, &basicInst, &water, &landmass, - &absolute, &pointLightInst, &spotLightInst, &networkStraight, &networkCurve}) { - prog->setViewProjection(viewPoint, viewProjection); - } + allPrograms(&SceneProgram::setViewProjection, viewPoint, viewProjection); } void SceneShader::setViewPort(const ViewPort & viewPort) const { - for (const auto & prog : std::initializer_list {&basic, &basicInst, &water, &landmass, - &absolute, &pointLightInst, &spotLightInst, &networkStraight, &networkCurve}) { - prog->setViewPort(viewPort); - } + allPrograms(&SceneProgram::setViewPort, viewPort); } void diff --git a/gfx/gl/sceneShader.h b/gfx/gl/sceneShader.h index 8621442..07b0b26 100644 --- a/gfx/gl/sceneShader.h +++ b/gfx/gl/sceneShader.h @@ -71,4 +71,7 @@ public: void setViewProjection(const GlobalPosition3D & viewPoint, const glm::mat4 & viewProjection) const; void setViewPort(const ViewPort & viewPort) const; + +private: + inline void allPrograms(auto member, auto &&... ps) const; }; -- cgit v1.2.3