Added releaseGLObjects to NodeCallbacks, Drawable::DrawCallbacks and wired up

osgProducer to use it when doing cleanup_frame.
This commit is contained in:
Robert Osfield 2006-10-02 15:38:31 +00:00
parent 02783e1dfd
commit e0599f652e
12 changed files with 81 additions and 8 deletions

View File

@ -30,6 +30,8 @@ QT4_ROOT ?= /usr/local/
SDL_INSTALLED ?= no SDL_INSTALLED ?= no
FLTK_INSTALLED ?= no
ifeq ($(OS),Darwin) ifeq ($(OS),Darwin)
DARWIN_QUICKTIME ?= yes DARWIN_QUICKTIME ?= yes
endif endif

View File

@ -285,6 +285,7 @@ endif
ifeq ($(GLUT_INSTALLED),yes) ifeq ($(GLUT_INSTALLED),yes)
EXAMPLE_DIRS += osgGLUTsimple EXAMPLE_DIRS += osgGLUTsimple
EXAMPLE_DIRS += osgGLUTkeyboardmouse EXAMPLE_DIRS += osgGLUTkeyboardmouse
EXAMPLE_DIRS += osgsimpleviewerGLUT
endif endif
ifeq ($(QT3_INSTALLED),yes) ifeq ($(QT3_INSTALLED),yes)
@ -298,3 +299,11 @@ endif
ifeq ($(SDL_INSTALLED),yes) ifeq ($(SDL_INSTALLED),yes)
EXAMPLE_DIRS += osgsimpleviewerSDL EXAMPLE_DIRS += osgsimpleviewerSDL
endif endif
ifeq ($(FLTK_INSTALLED),yes)
EXAMPLE_DIRS += osgsimpleviewerFLTK
endif
ifeq ($(PRODUCER_INSTALLED),yes)
EXAMPLE_DIRS += osgsimpleviewerProducer
endif

View File

@ -378,6 +378,11 @@ class OSG_EXPORT Drawable : public Object
/** do customized draw code.*/ /** do customized draw code.*/
virtual void drawImplementation(osg::RenderInfo& renderInfo,const osg::Drawable* drawable) const { drawImplementation(*renderInfo.getState(), drawable); } virtual void drawImplementation(osg::RenderInfo& renderInfo,const osg::Drawable* drawable) const { drawImplementation(*renderInfo.getState(), drawable); }
/** release OpenGL objects in specified graphics context if State
object is passed, otherwise release OpenGL objexts for all graphics context if
State object pointer NULL.*/
virtual void releaseGLObjects(State* =0) const {}
}; };
/** Set the DrawCallback which allows users to attach customize the drawing of existing Drawable object.*/ /** Set the DrawCallback which allows users to attach customize the drawing of existing Drawable object.*/

View File

@ -82,6 +82,12 @@ class OSG_EXPORT NodeCallback : public virtual Object {
} }
} }
} }
/** release OpenGL objects in specified graphics context if State
object is passed, otherwise release OpenGL objexts for all graphics context if
State object pointer NULL.*/
virtual void releaseGLObjects(State* =0) const {}
public: public:

View File

@ -69,7 +69,10 @@ class OSGGA_EXPORT SimpleViewer : public osgGA::GUIActionAdapter, public osg::Re
virtual void frameCullTraversal(); virtual void frameCullTraversal();
virtual void frameDrawTraversal(); virtual void frameDrawTraversal();
/** Clean up all OpenGL objects associated with this viewer scenegraph. Note, must only be called from the graphics context associated with this viewer.*/ /** Release all OpenGL objects associated with this viewer's scenegraph. Note, does not deleted the actual OpenGL objects, it just releases them to the pending GL object delete lists which will need flushing once a valid graphics context is obtained.*/
virtual void releaseAllGLObjects();
/** Clean up all OpenGL objects associated with this viewer's scenegraph. Note, must only be called from the graphics context associated with this viewer.*/
virtual void cleanup(); virtual void cleanup();
public: public:

View File

@ -305,6 +305,12 @@ class OSGPRODUCER_EXPORT Viewer : public OsgCameraGroup, public osgGA::GUIAction
/** Update internal structures w.r.t updated scene data.*/ /** Update internal structures w.r.t updated scene data.*/
virtual void updatedSceneData(); virtual void updatedSceneData();
/** Dispatch a clean up frame that should be called before closing a OsgCameraGroup, i.e. on exit from an app.
* The clean up frame first release all GL objects associated with all the graphics context associated with
* the camera group, then runs a special frame that does the actual OpenGL deletion of GL objects for each
* graphics context. */
virtual void cleanup_frame();
protected : protected :

View File

