2006-07-18 23:21:48 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +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
|
|
|
|
* (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.
|
|
|
|
*/
|
2004-07-20 13:37:59 +08:00
|
|
|
#include <osgUtil/GLObjectsVisitor>
|
2001-10-22 05:27:40 +08:00
|
|
|
#include <osg/Drawable>
|
2004-09-24 04:01:40 +08:00
|
|
|
#include <osg/Notify>
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
using namespace osg;
|
|
|
|
using namespace osgUtil;
|
|
|
|
|
2004-07-20 13:37:59 +08:00
|
|
|
GLObjectsVisitor::GLObjectsVisitor(Mode mode)
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
setTraversalMode(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN);
|
2004-10-19 17:29:13 +08:00
|
|
|
|
2001-10-21 04:26:36 +08:00
|
|
|
_mode = mode;
|
2004-10-19 17:29:13 +08:00
|
|
|
|
2001-10-21 04:26:36 +08:00
|
|
|
_state = NULL;
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2004-07-20 13:37:59 +08:00
|
|
|
void GLObjectsVisitor::apply(osg::Node& node)
|
2001-10-21 04:26:36 +08:00
|
|
|
{
|
2004-07-20 13:37:59 +08:00
|
|
|
if (node.getStateSet())
|
2001-10-21 04:26:36 +08:00
|
|
|
{
|
2004-07-20 13:37:59 +08:00
|
|
|
apply(*(node.getStateSet()));
|
2001-10-21 04:26:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
traverse(node);
|
|
|
|
}
|
|
|
|
|
2004-07-20 13:37:59 +08:00
|
|
|
void GLObjectsVisitor::apply(osg::Geode& node)
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2004-07-20 13:37:59 +08:00
|
|
|
if (node.getStateSet())
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2004-07-20 13:37:59 +08:00
|
|
|
apply(*(node.getStateSet()));
|
|
|
|
}
|
2001-10-21 04:26:36 +08:00
|
|
|
|
2004-07-20 13:37:59 +08:00
|
|
|
for(unsigned int i=0;i<node.getNumDrawables();++i)
|
|
|
|
{
|
|
|
|
Drawable* drawable = node.getDrawable(i);
|
|
|
|
if (drawable)
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2004-07-20 13:37:59 +08:00
|
|
|
apply(*drawable);
|
2003-01-21 04:40:06 +08:00
|
|
|
if (drawable->getStateSet())
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2004-07-20 13:37:59 +08:00
|
|
|
apply(*(drawable->getStateSet()));
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
}
|
2001-10-21 04:26:36 +08:00
|
|
|
}
|
2004-07-20 13:37:59 +08:00
|
|
|
}
|
2001-10-21 04:26:36 +08:00
|
|
|
|
2004-07-20 13:37:59 +08:00
|
|
|
void GLObjectsVisitor::apply(osg::Drawable& drawable)
|
|
|
|
{
|
2006-02-22 22:31:13 +08:00
|
|
|
if (_drawablesAppliedSet.count(&drawable)!=0) return;
|
|
|
|
|
|
|
|
_drawablesAppliedSet.insert(&drawable);
|
|
|
|
|
2001-10-21 04:26:36 +08:00
|
|
|
if (_mode&SWITCH_OFF_DISPLAY_LISTS)
|
|
|
|
{
|
2004-07-20 13:37:59 +08:00
|
|
|
drawable.setUseDisplayList(false);
|
2001-10-21 04:26:36 +08:00
|
|
|
}
|
2004-07-20 13:37:59 +08:00
|
|
|
|
2001-10-21 04:26:36 +08:00
|
|
|
if (_mode&SWITCH_ON_DISPLAY_LISTS)
|
|
|
|
{
|
2004-07-20 13:37:59 +08:00
|
|
|
drawable.setUseDisplayList(true);
|
2001-10-21 04:26:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_mode&COMPILE_DISPLAY_LISTS && _state.valid())
|
|
|
|
{
|
2004-07-20 13:37:59 +08:00
|
|
|
drawable.compileGLObjects(*_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_mode&RELEASE_DISPLAY_LISTS)
|
|
|
|
{
|
|
|
|
drawable.releaseGLObjects(_state.get());
|
|
|
|
}
|
2004-10-19 17:29:13 +08:00
|
|
|
|
|
|
|
if (_mode&SWITCH_ON_VERTEX_BUFFER_OBJECTS)
|
|
|
|
{
|
|
|
|
drawable.setUseVertexBufferObjects(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_mode&SWITCH_OFF_VERTEX_BUFFER_OBJECTS)
|
|
|
|
{
|
|
|
|
drawable.setUseVertexBufferObjects(false);
|
|
|
|
}
|
2004-07-20 13:37:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLObjectsVisitor::apply(osg::StateSet& stateset)
|
|
|
|
{
|
2006-02-22 22:31:13 +08:00
|
|
|
if (_stateSetAppliedSet.count(&stateset)!=0) return;
|
|
|
|
|
|
|
|
_stateSetAppliedSet.insert(&stateset);
|
|
|
|
|
|
|
|
if (_mode & COMPILE_STATE_ATTRIBUTES && _state.valid())
|
2004-07-20 13:37:59 +08:00
|
|
|
{
|
|
|
|
stateset.compileGLObjects(*_state);
|
|
|
|
}
|
2006-02-22 22:31:13 +08:00
|
|
|
|
|
|
|
if (_mode & RELEASE_STATE_ATTRIBUTES)
|
2004-07-20 13:37:59 +08:00
|
|
|
{
|
|
|
|
stateset.releaseGLObjects(_state.get());
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
2006-02-22 22:31:13 +08:00
|
|
|
|
|
|
|
if (_mode & CHECK_BLACK_LISTED_MODES)
|
|
|
|
{
|
2006-02-23 03:14:01 +08:00
|
|
|
stateset.checkValidityOfAssociatedModes(*_state.get());
|
2006-02-22 22:31:13 +08:00
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|