|
|
|
@ -865,51 +865,73 @@ namespace Shader
|
|
|
|
|
|
|
|
|
|
void ShaderVisitor::apply(osg::Geometry& geometry)
|
|
|
|
|
{
|
|
|
|
|
pushRequirements(geometry);
|
|
|
|
|
bool needPop = (geometry.getStateSet() != nullptr);
|
|
|
|
|
if (geometry.getStateSet()) // TODO: check if stateset affects shader permutation before pushing it
|
|
|
|
|
{
|
|
|
|
|
pushRequirements(geometry);
|
|
|
|
|
applyStateSet(geometry.getStateSet(), geometry);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!mRequirements.empty())
|
|
|
|
|
{
|
|
|
|
|
const ShaderRequirements& reqs = mRequirements.back();
|
|
|
|
|
|
|
|
|
|
adjustGeometry(geometry, reqs);
|
|
|
|
|
|
|
|
|
|
const ShaderRequirements& reqs = mRequirements.back();
|
|
|
|
|
adjustGeometry(geometry, reqs);
|
|
|
|
|
createProgram(reqs);
|
|
|
|
|
createProgram(reqs);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
ensureFFP(geometry);
|
|
|
|
|
|
|
|
|
|
popRequirements();
|
|
|
|
|
if (needPop)
|
|
|
|
|
popRequirements();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ShaderVisitor::apply(osg::Drawable& drawable)
|
|
|
|
|
{
|
|
|
|
|
pushRequirements(drawable);
|
|
|
|
|
|
|
|
|
|
if (drawable.getStateSet())
|
|
|
|
|
applyStateSet(drawable.getStateSet(), drawable);
|
|
|
|
|
bool needPop = drawable.getStateSet();
|
|
|
|
|
|
|
|
|
|
const ShaderRequirements& reqs = mRequirements.back();
|
|
|
|
|
createProgram(reqs);
|
|
|
|
|
|
|
|
|
|
if (auto rig = dynamic_cast<SceneUtil::RigGeometry*>(&drawable))
|
|
|
|
|
{
|
|
|
|
|
osg::ref_ptr<osg::Geometry> sourceGeometry = rig->getSourceGeometry();
|
|
|
|
|
if (sourceGeometry && adjustGeometry(*sourceGeometry, reqs))
|
|
|
|
|
rig->setSourceGeometry(sourceGeometry);
|
|
|
|
|
}
|
|
|
|
|
else if (auto morph = dynamic_cast<SceneUtil::MorphGeometry*>(&drawable))
|
|
|
|
|
if (needPop)
|
|
|
|
|
{
|
|
|
|
|
osg::ref_ptr<osg::Geometry> sourceGeometry = morph->getSourceGeometry();
|
|
|
|
|
if (sourceGeometry && adjustGeometry(*sourceGeometry, reqs))
|
|
|
|
|
morph->setSourceGeometry(sourceGeometry);
|
|
|
|
|
pushRequirements(drawable);
|
|
|
|
|
|
|
|
|
|
if (drawable.getStateSet())
|
|
|
|
|
applyStateSet(drawable.getStateSet(), drawable);
|
|
|
|
|
}
|
|
|
|
|
else if (auto osgaRig = dynamic_cast<SceneUtil::RigGeometryHolder*>(&drawable))
|
|
|
|
|
|
|
|
|
|
if (!mRequirements.empty())
|
|
|
|
|
{
|
|
|
|
|
osg::ref_ptr<SceneUtil::OsgaRigGeometry> sourceOsgaRigGeometry = osgaRig->getSourceRigGeometry();
|
|
|
|
|
osg::ref_ptr<osg::Geometry> sourceGeometry = sourceOsgaRigGeometry->getSourceGeometry();
|
|
|
|
|
if (sourceGeometry && adjustGeometry(*sourceGeometry, reqs))
|
|
|
|
|
const ShaderRequirements& reqs = mRequirements.back();
|
|
|
|
|
createProgram(reqs);
|
|
|
|
|
|
|
|
|
|
if (auto rig = dynamic_cast<SceneUtil::RigGeometry*>(&drawable))
|
|
|
|
|
{
|
|
|
|
|
sourceOsgaRigGeometry->setSourceGeometry(sourceGeometry);
|
|
|
|
|
osgaRig->setSourceRigGeometry(sourceOsgaRigGeometry);
|
|
|
|
|
osg::ref_ptr<osg::Geometry> sourceGeometry = rig->getSourceGeometry();
|
|
|
|
|
if (sourceGeometry && adjustGeometry(*sourceGeometry, reqs))
|
|
|
|
|
rig->setSourceGeometry(sourceGeometry);
|
|
|
|
|
}
|
|
|
|
|
else if (auto morph = dynamic_cast<SceneUtil::MorphGeometry*>(&drawable))
|
|
|
|
|
{
|
|
|
|
|
osg::ref_ptr<osg::Geometry> sourceGeometry = morph->getSourceGeometry();
|
|
|
|
|
if (sourceGeometry && adjustGeometry(*sourceGeometry, reqs))
|
|
|
|
|
morph->setSourceGeometry(sourceGeometry);
|
|
|
|
|
}
|
|
|
|
|
else if (auto osgaRig = dynamic_cast<SceneUtil::RigGeometryHolder*>(&drawable))
|
|
|
|
|
{
|
|
|
|
|
osg::ref_ptr<SceneUtil::OsgaRigGeometry> sourceOsgaRigGeometry = osgaRig->getSourceRigGeometry();
|
|
|
|
|
osg::ref_ptr<osg::Geometry> sourceGeometry = sourceOsgaRigGeometry->getSourceGeometry();
|
|
|
|
|
if (sourceGeometry && adjustGeometry(*sourceGeometry, reqs))
|
|
|
|
|
{
|
|
|
|
|
sourceOsgaRigGeometry->setSourceGeometry(sourceGeometry);
|
|
|
|
|
osgaRig->setSourceRigGeometry(sourceOsgaRigGeometry);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
ensureFFP(drawable);
|
|
|
|
|
|
|
|
|
|
popRequirements();
|
|
|
|
|
if (needPop)
|
|
|
|
|
popRequirements();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ShaderVisitor::setAllowedToModifyStateSets(bool allowed)
|
|
|
|
|