Added support for RenderBin's have a local top level StateSet. This is now

used by default in the depth sorted bin.
This commit is contained in:
Robert Osfield
2006-06-29 15:57:24 +00:00
parent d74397ce58
commit 30265ac0b3
7 changed files with 44 additions and 6 deletions

View File

@@ -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> _sortCallback;
osg::ref_ptr<DrawCallback> _drawCallback;
osg::ref_ptr<osg::StateSet> _stateset;
};

View File

@@ -12,6 +12,7 @@
*/
#include <osg/AlphaFunc>
#include <osg/Notify>
using namespace osg;

View File

@@ -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;

View File

@@ -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)

View File

@@ -16,6 +16,7 @@
#include <osg/Notify>
#include <osg/ApplicationUsage>
#include <osg/AlphaFunc>
#include <algorithm>
@@ -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 "<<className()<<" sortMode "<<getSortMode()<<std::endl;
if (_stateset.valid())
{
state.pushStateSet(_stateset.get());
}
// draw first set of draw bins.
RenderBinList::iterator rbitr;
for(rbitr = _bins.begin();
@@ -395,6 +417,8 @@ void RenderBin::drawImplementation(osg::State& state,RenderLeaf*& previous)
rbitr->second->draw(state,previous);
}
if (_stateset.valid()) state.popStateSet();
//osg::notify(osg::NOTICE)<<"end RenderBin::drawImplementation "<<className()<<std::endl;
}

View File

@@ -194,10 +194,12 @@ void SceneView::setDefaults(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);
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;

View File

@@ -12,6 +12,7 @@
#include <osg/CopyOp>
#include <osg/Object>
#include <osg/State>
#include <osg/StateSet>
#include <osgUtil/RenderBin>
#include <osgUtil/RenderLeaf>
#include <osgUtil/RenderStage>
@@ -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)