OpenSceneGraph/include/osgUtil/GLObjectsVisitor
Robert Osfield aa833acfd3 Added support for releasing GLObjects, and renamed DisplayListVisitor the
GLObjectVisitor to better fit its function, and added support for releasing
objects as well as compiling them.
2004-07-20 05:37:59 +00:00

94 lines
2.7 KiB
C++

/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGUTIL_GLOBJECTSVISITOR
#define OSGUTIL_GLOBJECTSVISITOR 1
#include <osg/NodeVisitor>
#include <osg/Geode>
#include <osg/State>
#include <osgUtil/Export>
namespace osgUtil {
/** Visitor for traversing scene graph and setting each osg::Drawable's _useDisplayList flag,
* with option to immediately compile osg::Drawable OpenGL Display lists and
* osg::StateAttribute's.
*/
class OSGUTIL_EXPORT GLObjectsVisitor : public osg::NodeVisitor
{
public:
/** Operation modes of the.*/
enum ModeValues
{
SWITCH_ON_DISPLAY_LISTS = 0x1,
SWITCH_OFF_DISPLAY_LISTS = 0x2,
COMPILE_DISPLAY_LISTS = 0x4,
COMPILE_STATE_ATTRIBUTES = 0x8,
RELEASE_DISPLAY_LISTS = 0x10,
RELEASE_STATE_ATTRIBUTES = 0x20
};
typedef unsigned int Mode;
/** Construct a DisplayListVisior to traverse all child,
* with set specified display list mode. Default mode is to
* gset->setUseDisplayList(true).
*/
GLObjectsVisitor(Mode mode=COMPILE_DISPLAY_LISTS|COMPILE_STATE_ATTRIBUTES);
/** Set the operational mode of how the visitor should set up osg::Drawable's.*/
void setMode(Mode mode) { _mode = mode; }
/** Get the operational mode.*/
Mode getMode() const { return _mode; }
/** Set the State to use during traversal. */
void setState(osg::State* state)
{
_state = state;
}
osg::State* getState()
{
return _state.get();
}
/** Simply traverse using standard NodeVisitor traverse method.*/
virtual void apply(osg::Node& node);
/** For each Geode visited set the display list usage according to the
* _displayListMode.
*/
virtual void apply(osg::Geode& node);
void apply(osg::Drawable& drawable);
void apply(osg::StateSet& stateset);
protected:
Mode _mode;
osg::ref_ptr<osg::State> _state;
};
}
#endif