2001-10-22 05:27:40 +08:00
|
|
|
#include <osgUtil/DisplayListVisitor>
|
|
|
|
#include <osg/Drawable>
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
using namespace osg;
|
|
|
|
using namespace osgUtil;
|
|
|
|
|
2001-10-21 04:26:36 +08:00
|
|
|
DisplayListVisitor::DisplayListVisitor(Mode mode)
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
setTraversalMode(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN);
|
|
|
|
|
2001-10-21 04:26:36 +08:00
|
|
|
_mode = mode;
|
2001-09-20 05:08:56 +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
|
|
|
|
2001-10-21 04:26:36 +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)
|
|
|
|
{
|
2001-10-21 04:26:36 +08:00
|
|
|
if (_mode&COMPILE_STATE_ATTRIBUTES && _state.valid())
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2001-10-21 04:26:36 +08:00
|
|
|
if (node.getStateSet())
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2001-10-21 04:26:36 +08:00
|
|
|
node.getStateSet()->compile(*_state);
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
2001-10-21 04:26:36 +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
|
|
|
{
|
2001-10-21 04:26:36 +08:00
|
|
|
Drawable* drawable = node.getDrawable(i);
|
|
|
|
if (drawable->getUseDisplayList())
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2001-10-21 04:26:36 +08:00
|
|
|
if (drawable->getStateSet())
|
2001-09-20 05:08:56 +08:00
|
|
|
{
|
2001-10-21 04:26:36 +08:00
|
|
|
drawable->getStateSet()->compile(*_state);
|
2001-09-20 05:08:56 +08:00
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
}
|
2001-10-21 04:26:36 +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)
|
2001-09-20 05:08:56 +08:00
|
|
|
{
|
2001-10-21 04:26:36 +08:00
|
|
|
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)
|
2001-10-21 04:26:36 +08:00
|
|
|
{
|
|
|
|
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)
|
2001-10-21 04:26:36 +08:00
|
|
|
{
|
|
|
|
if (node.getDrawable(i)->getUseDisplayList())
|
|
|
|
{
|
|
|
|
node.getDrawable(i)->compile(*_state);
|
|
|
|
}
|
2001-09-20 05:08:56 +08:00
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
}
|