From 83c43ea9e39f4e6ed5e50ccced66700af39987be Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 29 Jan 2024 01:02:51 +0000 Subject: Set shadow program uniforms all in one function, merge setting of view projections --- gfx/gl/shadowMapper.cpp | 33 ++++++++++----------------------- gfx/gl/shadowMapper.h | 6 +++--- 2 files changed, 13 insertions(+), 26 deletions(-) (limited to 'gfx/gl') diff --git a/gfx/gl/shadowMapper.cpp b/gfx/gl/shadowMapper.cpp index 4141278..f3d5dea 100644 --- a/gfx/gl/shadowMapper.cpp +++ b/gfx/gl/shadowMapper.cpp @@ -140,8 +140,7 @@ ShadowMapper::update(const SceneProvider & scene, const Direction3D & dir, const Definitions out; std::transform(bandViewExtents.begin(), std::prev(bandViewExtents.end()), std::next(bandViewExtents.begin()), DefinitionsInserter {out}, - [this, bands = bandViewExtents.size() - 2, &out, &lightViewDir]( - const auto & near, const auto & far) mutable { + [bands = bandViewExtents.size() - 2, &lightViewDir](const auto & near, const auto & far) mutable { const auto extents_minmax = [extents = std::span {near.begin(), far.end()}](auto && comp) { const auto mm = std::minmax_element(extents.begin(), extents.end(), comp); return std::make_pair(comp.get(*mm.first), comp.get(*mm.second)); @@ -152,15 +151,13 @@ ShadowMapper::update(const SceneProvider & scene, const Direction3D & dir, const }(extents_minmax(CompareBy {0}), extents_minmax(CompareBy {1}), extents_minmax(CompareBy {2})); const auto lightViewDirProjection = lightProjection * lightViewDir; - fixedPoint.setViewProjection(lightViewDirProjection, out.maps); - dynamicPoint.setViewProjection(lightViewDirProjection, out.maps); - dynamicPointInst.setViewProjection(lightViewDirProjection, out.maps); return std::make_pair(lightViewDirProjection, shadowMapRegions[0][0]); }); - fixedPoint.setViewPoint(lightViewPoint, out.maps); - dynamicPoint.setViewPoint(lightViewPoint, out.maps); - dynamicPointInst.setViewPoint(lightViewPoint, out.maps); + std::span vps {out.projections.data(), out.maps}; + for (const auto p : std::initializer_list {&fixedPoint, &dynamicPoint, &dynamicPointInst}) { + p->setView(vps, lightViewPoint); + } scene.shadows(*this); glCullFace(GL_BACK); @@ -169,29 +166,19 @@ ShadowMapper::update(const SceneProvider & scene, const Direction3D & dir, const } ShadowMapper::ShadowProgram::ShadowProgram(const Shader & vs) : - Program {vs, commonShadowPoint_gs}, viewProjectionLoc {{ - {*this, "viewProjection[0]"}, - {*this, "viewProjection[1]"}, - {*this, "viewProjection[2]"}, - {*this, "viewProjection[3]"}, - }}, + Program {vs, commonShadowPoint_gs}, viewProjectionLoc {*this, "viewProjection"}, viewProjectionsLoc {*this, "viewProjections"}, viewPointLoc {*this, "viewPoint"} { } void -ShadowMapper::ShadowProgram::setViewPoint(const GlobalPosition3D viewPoint, size_t n) const +ShadowMapper::ShadowProgram::setView( + const std::span viewProjection, const GlobalPosition3D viewPoint) const { use(); glUniform(viewPointLoc, viewPoint); - glUniform(viewProjectionsLoc, static_cast(n)); -} - -void -ShadowMapper::ShadowProgram::setViewProjection(const glm::mat4 & viewProjection, size_t n) const -{ - use(); - glUniform(viewProjectionLoc[n], viewProjection); + glUniform(viewProjectionLoc, viewProjection); + glUniform(viewProjectionsLoc, static_cast(viewProjection.size())); } void diff --git a/gfx/gl/shadowMapper.h b/gfx/gl/shadowMapper.h index 4f81e58..b948f50 100644 --- a/gfx/gl/shadowMapper.h +++ b/gfx/gl/shadowMapper.h @@ -5,6 +5,7 @@ #include "program.h" #include #include +#include #include class SceneProvider; @@ -28,12 +29,11 @@ public: public: explicit ShadowProgram(const Shader & vs); - void setViewPoint(const GlobalPosition3D, size_t n) const; - void setViewProjection(const glm::mat4 &, size_t n) const; + void setView(const std::span, const GlobalPosition3D) const; void use() const; private: - std::array viewProjectionLoc; + RequiredUniformLocation viewProjectionLoc; RequiredUniformLocation viewProjectionsLoc; RequiredUniformLocation viewPointLoc; }; -- cgit v1.2.3