2001-09-20 05:08:56 +08:00
|
|
|
#ifndef OSGUTIL_DISPLAYLISTVISITOR
|
|
|
|
#define OSGUTIL_DISPLAYLISTVISITOR 1
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
#include <osg/NodeVisitor>
|
|
|
|
#include <osg/Geode>
|
2001-09-20 05:08:56 +08:00
|
|
|
#include <osg/State>
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
#include <osgUtil/Export>
|
|
|
|
|
|
|
|
namespace osgUtil {
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
/** Visitor for traversing scene graph and setting each osg::GeoSet's _useDisplayList flag,
|
|
|
|
* with option to immediately compile osg::GeoSet's OpenGL Display lists.
|
|
|
|
* The mode of operation
|
2001-09-28 20:36:40 +08:00
|
|
|
* of the visitor is controlled by setting the DisplayListMode either on visitor
|
2001-01-11 00:32:10 +08:00
|
|
|
* constructor or via the setDisplayListMode() method. DisplayListMode options are:
|
|
|
|
* _displayListMode == SWITCH_ON_AND_COMPILE_DISPLAY_LISTS cals gset->compile() on
|
2001-09-28 20:36:40 +08:00
|
|
|
* all Geode children. Note, the visitor must only be used within a valid
|
2001-01-11 00:32:10 +08:00
|
|
|
* OpenGL context as compile uses OpenGL calls.
|
|
|
|
* _displayListMode == SWITCH_ON_DISPLAY_LISTS sets the Geode's children with
|
|
|
|
* gset->setUseDisplayList(true), this method does not directly create display list,
|
|
|
|
* or uses OpenGL calls so if safe to use before a valid OpenGL context has been set up.
|
|
|
|
* On the next redraw of the scene, the gset's draw methods will be called
|
|
|
|
* which then will respond to their _useDisplayList being set by creating display lists
|
|
|
|
* automatically.
|
|
|
|
* _displayListMode == SWITCH_OFF_DISPLAY_LISTS sets the Geode's children with
|
|
|
|
* gset->setUseDisplayList(false), this method does not directly create display list,
|
|
|
|
* or uses OpenGL calls so if safe to use before a valid OpenGL context has been set up.
|
|
|
|
*/
|
|
|
|
class OSGUTIL_EXPORT DisplayListVisitor : public osg::NodeVisitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/** Operation modes of the DisplayListVisitor.*/
|
|
|
|
enum DisplayListMode
|
|
|
|
{
|
|
|
|
SWITCH_ON_AND_COMPILE_DISPLAY_LISTS,
|
2001-09-20 05:08:56 +08:00
|
|
|
COMPILE_ON_DISPLAY_LISTS,
|
2001-01-11 00:32:10 +08:00
|
|
|
SWITCH_ON_DISPLAY_LISTS,
|
|
|
|
SWITCH_OFF_DISPLAY_LISTS
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Construct a CompileGeoSetsVisior to traverse all child,
|
2001-09-28 20:36:40 +08:00
|
|
|
* with set specified display list mode. Default mode is to
|
2001-01-11 00:32:10 +08:00
|
|
|
* gset->setUseDisplayList(true).
|
|
|
|
*/
|
|
|
|
DisplayListVisitor(DisplayListMode mode=SWITCH_ON_DISPLAY_LISTS);
|
|
|
|
|
|
|
|
/** Set the operational mode of how the visitor should set up osg::GeoSet's.*/
|
|
|
|
void setDisplayListMode(DisplayListMode mode) { _displayListMode = mode; }
|
|
|
|
|
|
|
|
/** Get the operational mode.*/
|
|
|
|
DisplayListMode getDisplayListMode() const { return _displayListMode; }
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
/** Set the State to use during traversal. */
|
|
|
|
void setState(osg::State* state)
|
|
|
|
{
|
|
|
|
_externalState = state;
|
|
|
|
if (_externalState.valid()) _activeState = _externalState;
|
|
|
|
else _activeState = _localState;
|
|
|
|
}
|
|
|
|
|
|
|
|
osg::State* getState()
|
|
|
|
{
|
|
|
|
return _activeState.get();
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
/** Simply traverse using standard NodeVisitor traverse method.*/
|
|
|
|
virtual void apply(osg::Node& node)
|
|
|
|
{
|
|
|
|
traverse(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** For each Geode visited set the display list usage according to the
|
|
|
|
* _displayListMode.
|
|
|
|
*/
|
|
|
|
virtual void apply(osg::Geode& node);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
DisplayListMode _displayListMode;
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
/** local state is created in constructor and used as the default state during traversal.*/
|
|
|
|
osg::ref_ptr<osg::State> _localState;
|
|
|
|
/** external state is used to override the default state.*/
|
|
|
|
osg::ref_ptr<osg::State> _externalState;
|
|
|
|
/** active state is equal to _externalState when it is valid, otherwise defaults to _localState.*/
|
|
|
|
osg::ref_ptr<osg::State> _activeState;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|