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:
Robert Osfield
2005-05-07 20:47:09 +00:00
parent 08d5f9f85a
commit d1a1b1d95c
23 changed files with 167 additions and 21 deletions

View File

@@ -238,10 +238,9 @@ class OSG_EXPORT Drawable : public Object
*/
virtual void compileGLObjects(State& state) const;
/**
if osg::State object is supplied: release any OpenGL display lists associated with graphics context specified
or
if state pointer is NULL: release all display lists for all graphics contexts */
/** If State is non-zero, this function releases OpenGL objects for
* the specified graphics context. Otherwise, releases OpenGL objexts
* for all graphics contexts. */
virtual void releaseGLObjects(State* state=0) const;
struct UpdateCallback : public virtual osg::Object

View File

@@ -132,6 +132,11 @@ class OSG_EXPORT Geode : public Node
return _bbox;
}
/** If State is non-zero, this function releases any associated OpenGL objects for
* the specified graphics context. Otherwise, releases OpenGL objexts
* for all graphics contexts. */
virtual void releaseGLObjects(osg::State* = 0) const;
protected:
virtual ~Geode();

View File

@@ -120,6 +120,12 @@ class OSG_EXPORT Group : public Node
return _children.size(); // node not found.
}
/** If State is non-zero, this function releases any associated OpenGL objects for
* the specified graphics context. Otherwise, releases OpenGL objexts
* for all graphics contexts. */
virtual void releaseGLObjects(osg::State* = 0) const;
protected:
virtual ~Group();

View File

@@ -248,6 +248,12 @@ class OSG_EXPORT Node : public Object
void dirtyBound();
/** If State is non-zero, this function releases any associated OpenGL objects for
* the specified graphics context. Otherwise, releases OpenGL objexts
* for all graphics contexts. */
virtual void releaseGLObjects(osg::State* = 0) const;
protected:
/** Node destructor. Note, is protected so that Nodes cannot

View File

@@ -20,6 +20,9 @@
namespace osg {
// forward declare
class State;
/** META_Object macro define the standard clone, isSameKindAs and className methods.
* Use when subclassing from Object to make it more convenient to define
* the standard pure virtual clone, isSameKindAs and className methods
@@ -102,6 +105,11 @@ class OSG_EXPORT Object : public Referenced
inline const Referenced* getUserData() const { return _userData.get(); }
/** If State is non-zero, this function releases any associated OpenGL objects for
* the specified graphics context. Otherwise, releases OpenGL objexts
* for all graphics contexts. */
virtual void releaseGLObjects(osg::State* = 0) const {}
protected:
/** Object destructor. Note, is protected so that Objects cannot

View File

@@ -349,7 +349,11 @@ class OSGDB_EXPORT Registry : public osg::Referenced
/** Remove all archives from the archive cache.*/
void clearArchiveCache();
/** If State is non-zero, this function releases OpenGL objects for
* the specified graphics context. Otherwise, releases OpenGL objexts
* for all graphics contexts. */
void releaseGLObjects(osg::State* state=0);
/** get the attached library with specified name.*/
DynamicLibrary* getLibrary(const std::string& fileName);

View File

@@ -188,9 +188,16 @@ class OSGPRODUCER_EXPORT OsgCameraGroup : public Producer::CameraGroup
/** Dispatch the cull and draw for each of the Camera's for this frame.*/
virtual void frame();
/** 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 :
virtual void setUpSceneViewsWithData();

View File

@@ -79,8 +79,15 @@ class OSGPRODUCER_EXPORT OsgSceneHandler : public Producer::Camera::SceneHandler
virtual void draw(Producer::Camera& camera)
{
if (_flushOfAllDeletedGLObjectsOnNextFrame && _sceneView.valid())
{
_sceneView->flushAllDeletedGLObjects();
}
if (_drawCallback.valid()) (*_drawCallback)(*this,camera);
else drawImplementation(camera);
_flushOfAllDeletedGLObjectsOnNextFrame = false;
}
virtual void drawImplementation(Producer::Camera& camera);
@@ -89,10 +96,12 @@ class OSGPRODUCER_EXPORT OsgSceneHandler : public Producer::Camera::SceneHandler
Callback* getDrawCallback() { return _drawCallback.get(); }
const Callback* getDrawCallback() const { return _drawCallback.get(); }
void setContextID( int id );
void setFlushOfAllDeletedGLObjectsOnNextFrame(bool flag) { _flushOfAllDeletedGLObjectsOnNextFrame = flag; }
bool getFlushOfAllDeletedGLObjectsOnNextFrame() const { return _flushOfAllDeletedGLObjectsOnNextFrame; }
protected:
virtual ~OsgSceneHandler() {}
@@ -106,6 +115,8 @@ class OSGPRODUCER_EXPORT OsgSceneHandler : public Producer::Camera::SceneHandler
osg::Timer_t _frameStartTick;
osg::Timer_t _previousFrameStartTick;
bool _flushOfAllDeletedGLObjectsOnNextFrame;
};
}

View File

@@ -120,7 +120,7 @@ public:
/** If State is non-zero, this function releases OpenGL objects for
* the specified graphics context. Otherwise, releases OpenGL objexts
* for all graphics contexts. */
virtual void releaseGLObjects(osg::State* state=0) const;
virtual void releaseGLObjects(osg::State* state=0) const;
protected:

View File

@@ -235,6 +235,10 @@ public:
/** accept a PrimtiveFunctor and call its methods to tell it about the interal primtives that this Drawable has.*/
virtual void 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. */
virtual void releaseGLObjects(osg::State* state=0) const;
// make Font a friend to allow it set the _font to 0 if the font is
// forcefully unloaded.