OpenSceneGraph/include/osgUtil/GLObjectsVisitor

119 lines
3.6 KiB
Plaintext
Raw Normal View History

2006-07-18 23:21:48 +08:00
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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
2001-01-11 00:32:10 +08:00
#include <osg/NodeVisitor>
#include <osg/Geode>
#include <osg/State>
2001-01-11 00:32:10 +08:00
#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.
2001-01-11 00:32:10 +08:00
*/
class OSGUTIL_EXPORT GLObjectsVisitor : public osg::NodeVisitor
2001-01-11 00:32:10 +08:00
{
public:
/** Operation modes of the.*/
enum ModeValues
2001-01-11 00:32:10 +08:00
{
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,
SWITCH_ON_VERTEX_BUFFER_OBJECTS = 0x40,
SWITCH_OFF_VERTEX_BUFFER_OBJECTS = 0x80,
CHECK_BLACK_LISTED_MODES = 0x100
2001-01-11 00:32:10 +08:00
};
typedef unsigned int Mode;
2001-01-11 00:32:10 +08:00
/** Construct a GLObjectsVisitor to traverse all children, operating on
2004-07-23 12:03:57 +08:00
* node according to specified mode, such as to compile or release
* display list/texture objects etc. Default mode is to compile
* GL objects.
2001-01-11 00:32:10 +08:00
*/
GLObjectsVisitor(Mode mode=COMPILE_DISPLAY_LISTS|COMPILE_STATE_ATTRIBUTES|CHECK_BLACK_LISTED_MODES);
virtual void reset()
{
_drawablesAppliedSet.clear();
_stateSetAppliedSet.clear();
}
2001-01-11 00:32:10 +08:00
2004-07-23 12:03:57 +08:00
/** Set the operational mode of what operations to do on the scene graph.*/
void setMode(Mode mode) { _mode = mode; }
2001-01-11 00:32:10 +08:00
/** Get the operational mode.*/
Mode getMode() const { return _mode; }
/** Set the State to use during traversal. */
void setState(osg::State* state)
{
2006-11-14 20:51:31 +08:00
_renderInfo.setState(state);
}
osg::State* getState()
{
2006-11-14 20:51:31 +08:00
return _renderInfo.getState();
}
void setRenderInfo(osg::RenderInfo& renderInfo)
{
_renderInfo = renderInfo;
}
2006-11-14 20:51:31 +08:00
osg::RenderInfo& getRenderInfo()
{
return _renderInfo;
}
2001-01-11 00:32:10 +08:00
/** Simply traverse using standard NodeVisitor traverse method.*/
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);
void apply(osg::Drawable& drawable);
void apply(osg::StateSet& stateset);
2001-01-11 00:32:10 +08:00
protected:
typedef std::set<osg::Drawable*> DrawableAppliedSet;
typedef std::set<osg::StateSet*> StatesSetAppliedSet;
Mode _mode;
2006-11-14 20:51:31 +08:00
osg::RenderInfo _renderInfo;
DrawableAppliedSet _drawablesAppliedSet;
StatesSetAppliedSet _stateSetAppliedSet;
2001-01-11 00:32:10 +08:00
};
}
2001-01-11 00:32:10 +08:00
#endif