OpenSceneGraph/src/osgUtil/DisplayListVisitor.cpp

75 lines
1.7 KiB
C++
Raw Normal View History

#include <osgUtil/DisplayListVisitor>
#include <osg/Drawable>
2001-01-11 00:32:10 +08:00
using namespace osg;
using namespace osgUtil;
DisplayListVisitor::DisplayListVisitor(Mode mode)
2001-01-11 00:32:10 +08:00
{
setTraversalMode(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN);
_mode = mode;
_state = NULL;
2001-01-11 00:32:10 +08:00
}
void DisplayListVisitor::apply(osg::Node& node)
{
if ((_mode&COMPILE_STATE_ATTRIBUTES) && node.getStateSet() && _state.valid())
{
node.getStateSet()->compile(*_state);
}
traverse(node);
}
2001-01-11 00:32:10 +08:00
void DisplayListVisitor::apply(osg::Geode& node)
{
if (_mode&COMPILE_STATE_ATTRIBUTES && _state.valid())
2001-01-11 00:32:10 +08:00
{
if (node.getStateSet())
2001-01-11 00:32:10 +08:00
{
node.getStateSet()->compile(*_state);
2001-01-11 00:32:10 +08:00
}
2002-07-18 18:06:21 +08:00
for(unsigned int i=0;i<node.getNumDrawables();++i)
2001-01-11 00:32:10 +08:00
{
Drawable* drawable = node.getDrawable(i);
if (drawable->getUseDisplayList())
2001-01-11 00:32:10 +08:00
{
if (drawable->getStateSet())
{
drawable->getStateSet()->compile(*_state);
}
2001-01-11 00:32:10 +08:00
}
}
}
if (_mode&SWITCH_OFF_DISPLAY_LISTS)
{
2002-07-18 18:06:21 +08:00
for(unsigned int i=0;i<node.getNumDrawables();++i)
{
node.getDrawable(i)->setUseDisplayList(false);
}
}
if (_mode&SWITCH_ON_DISPLAY_LISTS)
{
2002-07-18 18:06:21 +08:00
for(unsigned int i=0;i<node.getNumDrawables();++i)
{
node.getDrawable(i)->setUseDisplayList(true);
}
}
if (_mode&COMPILE_DISPLAY_LISTS && _state.valid())
{
2002-07-18 18:06:21 +08:00
for(unsigned int i=0;i<node.getNumDrawables();++i)
{
if (node.getDrawable(i)->getUseDisplayList())
{
node.getDrawable(i)->compile(*_state);
}
}
2001-01-11 00:32:10 +08:00
}
}