2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +08:00
|
|
|
* 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
|
2003-01-22 00:45:36 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2003-01-22 00:45:36 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2003-01-22 00:45:36 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2001-10-04 23:12:57 +08:00
|
|
|
|
2004-07-20 13:37:59 +08:00
|
|
|
#ifndef OSGUTIL_GLOBJECTSVISITOR
|
|
|
|
#define OSGUTIL_GLOBJECTSVISITOR 1
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2009-03-10 00:53:57 +08:00
|
|
|
#include <OpenThreads/Mutex>
|
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 {
|
|
|
|
|
2012-03-22 01:36:20 +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
|
|
|
*/
|
2004-07-20 13:37:59 +08:00
|
|
|
class OSGUTIL_EXPORT GLObjectsVisitor : public osg::NodeVisitor
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2001-10-21 04:26:36 +08:00
|
|
|
/** Operation modes of the.*/
|
|
|
|
enum ModeValues
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2004-10-19 17:29:13 +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,
|
2006-02-22 22:31:13 +08:00
|
|
|
SWITCH_OFF_VERTEX_BUFFER_OBJECTS = 0x80,
|
2006-03-17 19:28:35 +08:00
|
|
|
CHECK_BLACK_LISTED_MODES = 0x100
|
2001-01-11 00:32:10 +08:00
|
|
|
};
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2001-10-21 04:26:36 +08:00
|
|
|
typedef unsigned int Mode;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2004-09-27 02:39:34 +08:00
|
|
|
/** Construct a GLObjectsVisitor to traverse all children, operating on
|
2012-03-22 01:36:20 +08:00
|
|
|
* node according to specified mode, such as to compile or release
|
|
|
|
* display list/texture objects etc. Default mode is to compile
|
2004-07-23 12:03:57 +08:00
|
|
|
* GL objects.
|
2001-01-11 00:32:10 +08:00
|
|
|
*/
|
2012-03-22 01:36:20 +08:00
|
|
|
GLObjectsVisitor(Mode mode=COMPILE_DISPLAY_LISTS|COMPILE_STATE_ATTRIBUTES|CHECK_BLACK_LISTED_MODES);
|
|
|
|
|
2013-01-25 02:48:34 +08:00
|
|
|
META_NodeVisitor(osgUtil, GLObjectsVisitor)
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2006-02-22 22:31:13 +08:00
|
|
|
virtual void reset()
|
|
|
|
{
|
|
|
|
_drawablesAppliedSet.clear();
|
|
|
|
_stateSetAppliedSet.clear();
|
|
|
|
}
|
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-07-23 12:03:57 +08:00
|
|
|
/** Set the operational mode of what operations to do on the scene graph.*/
|
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; }
|
2012-03-22 01:36:20 +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)
|
|
|
|
{
|
2006-11-14 20:51:31 +08:00
|
|
|
_renderInfo.setState(state);
|
2001-09-20 05:08:56 +08:00
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
osg::State* getState()
|
|
|
|
{
|
2006-11-14 20:51:31 +08:00
|
|
|
return _renderInfo.getState();
|
|
|
|
}
|
|
|
|
|
|
|
|
void setRenderInfo(osg::RenderInfo& renderInfo)
|
|
|
|
{
|
|
|
|
_renderInfo = renderInfo;
|
2001-09-20 05:08:56 +08:00
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
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.*/
|
2001-10-21 04:26:36 +08:00
|
|
|
virtual void apply(osg::Node& node);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-07-20 13:37:59 +08:00
|
|
|
void apply(osg::Drawable& drawable);
|
|
|
|
void apply(osg::StateSet& stateset);
|
|
|
|
|
2017-10-25 23:13:26 +08:00
|
|
|
/** Do a compile traversal and then reset any state,*/
|
|
|
|
void compile(osg::Node& node);
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
protected:
|
|
|
|
|
2006-02-22 22:31:13 +08:00
|
|
|
typedef std::set<osg::Drawable*> DrawableAppliedSet;
|
|
|
|
typedef std::set<osg::StateSet*> StatesSetAppliedSet;
|
2004-10-19 17:29:13 +08:00
|
|
|
|
2006-02-22 22:31:13 +08:00
|
|
|
Mode _mode;
|
2006-11-14 20:51:31 +08:00
|
|
|
osg::RenderInfo _renderInfo;
|
2006-02-22 22:31:13 +08:00
|
|
|
DrawableAppliedSet _drawablesAppliedSet;
|
|
|
|
StatesSetAppliedSet _stateSetAppliedSet;
|
2007-01-27 00:08:52 +08:00
|
|
|
osg::ref_ptr<osg::Program> _lastCompiledProgram;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2007-07-18 17:05:11 +08:00
|
|
|
class OSGUTIL_EXPORT GLObjectsOperation : public osg::GraphicsOperation
|
2007-07-14 01:25:35 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2007-07-30 18:52:37 +08:00
|
|
|
GLObjectsOperation(GLObjectsVisitor::Mode mode = GLObjectsVisitor::COMPILE_DISPLAY_LISTS|GLObjectsVisitor::COMPILE_STATE_ATTRIBUTES|GLObjectsVisitor::CHECK_BLACK_LISTED_MODES);
|
|
|
|
|
2007-07-14 01:25:35 +08:00
|
|
|
GLObjectsOperation(osg::Node* subgraph, GLObjectsVisitor::Mode mode = GLObjectsVisitor::COMPILE_DISPLAY_LISTS|GLObjectsVisitor::COMPILE_STATE_ATTRIBUTES|GLObjectsVisitor::CHECK_BLACK_LISTED_MODES);
|
|
|
|
|
|
|
|
virtual void operator () (osg::GraphicsContext* context);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2007-07-14 01:25:35 +08:00
|
|
|
protected:
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2007-07-14 01:25:35 +08:00
|
|
|
osg::ref_ptr<osg::Node> _subgraph;
|
|
|
|
GLObjectsVisitor::Mode _mode;
|
|
|
|
};
|
|
|
|
|
2002-02-03 20:33:41 +08:00
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|