diff --git a/apps/openmw/mwrender/sky.cpp b/apps/openmw/mwrender/sky.cpp index b74a822f14..c16a1ee56c 100644 --- a/apps/openmw/mwrender/sky.cpp +++ b/apps/openmw/mwrender/sky.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -472,14 +473,20 @@ public: osg::ref_ptr queryNode (new osg::Group); // Need to render after the world geometry so we can correctly test for occlusions - queryNode->getOrCreateStateSet()->setRenderBinDetails(RenderBin_OcclusionQuery, "RenderBin"); - queryNode->getOrCreateStateSet()->setNestRenderBins(false); + osg::StateSet* stateset = queryNode->getOrCreateStateSet(); + stateset->setRenderBinDetails(RenderBin_OcclusionQuery, "RenderBin"); + stateset->setNestRenderBins(false); // Set up alpha testing on the occlusion testing subgraph, that way we can get the occlusion tested fragments to match the circular shape of the sun osg::ref_ptr alphaFunc (new osg::AlphaFunc); alphaFunc->setFunction(osg::AlphaFunc::GREATER, 0.8); - queryNode->getOrCreateStateSet()->setAttributeAndModes(alphaFunc, osg::StateAttribute::ON); - queryNode->getOrCreateStateSet()->setTextureAttributeAndModes(0, sunTex, osg::StateAttribute::ON); - queryNode->getOrCreateStateSet()->setAttributeAndModes(createUnlitMaterial(), osg::StateAttribute::ON); + stateset->setAttributeAndModes(alphaFunc, osg::StateAttribute::ON); + stateset->setTextureAttributeAndModes(0, sunTex, osg::StateAttribute::ON); + stateset->setAttributeAndModes(createUnlitMaterial(), osg::StateAttribute::ON); + // Disable writing to the color buffer. We are using this geometry for visibility tests only. + osg::ref_ptr colormask (new osg::ColorMask(0, 0, 0, 0)); + stateset->setAttributeAndModes(colormask, osg::StateAttribute::ON); + osg::ref_ptr po (new osg::PolygonOffset( -1., -1. )); + stateset->setAttributeAndModes(po, osg::StateAttribute::ON); mTransform->addChild(queryNode); @@ -543,15 +550,8 @@ private: oqn->getQueryGeometry()->setDataVariance(osg::Object::STATIC); osg::ref_ptr queryGeom = osg::clone(mGeom.get(), osg::CopyOp::DEEP_COPY_ALL); - // Disable writing to the color buffer. We are using this geometry for visibility tests only. - osg::ref_ptr colormask (new osg::ColorMask(0, 0, 0, 0)); - queryGeom->getOrCreateStateSet()->setAttributeAndModes(colormask, osg::StateAttribute::ON); - oqn->addChild(queryGeom); - // Remove the default OFF|PROTECTED setting for texturing. We *want* to enable texturing for alpha testing purposes - oqn->getQueryStateSet()->removeTextureMode(0, GL_TEXTURE_2D); - // Need to add texture coordinates so that texturing works. A bit ugly, relies on the vertex ordering // used within OcclusionQueryNode. osg::ref_ptr texCoordArray (new osg::Vec2Array); @@ -569,6 +569,7 @@ private: oqn->getQueryGeometry()->setTexCoordArray(0, texCoordArray, osg::Array::BIND_PER_VERTEX); + osg::StateSet* queryStateSet = new osg::StateSet; if (queryVisible) { osg::ref_ptr depth (new osg::Depth); @@ -578,12 +579,14 @@ private: // We want the sun glare to be "infinitely" far away. depth->setZNear(1.0); depth->setZFar(1.0); - oqn->getQueryStateSet()->setAttributeAndModes(depth, osg::StateAttribute::ON); + depth->setWriteMask(false); + queryStateSet->setAttributeAndModes(depth, osg::StateAttribute::ON); } else { - oqn->getQueryStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF); + queryStateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF); } + oqn->setQueryStateSet(queryStateSet); parent->addChild(oqn);