ShaderVisitor: avoid reset of rig geometry when not required

0.6.1
scrawl 8 years ago
parent 0772a03e98
commit 058681ad73

@ -317,34 +317,46 @@ namespace Shader
{ {
const ShaderRequirements& reqs = mRequirements.back(); const ShaderRequirements& reqs = mRequirements.back();
osg::ref_ptr<osg::Geometry> sourceGeometry = &geometry; bool useShader = reqs.mShaderRequired || mForceShaders;
SceneUtil::RigGeometry* rig = dynamic_cast<SceneUtil::RigGeometry*>(&geometry); bool generateTangents = reqs.mTexStageRequiringTangents != -1 && mAllowedToModifyStateSets;
if (rig)
sourceGeometry = rig->getSourceGeometry();
if (mAllowedToModifyStateSets) if (useShader || generateTangents)
{ {
// make sure that all UV sets are there osg::ref_ptr<osg::Geometry> sourceGeometry = &geometry;
for (std::map<int, std::string>::const_iterator it = reqs.mTextures.begin(); it != reqs.mTextures.end(); ++it) SceneUtil::RigGeometry* rig = dynamic_cast<SceneUtil::RigGeometry*>(&geometry);
if (rig)
sourceGeometry = rig->getSourceGeometry();
bool requiresSetGeometry = false;
if (mAllowedToModifyStateSets)
{ {
if (sourceGeometry->getTexCoordArray(it->first) == NULL) // make sure that all UV sets are there
sourceGeometry->setTexCoordArray(it->first, sourceGeometry->getTexCoordArray(0)); for (std::map<int, std::string>::const_iterator it = reqs.mTextures.begin(); it != reqs.mTextures.end(); ++it)
{
if (sourceGeometry->getTexCoordArray(it->first) == NULL)
{
sourceGeometry->setTexCoordArray(it->first, sourceGeometry->getTexCoordArray(0));
requiresSetGeometry = true;
}
}
} }
}
if (reqs.mTexStageRequiringTangents != -1 && mAllowedToModifyStateSets) if (generateTangents)
{ {
osg::ref_ptr<osgUtil::TangentSpaceGenerator> generator (new osgUtil::TangentSpaceGenerator); osg::ref_ptr<osgUtil::TangentSpaceGenerator> generator (new osgUtil::TangentSpaceGenerator);
generator->generate(sourceGeometry, reqs.mTexStageRequiringTangents); generator->generate(sourceGeometry, reqs.mTexStageRequiringTangents);
sourceGeometry->setTexCoordArray(7, generator->getTangentArray(), osg::Array::BIND_PER_VERTEX); sourceGeometry->setTexCoordArray(7, generator->getTangentArray(), osg::Array::BIND_PER_VERTEX);
} requiresSetGeometry = true;
}
if (rig) if (rig && requiresSetGeometry)
rig->setSourceGeometry(sourceGeometry); rig->setSourceGeometry(sourceGeometry);
}
// TODO: find a better place for the stateset // TODO: find a better place for the stateset
if (reqs.mShaderRequired || mForceShaders) if (useShader)
createProgram(reqs, geometry); createProgram(reqs, geometry);
} }

Loading…
Cancel
Save