From 590a340e6e436ae25abeca773ca5ac1895bdfe0e Mon Sep 17 00:00:00 2001 From: elsid Date: Thu, 2 Sep 2021 21:31:11 +0200 Subject: [PATCH] Remove redundant ShadowsBin::sCastingPrograms This variable is only used in ShadowsBin constructor and it's initialized each time before constructor call so required value can be just passed into ShadowsBin ctor. Make ShadowsBin default constructor private because it is required by osg even it's not actually called. --- components/sceneutil/shadowsbin.cpp | 13 ++++--------- components/sceneutil/shadowsbin.hpp | 4 ++-- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/components/sceneutil/shadowsbin.cpp b/components/sceneutil/shadowsbin.cpp index a6275a60e2..21f25dc4ad 100644 --- a/components/sceneutil/shadowsbin.cpp +++ b/components/sceneutil/shadowsbin.cpp @@ -42,11 +42,7 @@ namespace namespace SceneUtil { -ShadowsBin::CastingPrograms ShadowsBin::sCastingPrograms = { - nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr -}; - -ShadowsBin::ShadowsBin() +ShadowsBin::ShadowsBin(const CastingPrograms& castingPrograms) { mNoTestStateSet = new osg::StateSet; mNoTestStateSet->addUniform(new osg::Uniform("useDiffuseMapForShadowAlpha", false)); @@ -57,10 +53,10 @@ ShadowsBin::ShadowsBin() mShaderAlphaTestStateSet->addUniform(new osg::Uniform("useDiffuseMapForShadowAlpha", true)); mShaderAlphaTestStateSet->setMode(GL_BLEND, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED | osg::StateAttribute::OVERRIDE); - for (size_t i = 0; i < sCastingPrograms.size(); ++i) + for (size_t i = 0; i < castingPrograms.size(); ++i) { mAlphaFuncShaders[i] = new osg::StateSet; - mAlphaFuncShaders[i]->setAttribute(sCastingPrograms[i], osg::StateAttribute::ON | osg::StateAttribute::PROTECTED | osg::StateAttribute::OVERRIDE); + mAlphaFuncShaders[i]->setAttribute(castingPrograms[i], osg::StateAttribute::ON | osg::StateAttribute::PROTECTED | osg::StateAttribute::OVERRIDE); } } @@ -152,8 +148,7 @@ StateGraph* ShadowsBin::cullStateGraph(StateGraph* sg, StateGraph* root, std::un void ShadowsBin::addPrototype(const std::string & name, const CastingPrograms& castingPrograms) { - sCastingPrograms = castingPrograms; - osg::ref_ptr bin(new ShadowsBin); + osg::ref_ptr bin(new ShadowsBin(castingPrograms)); osgUtil::RenderBin::addRenderBinPrototype(name, bin); } diff --git a/components/sceneutil/shadowsbin.hpp b/components/sceneutil/shadowsbin.hpp index 67343c67f5..4b0d8cc544 100644 --- a/components/sceneutil/shadowsbin.hpp +++ b/components/sceneutil/shadowsbin.hpp @@ -22,7 +22,7 @@ namespace SceneUtil using CastingPrograms = Array>; META_Object(SceneUtil, ShadowsBin) - ShadowsBin(); + ShadowsBin(const CastingPrograms& castingPrograms); ShadowsBin(const ShadowsBin& rhs, const osg::CopyOp& copyop) : osgUtil::RenderBin(rhs, copyop) , mNoTestStateSet(rhs.mNoTestStateSet) @@ -65,7 +65,7 @@ namespace SceneUtil static void addPrototype(const std::string& name, const CastingPrograms& castingPrograms); private: - static CastingPrograms sCastingPrograms; + ShadowsBin() {} osg::ref_ptr mNoTestStateSet; osg::ref_ptr mShaderAlphaTestStateSet;