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
pull/3130/head
Bo Svensson 3 years ago committed by GitHub
parent fd251dfe55
commit e41fe7573a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -243,19 +243,22 @@ namespace Resource
void apply(osg::Node& node) override
{
if (node.getOrCreateStateSet()->getRenderingHint() == osg::StateSet::TRANSPARENT_BIN)
if (osg::StateSet* stateset = node.getStateSet())
{
osg::ref_ptr<osg::Depth> depth = SceneUtil::createDepth();
depth->setWriteMask(false);
if (stateset->getRenderingHint() == osg::StateSet::TRANSPARENT_BIN)
{
osg::ref_ptr<osg::Depth> depth = SceneUtil::createDepth();
depth->setWriteMask(false);
node.getOrCreateStateSet()->setAttributeAndModes(depth, osg::StateAttribute::ON);
}
else if (node.getOrCreateStateSet()->getRenderingHint() == osg::StateSet::OPAQUE_BIN)
{
osg::ref_ptr<osg::Depth> depth = SceneUtil::createDepth();
depth->setWriteMask(true);
stateset->setAttributeAndModes(depth, osg::StateAttribute::ON);
}
else if (stateset->getRenderingHint() == osg::StateSet::OPAQUE_BIN)
{
osg::ref_ptr<osg::Depth> depth = SceneUtil::createDepth();
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>
@ -268,22 +271,25 @@ namespace Resource
}
// Iterate each description, and see if the current node uses the specified material for alpha testing
for (auto description : mDescriptions)
if (node.getStateSet())
{
std::vector<std::string> descriptionParts;
std::istringstream descriptionStringStream(description);
for (std::string part; std::getline(descriptionStringStream, part, ' ');)
for (auto description : mDescriptions)
{
descriptionParts.emplace_back(part);
}
std::vector<std::string> descriptionParts;
std::istringstream descriptionStringStream(description);
for (std::string part; std::getline(descriptionStringStream, part, ' ');)
{
descriptionParts.emplace_back(part);
}
if (descriptionParts.size() > (3) && descriptionParts.at(3) == node.getOrCreateStateSet()->getName())
{
if (descriptionParts.at(0) == "alphatest")
if (descriptionParts.size() > (3) && descriptionParts.at(3) == node.getStateSet()->getName())
{
osg::AlphaFunc::ComparisonFunction mode = getTestMode(descriptionParts.at(1));
osg::ref_ptr<osg::AlphaFunc> alphaFunc (new osg::AlphaFunc(mode, std::stod(descriptionParts.at(2))));
node.getOrCreateStateSet()->setAttributeAndModes(alphaFunc, osg::StateAttribute::ON);
if (descriptionParts.at(0) == "alphatest")
{
osg::AlphaFunc::ComparisonFunction mode = getTestMode(descriptionParts.at(1));
osg::ref_ptr<osg::AlphaFunc> alphaFunc (new osg::AlphaFunc(mode, std::stod(descriptionParts.at(2))));
node.getStateSet()->setAttributeAndModes(alphaFunc, osg::StateAttribute::ON);
}
}
}
}

Loading…
Cancel
Save