1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-31 10:20:13 +00:00

avoids creating empty statesets for collada nodes (#3128)

* avoids creating empty statesets for collada nodes

With this PR we avoid creating empty statesets for collada nodes which will be detrimental to osg's draw performance.

* scenemanager.cpp
This commit is contained in:
Bo Svensson 2021-09-28 08:17:12 +00:00 committed by GitHub
parent fd251dfe55
commit e41fe7573a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -243,19 +243,22 @@ namespace Resource
void apply(osg::Node& node) override void apply(osg::Node& node) override
{ {
if (node.getOrCreateStateSet()->getRenderingHint() == osg::StateSet::TRANSPARENT_BIN) if (osg::StateSet* stateset = node.getStateSet())
{
if (stateset->getRenderingHint() == osg::StateSet::TRANSPARENT_BIN)
{ {
osg::ref_ptr<osg::Depth> depth = SceneUtil::createDepth(); osg::ref_ptr<osg::Depth> depth = SceneUtil::createDepth();
depth->setWriteMask(false); depth->setWriteMask(false);
node.getOrCreateStateSet()->setAttributeAndModes(depth, osg::StateAttribute::ON); stateset->setAttributeAndModes(depth, osg::StateAttribute::ON);
} }
else if (node.getOrCreateStateSet()->getRenderingHint() == osg::StateSet::OPAQUE_BIN) else if (stateset->getRenderingHint() == osg::StateSet::OPAQUE_BIN)
{ {
osg::ref_ptr<osg::Depth> depth = SceneUtil::createDepth(); osg::ref_ptr<osg::Depth> depth = SceneUtil::createDepth();
depth->setWriteMask(true); depth->setWriteMask(true);
node.getOrCreateStateSet()->setAttributeAndModes(depth, osg::StateAttribute::ON); stateset->setAttributeAndModes(depth, osg::StateAttribute::ON);
}
} }
/* Check if the <node> has <extra type="Node"> <technique profile="OpenSceneGraph"> <Descriptions> <Description> /* Check if the <node> has <extra type="Node"> <technique profile="OpenSceneGraph"> <Descriptions> <Description>
@ -268,6 +271,8 @@ namespace Resource
} }
// Iterate each description, and see if the current node uses the specified material for alpha testing // Iterate each description, and see if the current node uses the specified material for alpha testing
if (node.getStateSet())
{
for (auto description : mDescriptions) for (auto description : mDescriptions)
{ {
std::vector<std::string> descriptionParts; std::vector<std::string> descriptionParts;
@ -277,13 +282,14 @@ namespace Resource
descriptionParts.emplace_back(part); descriptionParts.emplace_back(part);
} }
if (descriptionParts.size() > (3) && descriptionParts.at(3) == node.getOrCreateStateSet()->getName()) if (descriptionParts.size() > (3) && descriptionParts.at(3) == node.getStateSet()->getName())
{ {
if (descriptionParts.at(0) == "alphatest") if (descriptionParts.at(0) == "alphatest")
{ {
osg::AlphaFunc::ComparisonFunction mode = getTestMode(descriptionParts.at(1)); osg::AlphaFunc::ComparisonFunction mode = getTestMode(descriptionParts.at(1));
osg::ref_ptr<osg::AlphaFunc> alphaFunc (new osg::AlphaFunc(mode, std::stod(descriptionParts.at(2)))); osg::ref_ptr<osg::AlphaFunc> alphaFunc (new osg::AlphaFunc(mode, std::stod(descriptionParts.at(2))));
node.getOrCreateStateSet()->setAttributeAndModes(alphaFunc, osg::StateAttribute::ON); node.getStateSet()->setAttributeAndModes(alphaFunc, osg::StateAttribute::ON);
}
} }
} }
} }