1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-30 18:45:38 +00:00

Remove existing shader when no longer required

This commit is contained in:
AnyOldName3 2020-12-03 21:06:02 +00:00
parent 5ad297e6ff
commit 48f397f168
2 changed files with 21 additions and 0 deletions

View file

@ -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();

View file

@ -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);
}; };