1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-31 23:45:35 +00:00

Merge branch 'shadervisitor48' into 'openmw-48'

Fixes to shader rendering state handling (0.48.0)

See merge request OpenMW/openmw!2783
This commit is contained in:
psi29a 2023-03-04 12:41:36 +00:00
commit a6989dcb12
5 changed files with 71 additions and 56 deletions

View file

@ -157,6 +157,7 @@
Bug #6937: Divided by Nix Hounds quest is broken
Bug #7008: Race condition on initializing a vector of reserved node names
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 #1465: "Reset" argument for AI functions
Feature #2491: Ability to make OpenMW "portable"

View file

@ -1,5 +1,7 @@
#include "morphgeometry.hpp"
#include <osgUtil/CullVisitor>
#include <cassert>
#include <components/resource/scenemanager.hpp>
@ -87,7 +89,18 @@ void MorphGeometry::accept(osg::NodeVisitor &nv)
nv.pushOntoNodePath(this);
if (nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR)
{
// The cull visitor won't be applied to the node itself,
// but we want to use its state to render the child geometry.
osg::StateSet* stateset = getStateSet();
osgUtil::CullVisitor* cv = static_cast<osgUtil::CullVisitor*>(&nv);
if (stateset)
cv->pushStateSet(stateset);
cull(&nv);
if (stateset)
cv->popStateSet();
}
else
nv.apply(*this);

View file

@ -1,8 +1,11 @@
#include "riggeometry.hpp"
#include <osg/MatrixTransform>
#include <osgUtil/CullVisitor>
#include <components/debug/debuglog.hpp>
#include <components/resource/scenemanager.hpp>
#include <osg/MatrixTransform>
#include "skeleton.hpp"
#include "util.hpp"
@ -387,7 +390,18 @@ void RigGeometry::accept(osg::NodeVisitor &nv)
nv.pushOntoNodePath(this);
if (nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR)
{
// The cull visitor won't be applied to the node itself,
// but we want to use its state to render the child geometry.
osg::StateSet* stateset = getStateSet();
osgUtil::CullVisitor* cv = static_cast<osgUtil::CullVisitor*>(&nv);
if (stateset)
cv->pushStateSet(stateset);
cull(&nv);
if (stateset)
cv->popStateSet();
}
else if (nv.getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR)
updateBounds(&nv);
else

View file

@ -5,6 +5,8 @@
#include <osg/Drawable>
#include <osg/NodeVisitor>
#include <osgUtil/CullVisitor>
#include <components/debug/debuglog.hpp>
#include <components/resource/scenemanager.hpp>
@ -220,6 +222,13 @@ void RigGeometryHolder::accept(osg::NodeVisitor &nv)
if (nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR && mSourceRigGeometry.get())
{
// The cull visitor won't be applied to the node itself,
// but we want to use its state to render the child geometry.
osg::StateSet* stateset = getStateSet();
osgUtil::CullVisitor* cv = static_cast<osgUtil::CullVisitor*>(&nv);
if (stateset)
cv->pushStateSet(stateset);
unsigned int traversalNumber = nv.getTraversalNumber();
if (mLastFrameNumber == traversalNumber)
{
@ -255,6 +264,8 @@ void RigGeometryHolder::accept(osg::NodeVisitor &nv)
nv.apply(geom);
nv.popFromNodePath();
}
if (stateset)
cv->popStateSet();
}
else if (nv.getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR)
{

View file

@ -820,74 +820,50 @@ namespace Shader
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
{
pushRequirements(geometry);
applyStateSet(geometry.getStateSet(), geometry);
}
if (!mRequirements.empty())
{
const ShaderRequirements& reqs = mRequirements.back();
const ShaderRequirements& reqs = mRequirements.back();
adjustGeometry(geometry, reqs);
createProgram(reqs);
adjustGeometry(geometry, reqs);
createProgram(reqs);
}
else
ensureFFP(geometry);
if (needPop)
popRequirements();
popRequirements();
}
void ShaderVisitor::apply(osg::Drawable& drawable)
{
bool needPop = drawable.getStateSet();
pushRequirements(drawable);
if (needPop)
if (drawable.getStateSet())
applyStateSet(drawable.getStateSet(), drawable);
const ShaderRequirements& reqs = mRequirements.back();
createProgram(reqs);
if (auto rig = dynamic_cast<SceneUtil::RigGeometry*>(&drawable))
{
pushRequirements(drawable);
if (drawable.getStateSet())
applyStateSet(drawable.getStateSet(), drawable);
osg::ref_ptr<osg::Geometry> sourceGeometry = rig->getSourceGeometry();
if (sourceGeometry && adjustGeometry(*sourceGeometry, reqs))
rig->setSourceGeometry(sourceGeometry);
}
if (!mRequirements.empty())
else if (auto morph = dynamic_cast<SceneUtil::MorphGeometry*>(&drawable))
{
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))
{
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);
}
}
osg::ref_ptr<osg::Geometry> sourceGeometry = morph->getSourceGeometry();
if (sourceGeometry && adjustGeometry(*sourceGeometry, reqs))
morph->setSourceGeometry(sourceGeometry);
}
else
ensureFFP(drawable);
if (needPop)
popRequirements();
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);
}
}
popRequirements();
}
void ShaderVisitor::setAllowedToModifyStateSets(bool allowed)