73 lines
2.6 KiB
Plaintext
73 lines
2.6 KiB
Plaintext
#ifndef OSGUTIL_COMPILEGEOSETVISITOR
|
|
#define OSGUTIL_COMPILEGEOSETVISITOR 1
|
|
|
|
#include <osg/NodeVisitor>
|
|
#include <osg/Geode>
|
|
|
|
#include <osgUtil/Export>
|
|
|
|
namespace osgUtil {
|
|
|
|
/** Visitor for traversing scene set each osg::GeoSet's _useDisplayList flag, or
|
|
* immediately compiling osg::GeoSet's OpenGL Display lists. The mode of operation
|
|
* of the vistor is controlled by setting the DisplayListMode either on visitor
|
|
* constructor or via the setDisplayListMode() method. DisplayListMode options are:
|
|
* _displayListMode == SWITCH_ON_AND_COMPILE_DISPLAY_LISTS cals gset->compile() on
|
|
* all Geode childern. Note, the visitor must only be used within a valid
|
|
* 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,
|
|
SWITCH_ON_DISPLAY_LISTS,
|
|
SWITCH_OFF_DISPLAY_LISTS
|
|
};
|
|
|
|
/** Construct a CompileGeoSetsVisior to traverse all child,
|
|
* with set specfied display list mode. Default mode is to
|
|
* 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; }
|
|
|
|
/** 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;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
#endif
|
|
|