From 48f397f168ba32965e209c498643413a1533f468 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Thu, 3 Dec 2020 21:06:02 +0000 Subject: [PATCH] Remove existing shader when no longer required --- components/shader/shadervisitor.cpp | 20 ++++++++++++++++++++ components/shader/shadervisitor.hpp | 1 + 2 files changed, 21 insertions(+) diff --git a/components/shader/shadervisitor.cpp b/components/shader/shadervisitor.cpp index 10e9e606e..e908b6aaa 100644 --- a/components/shader/shadervisitor.cpp +++ b/components/shader/shadervisitor.cpp @@ -294,7 +294,10 @@ namespace Shader void ShaderVisitor::createProgram(const ShaderRequirements &reqs) { if (!reqs.mShaderRequired && !mForceShaders) + { + ensureFFP(*reqs.mNode); return; + } osg::Node& node = *reqs.mNode; osg::StateSet* writableStateSet = nullptr; @@ -333,6 +336,19 @@ namespace Shader } } + void ShaderVisitor::ensureFFP(osg::Node& node) + { + if (!node.getStateSet() || !node.getStateSet()->getAttribute(osg::StateAttribute::PROGRAM)) + return; + osg::StateSet* writableStateSet = nullptr; + if (mAllowedToModifyStateSets) + writableStateSet = node.getStateSet(); + else + writableStateSet = getWritableStateSet(node); + + writableStateSet->removeAttribute(osg::StateAttribute::PROGRAM); + } + bool ShaderVisitor::adjustGeometry(osg::Geometry& sourceGeometry, const ShaderRequirements& reqs) { bool useShader = reqs.mShaderRequired || mForceShaders; @@ -380,6 +396,8 @@ namespace Shader createProgram(reqs); } + else + ensureFFP(geometry); if (needPop) popRequirements(); @@ -414,6 +432,8 @@ namespace Shader morph->setSourceGeometry(sourceGeometry); } } + else + ensureFFP(drawable); if (needPop) popRequirements(); diff --git a/components/shader/shadervisitor.hpp b/components/shader/shadervisitor.hpp index 6b2353b66..6031dbfe6 100644 --- a/components/shader/shadervisitor.hpp +++ b/components/shader/shadervisitor.hpp @@ -94,6 +94,7 @@ namespace Shader std::string mDefaultFsTemplate; void createProgram(const ShaderRequirements& reqs); + void ensureFFP(osg::Node& node); bool adjustGeometry(osg::Geometry& sourceGeometry, const ShaderRequirements& reqs); };