diff --git a/include/osgUtil/RenderBin b/include/osgUtil/RenderBin index c2e260bbd..b731a530d 100644 --- a/include/osgUtil/RenderBin +++ b/include/osgUtil/RenderBin @@ -72,6 +72,11 @@ class OSGUTIL_EXPORT RenderBin : public osg::Object virtual void reset(); + void setStateSet(osg::StateSet* stateset) { _stateset = stateset; } + osg::StateSet* getStateSet() { return _stateset.get(); } + const osg::StateSet* getStateSet() const { return _stateset.get(); } + + RenderBin* getParent() { return _parent; } const RenderBin* getParent() const { return _parent; } @@ -149,12 +154,12 @@ class OSGUTIL_EXPORT RenderBin : public osg::Object StateGraphList _stateGraphList; RenderLeafList _renderLeafList; - SortMode _sortMode; osg::ref_ptr _sortCallback; osg::ref_ptr _drawCallback; + osg::ref_ptr _stateset; }; diff --git a/src/osg/AlphaFunc.cpp b/src/osg/AlphaFunc.cpp index 5e941d941..b235c3302 100644 --- a/src/osg/AlphaFunc.cpp +++ b/src/osg/AlphaFunc.cpp @@ -12,6 +12,7 @@ */ #include +#include using namespace osg; diff --git a/src/osg/StateSet.cpp b/src/osg/StateSet.cpp index 6302cde33..fc39b1285 100644 --- a/src/osg/StateSet.cpp +++ b/src/osg/StateSet.cpp @@ -423,7 +423,7 @@ void StateSet::setGlobalDefaults() setMode(GL_DEPTH_TEST,StateAttribute::ON); - setAttributeAndModes(new AlphaFunc,StateAttribute::OFF); + // setAttributeAndModes(new AlphaFunc,StateAttribute::OFF); setAttributeAndModes(new BlendFunc,StateAttribute::OFF); Material *material = new Material; diff --git a/src/osgProducer/Viewer.cpp b/src/osgProducer/Viewer.cpp index 8510594fb..6f444bf0d 100644 --- a/src/osgProducer/Viewer.cpp +++ b/src/osgProducer/Viewer.cpp @@ -398,11 +398,12 @@ void Viewer::setUpViewer(unsigned int options) // enable depth testing by default. globalStateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON); - +#if 0 // set up an alphafunc by default to speed up blending operations. osg::AlphaFunc* alphafunc = new osg::AlphaFunc; alphafunc->setFunction(osg::AlphaFunc::GREATER,0.0f); globalStateSet->setAttributeAndModes(alphafunc, osg::StateAttribute::ON); +#endif } if (options & HEAD_LIGHT_SOURCE || options & SKY_LIGHT_SOURCE) diff --git a/src/osgUtil/RenderBin.cpp b/src/osgUtil/RenderBin.cpp index e327a3bf2..4586e4ad6 100644 --- a/src/osgUtil/RenderBin.cpp +++ b/src/osgUtil/RenderBin.cpp @@ -16,6 +16,7 @@ #include #include +#include #include @@ -128,6 +129,21 @@ RenderBin::RenderBin(SortMode mode) _parent = NULL; _stage = NULL; _sortMode = mode; + +#if 1 + if (_sortMode==SORT_BACK_TO_FRONT) + { + _stateset = new osg::StateSet; + _stateset->setThreadSafeRefUnref(true); + + // set up an alphafunc by default to speed up blending operations. + osg::AlphaFunc* alphafunc = new osg::AlphaFunc; + alphafunc->setFunction(osg::AlphaFunc::GREATER,0.0f); + alphafunc->setThreadSafeRefUnref(true); + + _stateset->setAttributeAndModes(alphafunc, osg::StateAttribute::ON); + } +#endif } RenderBin::RenderBin(const RenderBin& rhs,const CopyOp& copyop): @@ -140,7 +156,8 @@ RenderBin::RenderBin(const RenderBin& rhs,const CopyOp& copyop): _renderLeafList(rhs._renderLeafList), _sortMode(rhs._sortMode), _sortCallback(rhs._sortCallback), - _drawCallback(rhs._drawCallback) + _drawCallback(rhs._drawCallback), + _stateset(rhs._stateset) { } @@ -348,6 +365,11 @@ void RenderBin::drawImplementation(osg::State& state,RenderLeaf*& previous) { // osg::notify(osg::NOTICE)<<"begin RenderBin::drawImplementation "<second->draw(state,previous); } + if (_stateset.valid()) state.popStateSet(); + //osg::notify(osg::NOTICE)<<"end RenderBin::drawImplementation "<setMode(GL_DEPTH_TEST, osg::StateAttribute::ON); +#if 0 // set up an alphafunc by default to speed up blending operations. osg::AlphaFunc* alphafunc = new osg::AlphaFunc; - alphafunc->setFunction(osg::AlphaFunc::GREATER,0.0f); - _globalStateSet->setAttributeAndModes(alphafunc, osg::StateAttribute::ON); + alphafunc->setFunction(osg::AlphaFunc::GREATER,1.0f); + _globalStateSet->setAttributeAndModes(alphafunc, osg::StateAttribute::OFF); +#endif // set up an texture environment by default to speed up blending operations. osg::TexEnv* texenv = new osg::TexEnv; diff --git a/src/osgWrappers/osgUtil/RenderBin.cpp b/src/osgWrappers/osgUtil/RenderBin.cpp index 809d43d34..e830f315a 100644 --- a/src/osgWrappers/osgUtil/RenderBin.cpp +++ b/src/osgWrappers/osgUtil/RenderBin.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -54,6 +55,9 @@ BEGIN_OBJECT_REFLECTOR(osgUtil::RenderBin) I_Method0(const char *, libraryName); I_Method0(const char *, className); I_Method0(void, reset); + I_Method1(void, setStateSet, IN, osg::StateSet *, stateset); + I_Method0(osg::StateSet *, getStateSet); + I_Method0(const osg::StateSet *, getStateSet); I_Method0(osgUtil::RenderBin *, getParent); I_Method0(const osgUtil::RenderBin *, getParent); I_Method0(osgUtil::RenderStage *, getStage); @@ -94,6 +98,7 @@ BEGIN_OBJECT_REFLECTOR(osgUtil::RenderBin) I_Property(osgUtil::RenderBin::SortMode, SortMode); I_ReadOnlyProperty(osgUtil::RenderStage *, Stage); I_ReadOnlyProperty(osgUtil::RenderBin::StateGraphList &, StateGraphList); + I_Property(osg::StateSet *, StateSet); END_REFLECTOR BEGIN_ABSTRACT_OBJECT_REFLECTOR(osgUtil::RenderBin::DrawCallback)