From 36330f7e400bb4730e625fba97e528cfa95de0a9 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 27 Jan 2007 11:13:01 +0000 Subject: [PATCH] Changed osgUtil::RenderBin and osg::State to allow nesting of StateSet's associated with RenderBin's. --- include/osg/State | 13 ++++++++++++- src/osgUtil/RenderBin.cpp | 18 +++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/include/osg/State b/include/osg/State index ac1796016..8cab54d79 100644 --- a/include/osg/State +++ b/include/osg/State @@ -124,6 +124,18 @@ class OSG_EXPORT State : public Referenced /** pop all statesets off state stack, ensuring it is empty ready for the next frame. * Note, to return OpenGL to default state, one should do any state.popAllStatSets(); state.apply().*/ void popAllStateSets(); + + /** Get the number of StateSet's on the StateSet stack.*/ + unsigned int getStateSetStackSize() { return _stateStateStack.size(); } + + /** Pop StateSet's for the StateSet stack till its size equals the specified size.*/ + void popStateSetStackToSize(unsigned int size) { while (_stateStateStack.size()>size) popStateSet(); } + + typedef std::vector StateSetStack; + + /** Get the StateSet stack.*/ + StateSetStack& getStateSetStack() { return _stateStateStack; } + /** Copy the modes and attributes which capture the current state.*/ void captureCurrentState(StateSet& stateset) const; @@ -906,7 +918,6 @@ class OSG_EXPORT State : public Referenced typedef std::map UniformMap; - typedef std::vector StateSetStack; typedef std::vector > MatrixStack; typedef std::set > AppliedProgramObjectSet; diff --git a/src/osgUtil/RenderBin.cpp b/src/osgUtil/RenderBin.cpp index 1f6599bb1..5fe079391 100644 --- a/src/osgUtil/RenderBin.cpp +++ b/src/osgUtil/RenderBin.cpp @@ -367,11 +367,13 @@ void RenderBin::drawImplementation(osg::RenderInfo& renderInfo,RenderLeaf*& prev // osg::notify(osg::NOTICE)<<"begin RenderBin::drawImplementation "<second->draw(renderInfo,previous); } + if (stateSetStackSize!=state.getStateSetStackSize()) + { + state.popStateSetStackToSize(stateSetStackSize); + } + + previous = 0; + if (_stateset.valid()) { - state.popAllStateSets(); - previous = 0; + } //osg::notify(osg::NOTICE)<<"end RenderBin::drawImplementation "<