Remove existing shader when no longer required

pull/593/head
AnyOldName3 4 years ago
parent 5ad297e6ff
commit 48f397f168

@ -294,7 +294,10 @@ namespace Shader
void ShaderVisitor::createProgram(const ShaderRequirements &reqs) void ShaderVisitor::createProgram(const ShaderRequirements &reqs)
{ {
if (!reqs.mShaderRequired && !mForceShaders) if (!reqs.mShaderRequired && !mForceShaders)
{
ensureFFP(*reqs.mNode);
return; return;
}
osg::Node& node = *reqs.mNode; osg::Node& node = *reqs.mNode;
osg::StateSet* writableStateSet = nullptr; 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 ShaderVisitor::adjustGeometry(osg::Geometry& sourceGeometry, const ShaderRequirements& reqs)
{ {
bool useShader = reqs.mShaderRequired || mForceShaders; bool useShader = reqs.mShaderRequired || mForceShaders;
@ -380,6 +396,8 @@ namespace Shader
createProgram(reqs); createProgram(reqs);
} }
else
ensureFFP(geometry);
if (needPop) if (needPop)
popRequirements(); popRequirements();
@ -414,6 +432,8 @@ namespace Shader
morph->setSourceGeometry(sourceGeometry); morph->setSourceGeometry(sourceGeometry);
} }
} }
else
ensureFFP(drawable);
if (needPop) if (needPop)
popRequirements(); popRequirements();

@ -94,6 +94,7 @@ namespace Shader
std::string mDefaultFsTemplate; std::string mDefaultFsTemplate;
void createProgram(const ShaderRequirements& reqs); void createProgram(const ShaderRequirements& reqs);
void ensureFFP(osg::Node& node);
bool adjustGeometry(osg::Geometry& sourceGeometry, const ShaderRequirements& reqs); bool adjustGeometry(osg::Geometry& sourceGeometry, const ShaderRequirements& reqs);
}; };

Loading…
Cancel
Save