From 4b8897e33ea2e6749f90a81dae0a225569168d4d Mon Sep 17 00:00:00 2001 From: elsid Date: Sun, 19 May 2024 02:14:56 +0200 Subject: [PATCH] Use state sets without transparency support for recast mesh and agents paths --- apps/openmw/mwrender/actorspaths.cpp | 11 +++++++++- apps/openmw/mwrender/navmesh.cpp | 28 +++++++++++++++++++++++- apps/openmw/mwrender/recastmesh.cpp | 13 ++++++++++- components/sceneutil/detourdebugdraw.cpp | 12 ---------- components/sceneutil/detourdebugdraw.hpp | 2 -- 5 files changed, 49 insertions(+), 17 deletions(-) diff --git a/apps/openmw/mwrender/actorspaths.cpp b/apps/openmw/mwrender/actorspaths.cpp index b48da306c8..2a36e99f79 100644 --- a/apps/openmw/mwrender/actorspaths.cpp +++ b/apps/openmw/mwrender/actorspaths.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -30,13 +31,21 @@ namespace MWRender stateSet->setAttribute(material); return stateSet; } + + osg::ref_ptr makeDebugDrawStateSet() + { + osg::ref_ptr stateSet = new osg::StateSet; + stateSet->setAttributeAndModes(new osg::LineWidth()); + + return stateSet; + } } ActorsPaths::ActorsPaths(const osg::ref_ptr& root, bool enabled) : mRootNode(root) , mEnabled(enabled) , mGroupStateSet(makeGroupStateSet()) - , mDebugDrawStateSet(SceneUtil::DebugDraw::makeStateSet()) + , mDebugDrawStateSet(makeDebugDrawStateSet()) { } diff --git a/apps/openmw/mwrender/navmesh.cpp b/apps/openmw/mwrender/navmesh.cpp index e1ab0fbc37..f1100ba502 100644 --- a/apps/openmw/mwrender/navmesh.cpp +++ b/apps/openmw/mwrender/navmesh.cpp @@ -7,10 +7,13 @@ #include #include #include +#include #include #include #include +#include +#include #include #include @@ -23,6 +26,29 @@ namespace MWRender { + namespace + { + osg::ref_ptr makeDebugDrawStateSet() + { + const osg::ref_ptr lineWidth = new osg::LineWidth(); + + const osg::ref_ptr blendFunc = new osg::BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + const osg::ref_ptr depth = new SceneUtil::AutoDepth; + depth->setWriteMask(false); + + osg::ref_ptr stateSet = new osg::StateSet; + stateSet->setMode(GL_BLEND, osg::StateAttribute::ON); + stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF); + stateSet->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); + stateSet->setAttributeAndModes(lineWidth); + stateSet->setAttributeAndModes(blendFunc); + stateSet->setAttributeAndModes(depth); + + return stateSet; + } + } + struct NavMesh::LessByTilePosition { bool operator()(const DetourNavigator::TilePosition& lhs, @@ -169,7 +195,7 @@ namespace MWRender : mRootNode(root) , mWorkQueue(workQueue) , mGroupStateSet(SceneUtil::makeDetourGroupStateSet()) - , mDebugDrawStateSet(SceneUtil::DebugDraw::makeStateSet()) + , mDebugDrawStateSet(makeDebugDrawStateSet()) , mEnabled(enabled) , mMode(mode) , mId(std::numeric_limits::max()) diff --git a/apps/openmw/mwrender/recastmesh.cpp b/apps/openmw/mwrender/recastmesh.cpp index 36a56a1eda..30cfa82493 100644 --- a/apps/openmw/mwrender/recastmesh.cpp +++ b/apps/openmw/mwrender/recastmesh.cpp @@ -17,11 +17,22 @@ namespace MWRender { + namespace + { + osg::ref_ptr makeDebugDrawStateSet() + { + osg::ref_ptr stateSet = new osg::StateSet; + stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF); + + return stateSet; + } + } + RecastMesh::RecastMesh(const osg::ref_ptr& root, bool enabled) : mRootNode(root) , mEnabled(enabled) , mGroupStateSet(SceneUtil::makeDetourGroupStateSet()) - , mDebugDrawStateSet(SceneUtil::DebugDraw::makeStateSet()) + , mDebugDrawStateSet(makeDebugDrawStateSet()) { } diff --git a/components/sceneutil/detourdebugdraw.cpp b/components/sceneutil/detourdebugdraw.cpp index d6bba027eb..bd03c8383e 100644 --- a/components/sceneutil/detourdebugdraw.cpp +++ b/components/sceneutil/detourdebugdraw.cpp @@ -108,18 +108,6 @@ namespace SceneUtil mColors->push_back(value); } - osg::ref_ptr DebugDraw::makeStateSet() - { - osg::ref_ptr stateSet = new osg::StateSet; - stateSet->setMode(GL_BLEND, osg::StateAttribute::ON); - stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF); - stateSet->setMode(GL_DEPTH, osg::StateAttribute::OFF); - stateSet->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); - stateSet->setAttributeAndModes(new osg::LineWidth()); - stateSet->setAttributeAndModes(new osg::BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); - return stateSet; - } - osg::ref_ptr makeDetourGroupStateSet() { osg::ref_ptr material = new osg::Material; diff --git a/components/sceneutil/detourdebugdraw.hpp b/components/sceneutil/detourdebugdraw.hpp index e8606fd792..66e4e4103a 100644 --- a/components/sceneutil/detourdebugdraw.hpp +++ b/components/sceneutil/detourdebugdraw.hpp @@ -18,8 +18,6 @@ namespace SceneUtil explicit DebugDraw(osg::Group& group, const osg::ref_ptr& stateSet, const osg::Vec3f& shift, float recastInvertedScaleFactor); - static osg::ref_ptr makeStateSet(); - void depthMask(bool state) override; void texture(bool state) override;