@ -61,6 +61,11 @@ class OSGPRODUCER_EXPORT ViewerEventHandler : public osgGA::GUIEventHandler
void setWriteImageFileName(const std::string& filename); void setWriteImageFileName(const std::string& filename);
const std::string& getWriteImageFileName() const { return _writeImageFileName; } const std::string& getWriteImageFileName() const { return _writeImageFileName; }
/** release OpenGL objects in specified graphics context if State
object is passed, otherwise release OpenGL objexts for all graphics context if
State object pointer NULL.*/
virtual void releaseGLObjects(osg::State* =0) const;
protected: protected:
osgProducer::OsgCameraGroup* _cg; osgProducer::OsgCameraGroup* _cg;

View File

@ -483,6 +483,8 @@ void Drawable::releaseGLObjects(State* state) const
{ {
if (_stateset.valid()) _stateset->releaseGLObjects(state); if (_stateset.valid()) _stateset->releaseGLObjects(state);
if (_drawCallback.valid()) _drawCallback->releaseGLObjects(state);
if (!_useDisplayList) return; if (!_useDisplayList) return;
if (state) if (state)

View File

@ -494,6 +494,9 @@ void Node::dirtyBound()
void Node::releaseGLObjects(osg::State* state) const void Node::releaseGLObjects(osg::State* state) const
{ {
if (_stateset.valid()) _stateset->releaseGLObjects(state); if (_stateset.valid()) _stateset->releaseGLObjects(state);
if (_updateCallback.valid()) _updateCallback->releaseGLObjects(state);
if (_eventCallback.valid()) _eventCallback->releaseGLObjects(state);
if (_cullCallback.valid()) _cullCallback->releaseGLObjects(state);
} }

View File

@ -276,20 +276,29 @@ void SimpleViewer::frameDrawTraversal()
} }
} }
void SimpleViewer::cleanup() void SimpleViewer::releaseAllGLObjects()
{ {
for(EventHandlers::iterator hitr = _eventHandlers.begin();
hitr != _eventHandlers.end();
++hitr)
{
(*hitr)->releaseGLObjects(_sceneView->getState());
}
if (_databasePager.valid()) if (_databasePager.valid())
{ {
// clear the database pager so its starts a fresh on the next update/cull/draw traversals // clear the database pager so its starts a fresh on the next update/cull/draw traversals
_databasePager->clear(); _databasePager->clear();
// release the GL objects stored in the scene graph.
_sceneView->releaseAllGLObjects();
// do a flush to delete all the OpenGL objects that have been deleted or released from the scene graph.
_sceneView->flushAllDeletedGLObjects();
} }
// release the GL objects stored in the scene graph.
_sceneView->releaseAllGLObjects(); _sceneView->releaseAllGLObjects();
}
void SimpleViewer::cleanup()
{
releaseAllGLObjects();
// do a flush to delete all the OpenGL objects that have been deleted or released from the scene graph.
_sceneView->flushAllDeletedGLObjects(); _sceneView->flushAllDeletedGLObjects();
} }

View File

@ -972,3 +972,14 @@ void Viewer::getUsage(osg::ApplicationUsage& usage) const
} }
} }
void Viewer::cleanup_frame()
{
for(EventHandlerList::iterator itr = _eventHandlerList.begin();
itr != _eventHandlerList.end();
++itr)
{
(*itr)->releaseGLObjects();
}
OsgCameraGroup::cleanup_frame();
}

View File

@ -104,6 +104,13 @@ public:
virtual void operator()( const Producer::Camera & camera); virtual void operator()( const Producer::Camera & camera);
void releaseGLObjects() const
{
{ for(TextList::const_iterator itr = _descriptionList.begin(); itr != _descriptionList.end(); ++itr) (*itr)->releaseGLObjects(); }
{ for(TextList::const_iterator itr = _optionList.begin(); itr != _optionList.end(); ++itr) (*itr)->releaseGLObjects(); }
{ for(TextList::const_iterator itr = _explanationList.begin(); itr != _explanationList.end(); ++itr) (*itr)->releaseGLObjects(); }
}
protected: protected:
ViewerEventHandler* _veh; ViewerEventHandler* _veh;
@ -1238,3 +1245,8 @@ void ViewerEventHandler::getUsage(osg::ApplicationUsage& usage) const
usage.addKeyboardMouseBinding("z","Start recording camera path."); usage.addKeyboardMouseBinding("z","Start recording camera path.");
usage.addKeyboardMouseBinding("Z","If recording camera path stop recording camera path, save to \"saved_animation.path\"\nThen restart camera from beginning on animation path"); usage.addKeyboardMouseBinding("Z","If recording camera path stop recording camera path, save to \"saved_animation.path\"\nThen restart camera from beginning on animation path");
} }
void ViewerEventHandler::releaseGLObjects(osg::State*) const
{
if (_statsAndHelpDrawCallback) _statsAndHelpDrawCallback->releaseGLObjects();
}