mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-31 23:15:43 +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:
commit
a6989dcb12
5 changed files with 71 additions and 56 deletions
|
@ -157,6 +157,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"
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "morphgeometry.hpp"
|
#include "morphgeometry.hpp"
|
||||||
|
|
||||||
|
#include <osgUtil/CullVisitor>
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <components/resource/scenemanager.hpp>
|
#include <components/resource/scenemanager.hpp>
|
||||||
|
|
||||||
|
@ -87,7 +89,18 @@ void MorphGeometry::accept(osg::NodeVisitor &nv)
|
||||||
nv.pushOntoNodePath(this);
|
nv.pushOntoNodePath(this);
|
||||||
|
|
||||||
if (nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR)
|
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);
|
cull(&nv);
|
||||||
|
if (stateset)
|
||||||
|
cv->popStateSet();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
nv.apply(*this);
|
nv.apply(*this);
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
#include "riggeometry.hpp"
|
#include "riggeometry.hpp"
|
||||||
|
|
||||||
|
#include <osg/MatrixTransform>
|
||||||
|
|
||||||
|
#include <osgUtil/CullVisitor>
|
||||||
|
|
||||||
#include <components/debug/debuglog.hpp>
|
#include <components/debug/debuglog.hpp>
|
||||||
#include <components/resource/scenemanager.hpp>
|
#include <components/resource/scenemanager.hpp>
|
||||||
#include <osg/MatrixTransform>
|
|
||||||
|
|
||||||
#include "skeleton.hpp"
|
#include "skeleton.hpp"
|
||||||
#include "util.hpp"
|
#include "util.hpp"
|
||||||
|
@ -387,7 +390,18 @@ void RigGeometry::accept(osg::NodeVisitor &nv)
|
||||||
nv.pushOntoNodePath(this);
|
nv.pushOntoNodePath(this);
|
||||||
|
|
||||||
if (nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR)
|
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);
|
cull(&nv);
|
||||||
|
if (stateset)
|
||||||
|
cv->popStateSet();
|
||||||
|
}
|
||||||
else if (nv.getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR)
|
else if (nv.getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR)
|
||||||
updateBounds(&nv);
|
updateBounds(&nv);
|
||||||
else
|
else
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
#include <osg/Drawable>
|
#include <osg/Drawable>
|
||||||
#include <osg/NodeVisitor>
|
#include <osg/NodeVisitor>
|
||||||
|
|
||||||
|
#include <osgUtil/CullVisitor>
|
||||||
|
|
||||||
#include <components/debug/debuglog.hpp>
|
#include <components/debug/debuglog.hpp>
|
||||||
#include <components/resource/scenemanager.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())
|
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();
|
unsigned int traversalNumber = nv.getTraversalNumber();
|
||||||
if (mLastFrameNumber == traversalNumber)
|
if (mLastFrameNumber == traversalNumber)
|
||||||
{
|
{
|
||||||
|
@ -255,6 +264,8 @@ void RigGeometryHolder::accept(osg::NodeVisitor &nv)
|
||||||
nv.apply(geom);
|
nv.apply(geom);
|
||||||
nv.popFromNodePath();
|
nv.popFromNodePath();
|
||||||
}
|
}
|
||||||
|
if (stateset)
|
||||||
|
cv->popStateSet();
|
||||||
}
|
}
|
||||||
else if (nv.getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR)
|
else if (nv.getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR)
|
||||||
{
|
{
|
||||||
|
|
|
@ -820,74 +820,50 @@ 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);
|
||||||
const ShaderRequirements& reqs = mRequirements.back();
|
createProgram(reqs);
|
||||||
|
|
||||||
adjustGeometry(geometry, reqs);
|
popRequirements();
|
||||||
|
|
||||||
createProgram(reqs);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
ensureFFP(geometry);
|
|
||||||
|
|
||||||
if (needPop)
|
|
||||||
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);
|
||||||
|
|
||||||
|
const ShaderRequirements& reqs = mRequirements.back();
|
||||||
|
createProgram(reqs);
|
||||||
|
|
||||||
|
if (auto rig = dynamic_cast<SceneUtil::RigGeometry*>(&drawable))
|
||||||
{
|
{
|
||||||
pushRequirements(drawable);
|
osg::ref_ptr<osg::Geometry> sourceGeometry = rig->getSourceGeometry();
|
||||||
|
if (sourceGeometry && adjustGeometry(*sourceGeometry, reqs))
|
||||||
if (drawable.getStateSet())
|
rig->setSourceGeometry(sourceGeometry);
|
||||||
applyStateSet(drawable.getStateSet(), drawable);
|
|
||||||
}
|
}
|
||||||
|
else if (auto morph = dynamic_cast<SceneUtil::MorphGeometry*>(&drawable))
|
||||||
if (!mRequirements.empty())
|
|
||||||
{
|
{
|
||||||
const ShaderRequirements& reqs = mRequirements.back();
|
osg::ref_ptr<osg::Geometry> sourceGeometry = morph->getSourceGeometry();
|
||||||
createProgram(reqs);
|
if (sourceGeometry && adjustGeometry(*sourceGeometry, reqs))
|
||||||
|
morph->setSourceGeometry(sourceGeometry);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else if (auto osgaRig = dynamic_cast<SceneUtil::RigGeometryHolder*>(&drawable))
|
||||||
ensureFFP(drawable);
|
{
|
||||||
|
osg::ref_ptr<SceneUtil::OsgaRigGeometry> sourceOsgaRigGeometry = osgaRig->getSourceRigGeometry();
|
||||||
if (needPop)
|
osg::ref_ptr<osg::Geometry> sourceGeometry = sourceOsgaRigGeometry->getSourceGeometry();
|
||||||
popRequirements();
|
if (sourceGeometry && adjustGeometry(*sourceGeometry, reqs))
|
||||||
|
{
|
||||||
|
sourceOsgaRigGeometry->setSourceGeometry(sourceGeometry);
|
||||||
|
osgaRig->setSourceRigGeometry(sourceOsgaRigGeometry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
popRequirements();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderVisitor::setAllowedToModifyStateSets(bool allowed)
|
void ShaderVisitor::setAllowedToModifyStateSets(bool allowed)
|
||||||
|
|
Loading…
Reference in a new issue