Added support for an osgUtil::SceneView::init() traversal which is called once

per scene view.  The user can attach a NodeVisitor to do init for them, or
leave it to the default which is to use the osgUtil::DisplayListVisitor
which compiles all display lists and texture objects.  The init traversal
is called automatically by the first call to either app() or cull(), so
should not be called by user code during initialization. This ensures
that a valid graphics context has been established before OpenGL is initialized.

osgUtil::DisplayListVisitor has also been updated to use a bit mask for options, and the addition of
compilation of texture objects (via StateAttribute::compile) has also been
added.
This commit is contained in:
Robert Osfield
2001-10-20 20:26:36 +00:00
parent 489ef2d035
commit 7082abb8ad
4 changed files with 120 additions and 81 deletions

View File

@@ -4,53 +4,71 @@
using namespace osg;
using namespace osgUtil;
DisplayListVisitor::DisplayListVisitor(DisplayListMode mode)
DisplayListVisitor::DisplayListVisitor(Mode mode)
{
setTraversalMode(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN);
_displayListMode = mode;
_localState = new osg::State;
_externalState = NULL;
_mode = mode;
_activeState = _localState;
_state = NULL;
}
void DisplayListVisitor::apply(osg::Node& node)
{
if ((_mode&COMPILE_STATE_ATTRIBUTES) && node.getStateSet() && _state.valid())
{
node.getStateSet()->compile(*_state);
}
traverse(node);
}
void DisplayListVisitor::apply(osg::Geode& node)
{
switch(_displayListMode)
if (_mode&COMPILE_STATE_ATTRIBUTES && _state.valid())
{
case(SWITCH_OFF_DISPLAY_LISTS):
if (node.getStateSet())
{
for(int i=0;i<node.getNumDrawables();++i)
{
node.getDrawable(i)->setUseDisplayList(false);
}
node.getStateSet()->compile(*_state);
}
break;
case(SWITCH_ON_DISPLAY_LISTS):
for(int i=0;i<node.getNumDrawables();++i)
{
for(int i=0;i<node.getNumDrawables();++i)
Drawable* drawable = node.getDrawable(i);
if (drawable->getUseDisplayList())
{
node.getDrawable(i)->setUseDisplayList(true);
}
}
break;
case(COMPILE_ON_DISPLAY_LISTS):
{
for(int i=0;i<node.getNumDrawables();++i)
{
if (node.getDrawable(i)->getUseDisplayList())
if (drawable->getStateSet())
{
node.getDrawable(i)->compile(*_activeState);
drawable->getStateSet()->compile(*_state);
}
}
}
break;
case(SWITCH_ON_AND_COMPILE_DISPLAY_LISTS):
}
if (_mode&SWITCH_OFF_DISPLAY_LISTS)
{
for(int i=0;i<node.getNumDrawables();++i)
{
node.compileDrawables(*_activeState);
node.getDrawable(i)->setUseDisplayList(false);
}
}
if (_mode&SWITCH_ON_DISPLAY_LISTS)
{
for(int i=0;i<node.getNumDrawables();++i)
{
node.getDrawable(i)->setUseDisplayList(true);
}
}
if (_mode&COMPILE_DISPLAY_LISTS && _state.valid())
{
for(int i=0;i<node.getNumDrawables();++i)
{
if (node.getDrawable(i)->getUseDisplayList())
{
node.getDrawable(i)->compile(*_state);
}
}
break;
}
}

View File

@@ -1,5 +1,6 @@
#include <osgUtil/SceneView>
#include <osgUtil/AppVisitor>
#include <osgUtil/DisplayListVisitor>
#include <osg/Notify>
#include <osg/Texture>
@@ -28,6 +29,8 @@ SceneView::SceneView()
_viewport = new Viewport;
_initCalled = false;
}
@@ -46,19 +49,21 @@ void SceneView::setDefaults()
_light->setDiffuse(Vec4(0.8f,0.8f,0.8f,1.0f));
_light->setSpecular(Vec4(0.1f,0.1f,0.1f,1.0f));
_camera = new osg::Camera;
_camera = new Camera;
_state = new osg::State;
_state = new State;
_rendergraph = new osgUtil::RenderGraph;
_renderStage = new osgUtil::RenderStage;
_rendergraph = new RenderGraph;
_renderStage = new RenderStage;
_appVisitor = new osgUtil::AppVisitor;
_cullVisitor = new osgUtil::CullVisitor;
DisplayListVisitor* dlv = new DisplayListVisitor();
dlv->setState(_state.get());
_initVisitor = dlv;
_appVisitor = new AppVisitor;
_cullVisitor = new CullVisitor;
_cullVisitor->setRenderGraph(_rendergraph.get());
_cullVisitor->setRenderStage(_renderStage.get());
@@ -85,9 +90,29 @@ void SceneView::setDefaults()
}
void SceneView::init()
{
_initCalled = true;
if (_sceneData.valid() && _initVisitor.valid())
{
_initVisitor->reset();
_initVisitor->setFrameStamp(_frameStamp.get());
if (_frameStamp.valid())
{
_initVisitor->setTraversalNumber(_frameStamp->getFrameNumber());
}
_sceneData->accept(*_initVisitor.get());
}
}
void SceneView::app()
{
if (!_initCalled) init();
if (_sceneData.valid() && _appVisitor.valid())
{
_appVisitor->reset();
@@ -108,8 +133,11 @@ void SceneView::app()
void SceneView::cull()
{
if (!_sceneData) return;
if (!_initCalled) init();
_camera->adjustAspectRatio(_viewport->aspectRatio());