1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-03-03 15:09:39 +00:00

reapplies PR without npe (#3137)

* avoids creating empty statesets on drawables

Currently, we attempt to skip creating state on drawable nodes when this state matches the default state. This attempt is incomplete because we still create an avoidable empty stateset in the default case.

* renderingmanager.cpp

* nifloader.cpp

* nifloader.cpp

* shadervisitor.cpp
This commit is contained in:
Bo Svensson 2021-10-01 08:11:00 +00:00 committed by GitHub
parent 9cf9da9cbd
commit 2568f119a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 13 deletions

View file

@ -486,6 +486,7 @@ namespace MWRender
defaultMat->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4f(1,1,1,1)); defaultMat->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4f(1,1,1,1));
defaultMat->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4f(0.f, 0.f, 0.f, 0.f)); defaultMat->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4f(0.f, 0.f, 0.f, 0.f));
sceneRoot->getOrCreateStateSet()->setAttribute(defaultMat); sceneRoot->getOrCreateStateSet()->setAttribute(defaultMat);
sceneRoot->getOrCreateStateSet()->addUniform(new osg::Uniform("emissiveMult", 1.f));
mFog.reset(new FogManager()); mFog.reset(new FogManager());

View file

@ -1134,8 +1134,6 @@ namespace NifOsg
trans->addChild(toAttach); trans->addChild(toAttach);
parentNode->addChild(trans); parentNode->addChild(trans);
} }
// create partsys stateset in order to pass in ShaderVisitor like all other Drawables
partsys->getOrCreateStateSet();
} }
void handleNiGeometryData(osg::Geometry *geometry, const Nif::NiGeometryData* data, const std::vector<unsigned int>& boundTextures, const std::string& name) void handleNiGeometryData(osg::Geometry *geometry, const Nif::NiGeometryData* data, const std::vector<unsigned int>& boundTextures, const std::string& name)
@ -1923,8 +1921,6 @@ namespace NifOsg
void applyDrawableProperties(osg::Node* node, const std::vector<const Nif::Property*>& properties, SceneUtil::CompositeStateSetUpdater* composite, void applyDrawableProperties(osg::Node* node, const std::vector<const Nif::Property*>& properties, SceneUtil::CompositeStateSetUpdater* composite,
bool hasVertexColors, int animflags) bool hasVertexColors, int animflags)
{ {
osg::StateSet* stateset = node->getOrCreateStateSet();
// Specular lighting is enabled by default, but there's a quirk... // Specular lighting is enabled by default, but there's a quirk...
bool specEnabled = true; bool specEnabled = true;
osg::ref_ptr<osg::Material> mat (new osg::Material); osg::ref_ptr<osg::Material> mat (new osg::Material);
@ -2006,15 +2002,15 @@ namespace NifOsg
if (blendFunc->getDestination() == GL_DST_ALPHA) if (blendFunc->getDestination() == GL_DST_ALPHA)
blendFunc->setDestination(GL_ONE); blendFunc->setDestination(GL_ONE);
blendFunc = shareAttribute(blendFunc); blendFunc = shareAttribute(blendFunc);
stateset->setAttributeAndModes(blendFunc, osg::StateAttribute::ON); node->getOrCreateStateSet()->setAttributeAndModes(blendFunc, osg::StateAttribute::ON);
bool noSort = (alphaprop->flags>>13)&1; bool noSort = (alphaprop->flags>>13)&1;
if (!noSort) if (!noSort)
stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); node->getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
else else
stateset->setRenderBinToInherit(); node->getOrCreateStateSet()->setRenderBinToInherit();
} }
else else if (osg::StateSet* stateset = node->getStateSet())
{ {
stateset->removeAttribute(osg::StateAttribute::BLENDFUNC); stateset->removeAttribute(osg::StateAttribute::BLENDFUNC);
stateset->removeMode(GL_BLEND); stateset->removeMode(GL_BLEND);
@ -2025,9 +2021,9 @@ namespace NifOsg
{ {
osg::ref_ptr<osg::AlphaFunc> alphaFunc (new osg::AlphaFunc(getTestMode((alphaprop->flags>>10)&0x7), alphaprop->data.threshold/255.f)); osg::ref_ptr<osg::AlphaFunc> alphaFunc (new osg::AlphaFunc(getTestMode((alphaprop->flags>>10)&0x7), alphaprop->data.threshold/255.f));
alphaFunc = shareAttribute(alphaFunc); alphaFunc = shareAttribute(alphaFunc);
stateset->setAttributeAndModes(alphaFunc, osg::StateAttribute::ON); node->getOrCreateStateSet()->setAttributeAndModes(alphaFunc, osg::StateAttribute::ON);
} }
else else if (osg::StateSet* stateset = node->getStateSet())
{ {
stateset->removeAttribute(osg::StateAttribute::ALPHAFUNC); stateset->removeAttribute(osg::StateAttribute::ALPHAFUNC);
stateset->removeMode(GL_ALPHA_TEST); stateset->removeMode(GL_ALPHA_TEST);
@ -2083,8 +2079,10 @@ namespace NifOsg
mat = shareAttribute(mat); mat = shareAttribute(mat);
osg::StateSet* stateset = node->getOrCreateStateSet();
stateset->setAttributeAndModes(mat, osg::StateAttribute::ON); stateset->setAttributeAndModes(mat, osg::StateAttribute::ON);
stateset->addUniform(new osg::Uniform("emissiveMult", emissiveMult)); if (emissiveMult != 1.f)
stateset->addUniform(new osg::Uniform("emissiveMult", emissiveMult));
} }
}; };

View file

@ -116,7 +116,6 @@ namespace Shader
, mImageManager(imageManager) , mImageManager(imageManager)
, mDefaultShaderPrefix(defaultShaderPrefix) , mDefaultShaderPrefix(defaultShaderPrefix)
{ {
mRequirements.emplace_back();
} }
void ShaderVisitor::setForceShaders(bool force) void ShaderVisitor::setForceShaders(bool force)
@ -421,7 +420,10 @@ namespace Shader
void ShaderVisitor::pushRequirements(osg::Node& node) void ShaderVisitor::pushRequirements(osg::Node& node)
{ {
mRequirements.push_back(mRequirements.back()); if (mRequirements.empty())
mRequirements.emplace_back();
else
mRequirements.push_back(mRequirements.back());
mRequirements.back().mNode = &node; mRequirements.back().mNode = &node;
} }