From 6cc71745acbb355ec9ad014391e31dc6539194f3 Mon Sep 17 00:00:00 2001 From: "glassmancody.info" Date: Sat, 14 Aug 2021 14:50:33 -0700 Subject: [PATCH] ensure character preview is using standard depth --- apps/openmw/mwrender/characterpreview.cpp | 26 +++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwrender/characterpreview.cpp b/apps/openmw/mwrender/characterpreview.cpp index 580451ff8f..5c805ca856 100644 --- a/apps/openmw/mwrender/characterpreview.cpp +++ b/apps/openmw/mwrender/characterpreview.cpp @@ -131,6 +131,29 @@ namespace MWRender newStateSet->setTextureMode(7, GL_TEXTURE_2D, osg::StateAttribute::OFF); newStateSet->addUniform(mNoAlphaUniform); } + if (SceneUtil::getReverseZ() && stateset->getAttribute(osg::StateAttribute::DEPTH)) + { + if (!newStateSet) + { + newStateSet = new osg::StateSet(*stateset, osg::CopyOp::SHALLOW_COPY); + node.setStateSet(newStateSet); + } + // Setup standard depth ranges + osg::Depth* depth = static_cast(stateset->getAttribute(osg::StateAttribute::DEPTH)); + osg::ref_ptr newDepth = new osg::Depth(*depth); + switch (newDepth->getFunction()) + { + case osg::Depth::LESS: + newDepth->setFunction(osg::Depth::GREATER); + case osg::Depth::LEQUAL: + newDepth->setFunction(osg::Depth::GEQUAL); + case osg::Depth::GREATER: + newDepth->setFunction(osg::Depth::LESS); + case osg::Depth::GEQUAL: + newDepth->setFunction(osg::Depth::LEQUAL); + } + newStateSet->setAttribute(newDepth, osg::StateAttribute::ON); + } } traverse(node); } @@ -189,8 +212,7 @@ namespace MWRender stateset->setAttribute(defaultMat); stateset->addUniform(new osg::Uniform("projectionMatrix", static_cast(mCamera->getProjectionMatrix()))); - osg::ref_ptr depth = new osg::Depth; - stateset->setAttributeAndModes(depth, osg::StateAttribute::ON); + stateset->setAttributeAndModes(new osg::Depth, osg::StateAttribute::ON); SceneUtil::ShadowManager::disableShadowsForStateSet(stateset);