Added support for releasing GLObjects, and renamed DisplayListVisitor the
GLObjectVisitor to better fit its function, and added support for releasing objects as well as compiling them.
This commit is contained in:
@@ -10,13 +10,13 @@
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
#include <osgUtil/DisplayListVisitor>
|
||||
#include <osgUtil/GLObjectsVisitor>
|
||||
#include <osg/Drawable>
|
||||
|
||||
using namespace osg;
|
||||
using namespace osgUtil;
|
||||
|
||||
DisplayListVisitor::DisplayListVisitor(Mode mode)
|
||||
GLObjectsVisitor::GLObjectsVisitor(Mode mode)
|
||||
{
|
||||
setTraversalMode(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN);
|
||||
|
||||
@@ -26,55 +26,68 @@ DisplayListVisitor::DisplayListVisitor(Mode mode)
|
||||
}
|
||||
|
||||
|
||||
void DisplayListVisitor::apply(osg::Node& node)
|
||||
void GLObjectsVisitor::apply(osg::Node& node)
|
||||
{
|
||||
if ((_mode&COMPILE_STATE_ATTRIBUTES) && node.getStateSet() && _state.valid())
|
||||
if (node.getStateSet())
|
||||
{
|
||||
node.getStateSet()->compile(*_state);
|
||||
apply(*(node.getStateSet()));
|
||||
}
|
||||
|
||||
traverse(node);
|
||||
}
|
||||
|
||||
void DisplayListVisitor::apply(osg::Geode& node)
|
||||
void GLObjectsVisitor::apply(osg::Geode& node)
|
||||
{
|
||||
if (_mode&COMPILE_STATE_ATTRIBUTES && _state.valid())
|
||||
if (node.getStateSet())
|
||||
{
|
||||
if (node.getStateSet())
|
||||
{
|
||||
node.getStateSet()->compile(*_state);
|
||||
}
|
||||
apply(*(node.getStateSet()));
|
||||
}
|
||||
|
||||
for(unsigned int i=0;i<node.getNumDrawables();++i)
|
||||
for(unsigned int i=0;i<node.getNumDrawables();++i)
|
||||
{
|
||||
Drawable* drawable = node.getDrawable(i);
|
||||
if (drawable)
|
||||
{
|
||||
Drawable* drawable = node.getDrawable(i);
|
||||
apply(*drawable);
|
||||
if (drawable->getStateSet())
|
||||
{
|
||||
drawable->getStateSet()->compile(*_state);
|
||||
apply(*(drawable->getStateSet()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GLObjectsVisitor::apply(osg::Drawable& drawable)
|
||||
{
|
||||
if (_mode&SWITCH_OFF_DISPLAY_LISTS)
|
||||
{
|
||||
for(unsigned int i=0;i<node.getNumDrawables();++i)
|
||||
{
|
||||
node.getDrawable(i)->setUseDisplayList(false);
|
||||
}
|
||||
drawable.setUseDisplayList(false);
|
||||
}
|
||||
|
||||
if (_mode&SWITCH_ON_DISPLAY_LISTS)
|
||||
{
|
||||
for(unsigned int i=0;i<node.getNumDrawables();++i)
|
||||
{
|
||||
node.getDrawable(i)->setUseDisplayList(true);
|
||||
}
|
||||
drawable.setUseDisplayList(true);
|
||||
}
|
||||
|
||||
if (_mode&COMPILE_DISPLAY_LISTS && _state.valid())
|
||||
{
|
||||
for(unsigned int i=0;i<node.getNumDrawables();++i)
|
||||
{
|
||||
node.getDrawable(i)->compile(*_state);
|
||||
}
|
||||
drawable.compileGLObjects(*_state);
|
||||
}
|
||||
|
||||
if (_mode&RELEASE_DISPLAY_LISTS)
|
||||
{
|
||||
drawable.releaseGLObjects(_state.get());
|
||||
}
|
||||
}
|
||||
|
||||
void GLObjectsVisitor::apply(osg::StateSet& stateset)
|
||||
{
|
||||
if (_mode&COMPILE_STATE_ATTRIBUTES && _state.valid())
|
||||
{
|
||||
stateset.compileGLObjects(*_state);
|
||||
}
|
||||
if (_mode&RELEASE_STATE_ATTRIBUTES)
|
||||
{
|
||||
stateset.releaseGLObjects(_state.get());
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ CXXFILES = \
|
||||
CubeMapGenerator.cpp\
|
||||
CullVisitor.cpp\
|
||||
DelaunayTriangulator.cpp\
|
||||
DisplayListVisitor.cpp\
|
||||
GLObjectsVisitor.cpp\
|
||||
DisplayRequirementsVisitor.cpp\
|
||||
HalfWayMapGenerator.cpp\
|
||||
HighlightMapGenerator.cpp\
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
*/
|
||||
#include <osgUtil/SceneView>
|
||||
#include <osgUtil/UpdateVisitor>
|
||||
#include <osgUtil/DisplayListVisitor>
|
||||
#include <osgUtil/GLObjectsVisitor>
|
||||
|
||||
#include <osg/Timer>
|
||||
#include <osg/Notify>
|
||||
@@ -82,17 +82,17 @@ void SceneView::setDefaults()
|
||||
_renderStage = new RenderStage;
|
||||
|
||||
|
||||
DisplayListVisitor::Mode dlvMode = DisplayListVisitor::COMPILE_DISPLAY_LISTS|DisplayListVisitor::COMPILE_STATE_ATTRIBUTES;
|
||||
GLObjectsVisitor::Mode dlvMode = GLObjectsVisitor::COMPILE_DISPLAY_LISTS|GLObjectsVisitor::COMPILE_STATE_ATTRIBUTES;
|
||||
|
||||
#ifdef __sgi
|
||||
dlvMode = DisplayListVisitor::COMPILE_STATE_ATTRIBUTES;
|
||||
dlvMode = GLObjectsVisitor::COMPILE_STATE_ATTRIBUTES;
|
||||
#endif
|
||||
|
||||
// sgi's IR graphics has a problem with lighting and display lists, as it seems to store
|
||||
// lighting state with the display list, and the display list visitor doesn't currently apply
|
||||
// state before creating display lists. So will disable the init visitor default, this won't
|
||||
// affect functionality since the display lists will be created as and when needed.
|
||||
DisplayListVisitor* dlv = new DisplayListVisitor(dlvMode);
|
||||
GLObjectsVisitor* dlv = new GLObjectsVisitor(dlvMode);
|
||||
dlv->setNodeMaskOverride(0xffffffff);
|
||||
_initVisitor = dlv;
|
||||
|
||||
@@ -139,7 +139,7 @@ void SceneView::init()
|
||||
_initVisitor->reset();
|
||||
_initVisitor->setFrameStamp(_frameStamp.get());
|
||||
|
||||
DisplayListVisitor* dlv = dynamic_cast<DisplayListVisitor*>(_initVisitor.get());
|
||||
GLObjectsVisitor* dlv = dynamic_cast<GLObjectsVisitor*>(_initVisitor.get());
|
||||
if (dlv) dlv->setState(_state.get());
|
||||
|
||||
if (_frameStamp.valid())
|
||||
|
||||
Reference in New Issue
Block a user