2002-07-17 04:07:32 +08:00
|
|
|
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
|
2001-10-04 23:12:57 +08:00
|
|
|
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
|
|
|
//as published by the Free Software Foundation.
|
|
|
|
|
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 {
|
|
|
|
|
2002-06-26 18:28:17 +08:00
|
|
|
/** Visitor for traversing scene graph and setting each osg::Drawable's _useDisplayList flag,
|
2001-10-21 04:26:36 +08:00
|
|
|
* with option to immediately compile osg::Drawable OpenGL Display lists and
|
|
|
|
* osg::StateAttribute's.
|
2001-01-11 00:32:10 +08:00
|
|
|
*/
|
|
|
|
class OSGUTIL_EXPORT DisplayListVisitor : public osg::NodeVisitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2001-10-21 04:26:36 +08:00
|
|
|
/** Operation modes of the.*/
|
|
|
|
enum ModeValues
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2001-10-21 04:26:36 +08:00
|
|
|
SWITCH_ON_DISPLAY_LISTS = 0x1,
|
|
|
|
SWITCH_OFF_DISPLAY_LISTS = 0x2,
|
|
|
|
COMPILE_DISPLAY_LISTS = 0x4,
|
|
|
|
COMPILE_STATE_ATTRIBUTES = 0x8
|
2001-01-11 00:32:10 +08:00
|
|
|
};
|
2001-10-21 04:26:36 +08:00
|
|
|
|
|
|
|
typedef unsigned int Mode;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2002-06-26 18:28:17 +08:00
|
|
|
/** Construct a DisplayListVisior 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).
|
|
|
|
*/
|
2001-10-21 04:26:36 +08:00
|
|
|
DisplayListVisitor(Mode mode=COMPILE_DISPLAY_LISTS|COMPILE_STATE_ATTRIBUTES);
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2002-06-26 18:28:17 +08:00
|
|
|
/** Set the operational mode of how the visitor should set up osg::Drawable's.*/
|
2001-10-21 04:26:36 +08:00
|
|
|
void setMode(Mode mode) { _mode = mode; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
/** Get the operational mode.*/
|
2001-10-21 04:26:36 +08:00
|
|
|
Mode getMode() const { return _mode; }
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2001-10-21 04:26:36 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
/** Set the State to use during traversal. */
|
|
|
|
void setState(osg::State* state)
|
|
|
|
{
|
2001-10-21 04:26:36 +08:00
|
|
|
_state = state;
|
2001-09-20 05:08:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
osg::State* getState()
|
|
|
|
{
|
2001-10-21 04:26:36 +08:00
|
|
|
return _state.get();
|
2001-09-20 05:08:56 +08:00
|
|
|
}
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
/** Simply traverse using standard NodeVisitor traverse method.*/
|
2001-10-21 04:26:36 +08:00
|
|
|
virtual void apply(osg::Node& node);
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
/** For each Geode visited set the display list usage according to the
|
|
|
|
* _displayListMode.
|
|
|
|
*/
|
|
|
|
virtual void apply(osg::Geode& node);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2001-10-21 04:26:36 +08:00
|
|
|
Mode _mode;
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2001-10-21 04:26:36 +08:00
|
|
|
osg::ref_ptr<osg::State> _state;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2002-02-03 20:33:41 +08:00
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|