Attach shaders to geometry that lacks a stateset if necessary

depth-refraction
Alexei Dobrohotov 2 years ago
parent a9fdb51041
commit 6aef366fd3

@ -225,6 +225,7 @@
Bug #6937: Divided by Nix Hounds quest is broken Bug #6937: Divided by Nix Hounds quest is broken
Bug #7008: Race condition on initializing a vector of reserved node names Bug #7008: Race condition on initializing a vector of reserved node names
Bug #7121: Crash on TimeStamp construction with invalid hour value Bug #7121: Crash on TimeStamp construction with invalid hour value
Bug #7251: Force shaders setting still renders some drawables with FFP
Feature #890: OpenMW-CS: Column filtering Feature #890: OpenMW-CS: Column filtering
Feature #1465: "Reset" argument for AI functions Feature #1465: "Reset" argument for AI functions
Feature #2491: Ability to make OpenMW "portable" Feature #2491: Ability to make OpenMW "portable"

@ -612,9 +612,6 @@ namespace MWRender
mRootNode->getOrCreateStateSet()->setAttributeAndModes(clipcontrol, osg::StateAttribute::ON); mRootNode->getOrCreateStateSet()->setAttributeAndModes(clipcontrol, osg::StateAttribute::ON);
} }
// Assign a default shader on root to handle empty statesets
mResourceSystem->getSceneManager()->recreateShaders(mRootNode, "objects");
SceneUtil::setCameraClearDepth(mViewer->getCamera()); SceneUtil::setCameraClearDepth(mViewer->getCamera());
updateProjectionMatrix(); updateProjectionMatrix();

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

Loading…
Cancel
Save