Merge branch 'alpha-test-override' into 'master'

Ensure original (removed) state overrides replacement state when recreating shaders

Closes #6108

See merge request OpenMW/openmw!966

(cherry picked from commit 07a7a903a7a034b661adc1b033af928a9cd68528)

8a1b4bde Ensure original (removed) state overrides replacement state when recreating shaders
0e122b1e Avoid copy and deep equality check
2147c18c Do not overwrite old removed state with old dummy state
pull/593/head
psi29a 4 years ago
parent fa30531461
commit a5b8eb72a5

@ -280,10 +280,12 @@ namespace Shader
osg::StateSet::AttributeList removedAttributes;
if (osg::ref_ptr<osg::StateSet> removedState = getRemovedState(*stateset))
removedAttributes = removedState->getAttributeList();
for (const auto& attributeMap : { attributes, removedAttributes })
for (const auto* attributeMap : std::initializer_list<const osg::StateSet::AttributeList*>{ &attributes, &removedAttributes })
{
for (osg::StateSet::AttributeList::const_iterator it = attributeMap.begin(); it != attributeMap.end(); ++it)
for (osg::StateSet::AttributeList::const_iterator it = attributeMap->begin(); it != attributeMap->end(); ++it)
{
if (attributeMap != &removedAttributes && removedAttributes.count(it->first))
continue;
if (it->first.first == osg::StateAttribute::MATERIAL)
{
// This should probably be moved out of ShaderRequirements and be applied directly now it's a uniform instead of a define
@ -405,9 +407,12 @@ namespace Shader
{
writableStateSet->addUniform(new osg::Uniform("alphaRef", reqs.mAlphaRef));
const auto* alphaFunc = writableStateSet->getAttributePair(osg::StateAttribute::ALPHAFUNC);
if (alphaFunc)
removedState->setAttribute(alphaFunc->first, alphaFunc->second);
if (!removedState->getAttributePair(osg::StateAttribute::ALPHAFUNC))
{
const auto* alphaFunc = writableStateSet->getAttributePair(osg::StateAttribute::ALPHAFUNC);
if (alphaFunc)
removedState->setAttribute(alphaFunc->first, alphaFunc->second);
}
// This prevents redundant glAlphaFunc calls while letting the shadows bin still see the test
writableStateSet->setAttribute(RemovedAlphaFunc::getInstance(reqs.mAlphaFunc), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);

Loading…
Cancel
Save