From 9a43f9e749f9f51cb37dabd9c1d33f2ee9441b2f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 17 Oct 2024 18:26:24 +0100 Subject: Re-express viewProjections calculations as a fold expression --- gfx/gl/shadowStenciller.cpp | 10 +++++----- gfx/gl/shadowStenciller.h | 4 +++- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'gfx/gl') diff --git a/gfx/gl/shadowStenciller.cpp b/gfx/gl/shadowStenciller.cpp index 55ad8e1..89b61cc 100644 --- a/gfx/gl/shadowStenciller.cpp +++ b/gfx/gl/shadowStenciller.cpp @@ -10,8 +10,6 @@ #include "maths.h" #include -template constexpr T STENCIL_ANGLES = 8; - ShadowStenciller::ShadowStenciller() : shadowCaster {shadowStencil_vs, shadowStencil_gs, shadowStencil_fs}, viewProjections {} { @@ -24,9 +22,11 @@ ShadowStenciller::ShadowStenciller() : void ShadowStenciller::setLightDirection(const LightDirection & lightDir) { - viewProjections = std::array {0, 1, 2, 3, 4, 5, 6, 7} * [&lightDir](const auto & ep) { - return rotate_pitch(half_pi - lightDir.position().y) * rotate_yaw((ep * quarter_pi) - lightDir.position().x); - }; + viewProjections = [&lightDir](std::integer_sequence) { + constexpr float STEP = two_pi / STENCIL_ANGLES; + return std::array { + rotate_pitch(half_pi - lightDir.position().y) * rotate_yaw((Ep * STEP) - lightDir.position().x)...}; + }(std::make_integer_sequence>()); } glTexture diff --git a/gfx/gl/shadowStenciller.h b/gfx/gl/shadowStenciller.h index 03efced..ac83eb1 100644 --- a/gfx/gl/shadowStenciller.h +++ b/gfx/gl/shadowStenciller.h @@ -9,6 +9,8 @@ class LightDirection; class ShadowStenciller { public: + template static constexpr T STENCIL_ANGLES = 8; + ShadowStenciller(); [[nodiscard]] @@ -21,5 +23,5 @@ private: Program shadowCaster; Program::RequiredUniformLocation viewProjectionLoc {shadowCaster, "viewProjection"}; - std::array viewProjections; + std::array> viewProjections; }; -- cgit v1.2.3