Added more comprehensive releaseGLObjects(State*=0) throughout Nodes,
Drawables,StateSet, and osgDB::Registry. Added cleanup_frame() from to osgProducer::OsgCamerGroup to help with proper clean of OpenGL objects before exit, and modified osgviewer, osghangglider, osgwindows examples to do the extra frame call to cleanup_frame() before exit.
This commit is contained in:
@@ -490,6 +490,8 @@ void Drawable::compileGLObjects(State& state) const
|
||||
|
||||
void Drawable::releaseGLObjects(State* state) const
|
||||
{
|
||||
if (_stateset.valid()) _stateset->releaseGLObjects(state);
|
||||
|
||||
if (!_useDisplayList) return;
|
||||
|
||||
if (state)
|
||||
|
||||
@@ -214,3 +214,15 @@ void Geode::compileDrawables(State& state)
|
||||
(*itr)->compileGLObjects(state);
|
||||
}
|
||||
}
|
||||
|
||||
void Geode::releaseGLObjects(osg::State* state) const
|
||||
{
|
||||
Node::releaseGLObjects(state);
|
||||
|
||||
for(DrawableList::const_iterator itr=_drawables.begin();
|
||||
itr!=_drawables.end();
|
||||
++itr)
|
||||
{
|
||||
(*itr)->releaseGLObjects(state);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -388,3 +388,15 @@ bool Group::computeBound() const
|
||||
_bsphere_computed = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void Group::releaseGLObjects(osg::State* state) const
|
||||
{
|
||||
Node::releaseGLObjects(state);
|
||||
|
||||
for(NodeList::const_iterator itr=_children.begin();
|
||||
itr!=_children.end();
|
||||
++itr)
|
||||
{
|
||||
(*itr)->releaseGLObjects(state);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -427,3 +427,11 @@ void Node::dirtyBound()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void Node::releaseGLObjects(osg::State* state) const
|
||||
{
|
||||
if (_stateset.valid()) _stateset->releaseGLObjects(state);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1787,6 +1787,19 @@ void Registry::clearArchiveCache()
|
||||
_archiveCache.clear();
|
||||
}
|
||||
|
||||
void Registry::releaseGLObjects(osg::State* state)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex);
|
||||
|
||||
for(ObjectCache::iterator itr = _objectCache.begin();
|
||||
itr != _objectCache.end();
|
||||
++itr)
|
||||
{
|
||||
osg::Object* object = itr->second.first.get();
|
||||
object->releaseGLObjects(state);
|
||||
}
|
||||
}
|
||||
|
||||
DatabasePager* Registry::getOrCreateDatabasePager()
|
||||
{
|
||||
if (!_databasePager) _databasePager = new DatabasePager;
|
||||
|
||||
@@ -644,3 +644,23 @@ void OsgCameraGroup::frame()
|
||||
CameraGroup::frame();
|
||||
}
|
||||
|
||||
void OsgCameraGroup::cleanup_frame()
|
||||
{
|
||||
// first relase all GL objects and switch on the flush of deleted objects
|
||||
// in the next frame.
|
||||
for(SceneHandlerList::iterator itr = _shvec.begin();
|
||||
itr != _shvec.end();
|
||||
++itr)
|
||||
{
|
||||
(*itr)->getSceneView()->releaseAllGLObjects();
|
||||
(*itr)->setFlushOfAllDeletedGLObjectsOnNextFrame(true);
|
||||
}
|
||||
|
||||
// make sure that the registry all flushes all its texture objects.
|
||||
osgDB::Registry::instance()->releaseGLObjects();
|
||||
|
||||
// then run the frame to do the actuall OpenGL clean up.
|
||||
frame();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ OsgSceneHandler::OsgSceneHandler( osg::DisplaySettings *ds) :
|
||||
{
|
||||
_frameStartTick = 0;
|
||||
_previousFrameStartTick = 0;
|
||||
_flushOfAllDeletedGLObjectsOnNextFrame = false;
|
||||
}
|
||||
|
||||
void OsgSceneHandler::init()
|
||||
|
||||
@@ -1008,3 +1008,12 @@ void Text::accept(osg::PrimitiveFunctor& pf) const
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** If State is non-zero, this function releases OpenGL objects for
|
||||
* the specified graphics context. Otherwise, releases OpenGL objexts
|
||||
* for all graphics contexts. */
|
||||
void Text::releaseGLObjects(osg::State* state) const
|
||||
{
|
||||
Drawable::releaseGLObjects(state);
|
||||
if (_font.valid()) _font->releaseGLObjects(state);
|
||||
}
|
||||
|
||||
@@ -641,15 +641,14 @@ void SceneView::releaseAllGLObjects()
|
||||
{
|
||||
if (!_sceneData) return;
|
||||
|
||||
GLObjectsVisitor globjv(GLObjectsVisitor::RELEASE_DISPLAY_LISTS|GLObjectsVisitor::RELEASE_STATE_ATTRIBUTES);
|
||||
globjv.setNodeMaskOverride(0xffffffff);
|
||||
globjv.setState(_state.get());
|
||||
_sceneData->accept(globjv);
|
||||
_sceneData->releaseGLObjects(_state.get());
|
||||
}
|
||||
|
||||
|
||||
void SceneView::flushAllDeletedGLObjects()
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"SceneView::flushAllDeletedGLObjects()"<<std::endl;
|
||||
|
||||
_requiresFlush = false;
|
||||
|
||||
double availableTime = 100.0f;
|
||||
@@ -660,7 +659,8 @@ void SceneView::flushAllDeletedGLObjects()
|
||||
osg::Drawable::flushDeletedVertexBufferObjects(_state->getContextID(),currentTime,availableTime);
|
||||
osg::VertexProgram::flushDeletedVertexProgramObjects(_state->getContextID(),currentTime,availableTime);
|
||||
osg::FragmentProgram::flushDeletedFragmentProgramObjects(_state->getContextID(),currentTime,availableTime);
|
||||
}
|
||||
osg::Program::flushDeletedGlPrograms(_state->getContextID(),currentTime,availableTime);
|
||||
}
|
||||
|
||||
void SceneView::flushDeletedGLObjects(double& availableTime)
|
||||
{
|
||||
@@ -672,6 +672,7 @@ void SceneView::flushDeletedGLObjects(double& availableTime)
|
||||
osg::Drawable::flushDeletedVertexBufferObjects(_state->getContextID(),currentTime,availableTime);
|
||||
osg::VertexProgram::flushDeletedVertexProgramObjects(_state->getContextID(),currentTime,availableTime);
|
||||
osg::FragmentProgram::flushDeletedFragmentProgramObjects(_state->getContextID(),currentTime,availableTime);
|
||||
osg::Program::flushDeletedGlPrograms(_state->getContextID(),currentTime,availableTime);
|
||||
}
|
||||
|
||||
void SceneView::draw()
|
||||
|
||||
Reference in New Issue
Block a user