Added cached Depth and ColorMask to reduce the amount of duplicate state in the osgUI subgraph

This commit is contained in:
Robert Osfield 2014-05-28 10:18:57 +00:00
parent 1fcb91900a
commit 26a7c30229
2 changed files with 12 additions and 3 deletions

View File

@ -17,6 +17,8 @@
#include <osg/Object>
#include <osg/BoundingBox>
#include <osg/Texture2D>
#include <osg/Depth>
#include <osg/ColorMask>
#include <osg/Vec4>
#include <osgUI/AlignmentSettings>
@ -55,6 +57,9 @@ public:
protected:
virtual ~Style() {}
osg::ref_ptr<osg::Depth> _disabledDepthWrite;
osg::ref_ptr<osg::Depth> _enabledDepthWrite;
osg::ref_ptr<osg::ColorMask> _disableColorWriteMask;
osg::ref_ptr<osg::Texture2D> _clipTexture;
osg::Vec4 _backgroundColor;

View File

@ -45,6 +45,10 @@ Style::Style()
//image = osgDB::readImageFile("Images/lz.rgb");
//_clipTexture->setImage(image.get());
_disabledDepthWrite = new osg::Depth(osg::Depth::LESS,0.0, 1.0,false);
_enabledDepthWrite = new osg::Depth(osg::Depth::LESS,0.0, 1.0,true);
_disableColorWriteMask = new osg::ColorMask(false, false, false, false);
}
Style::Style(const Style& style, const osg::CopyOp& copyop):
@ -91,8 +95,8 @@ osg::Node* Style::createDepthSetPanel(const osg::BoundingBox& extents)
geometry->addPrimitiveSet( new osg::DrawArrays(GL_TRIANGLE_STRIP, 0, 4) );
osg::ref_ptr<osg::StateSet> stateset = geometry->getOrCreateStateSet();
stateset->setAttributeAndModes( new osg::Depth(osg::Depth::LESS,0.0, 1.0,true), osg::StateAttribute::ON);
stateset->setAttributeAndModes( new osg::ColorMask(false, false, false, false));
stateset->setAttributeAndModes( _enabledDepthWrite.get(), osg::StateAttribute::ON);
stateset->setAttributeAndModes( _disableColorWriteMask.get() );
return geometry.release();
}
@ -136,7 +140,7 @@ void Style::setupDialogStateSet(osg::StateSet* stateset)
{
stateset->setRenderBinDetails(5, "TraversalOrderBin", osg::StateSet::OVERRIDE_RENDERBIN_DETAILS);
stateset->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
stateset->setAttributeAndModes( new osg::Depth(osg::Depth::LESS,0.0, 1.0,false), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE );
stateset->setAttributeAndModes( _disabledDepthWrite.get(), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE );
}
void Style::setupClipStateSet(const osg::BoundingBox& extents, osg::StateSet* stateset)