Added a concrete osg::DeleteHandler implementation which provides support for
retain objects for several frames before deleting them. Also added RenderStageCache into CullVistor.cpp that is used for handling RTT osg::Camera's that are being used in double buffered SceneView usage.
This commit is contained in:
83
include/osg/DeleteHandler
Normal file
83
include/osg/DeleteHandler
Normal file
@@ -0,0 +1,83 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSG_DELETEHANDLER
|
||||
#define OSG_DELETEHANDLER 1
|
||||
|
||||
#include <osg/Referenced>
|
||||
|
||||
#include <list>
|
||||
|
||||
namespace osg {
|
||||
|
||||
|
||||
/** Class for override the default delete behavior so that users can implement their own object
|
||||
* deletion schemes. This might be done to help implement protection of multiple threads from deleting
|
||||
* objects unintentionally.
|
||||
* Note, the DeleteHandler cannot itself be reference counted, otherwise it
|
||||
* would be responsible for deleting itself!
|
||||
* An static auto_ptr<> is used internally in Referenced.cpp to manage the
|
||||
* DeleteHandler's memory.*/
|
||||
class DeleteHandler
|
||||
{
|
||||
public:
|
||||
|
||||
typedef std::pair<int, const osg::Referenced*> FrameNumberObjectPair;
|
||||
typedef std::list<FrameNumberObjectPair> ObjectsToDeleteList;
|
||||
|
||||
DeleteHandler(int numberOfFramesToRetainObjects=0);
|
||||
|
||||
virtual ~DeleteHandler() { flushAll(); }
|
||||
|
||||
/** Set the number of frames to retain objects that are have been requested for deletion.
|
||||
* When set to zero objects are deleted immediately, by set to 1 there are kept around for an extra frame etc.
|
||||
* The ability to retain obejcts for several frames is useful to prevent premature deletion when objects
|
||||
* are stil be used the graphics threads that are using double buffering of rendering data structures with
|
||||
* non ref_ptr<> pointers to scene graph elements.*/
|
||||
void setNumFramesToRetainObjects(int numberOfFramesToRetainObjects) { _numFramesToRetainObjects = numberOfFramesToRetainObjects; }
|
||||
|
||||
int getNumFramesToRetainObjects() const { return _numFramesToRetainObjects; }
|
||||
|
||||
/** Set the current frame numberso that subsequent deletes get tagged as associated with this frame.*/
|
||||
void setFrameNumber(int frameNumber) { _currentFrameNumber = frameNumber; }
|
||||
|
||||
/** Get the current frame number.*/
|
||||
int getFrameNumber() const { return _currentFrameNumber; }
|
||||
|
||||
inline void doDelete(const Referenced* object) { delete object; }
|
||||
|
||||
/** Flush objects that ready to be fully deleted.*/
|
||||
virtual void flush();
|
||||
|
||||
/** Flush all objects that the DeleteHandler holds.
|
||||
* Note, this should only be called if there are no threads running with non ref_ptr<> pointers, such as graphics threads.*/
|
||||
virtual void flushAll();
|
||||
|
||||
/** Request the deletion of an object.
|
||||
* Depending on users implementation of DeleteHandler, the delete of the object may occur
|
||||
* straight away or be delayed until doDelete is called.
|
||||
* The default implementation does a delete straight away.*/
|
||||
virtual void requestDelete(const osg::Referenced* object);
|
||||
|
||||
protected:
|
||||
|
||||
int _numFramesToRetainObjects;
|
||||
int _currentFrameNumber;
|
||||
OpenThreads::Mutex _mutex;
|
||||
ObjectsToDeleteList _objectsToDelete;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <OpenThreads/Mutex>
|
||||
#endif
|
||||
|
||||
|
||||
namespace osg {
|
||||
|
||||
#ifndef OSG_JAVA_BUILD
|
||||
@@ -104,8 +105,11 @@ class OSG_EXPORT Referenced
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~Referenced();
|
||||
|
||||
void deletUsingDeleteHandler() const;
|
||||
|
||||
mutable OpenThreads::Mutex* _refMutex;
|
||||
|
||||
mutable int _refCount;
|
||||
@@ -114,32 +118,6 @@ class OSG_EXPORT Referenced
|
||||
|
||||
};
|
||||
|
||||
|
||||
/** Class for override the default delete behavior so that users can implment their own object
|
||||
* deletion schemes. This might be done to help implement protection of multiple threads from deleting
|
||||
* objects unintentionally.
|
||||
* Note, the DeleteHandler cannot itself be reference counted, otherwise it
|
||||
* would be responsible for deleting itself!
|
||||
* An static auto_ptr<> is used internally in Referenced.cpp to manage the
|
||||
* DeleteHandler's memory.*/
|
||||
class DeleteHandler
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~DeleteHandler() {}
|
||||
|
||||
/** flush any cache of objects that need to be deleted by doing an actual delete.*/
|
||||
virtual void flush() {}
|
||||
|
||||
inline void doDelete(const Referenced* object) { delete object; }
|
||||
|
||||
/** Request the deletion of an object.
|
||||
* Depending on users implementation of DeleteHandler, the delete of the object may occur
|
||||
* straight away or be delayed until doDelete is called.
|
||||
* The default implementation does a delete straight away.*/
|
||||
virtual void requestDelete(const Referenced* object) { doDelete(object); }
|
||||
};
|
||||
|
||||
inline void Referenced::ref() const
|
||||
{
|
||||
if (_refMutex)
|
||||
@@ -170,13 +148,14 @@ inline void Referenced::unref() const
|
||||
|
||||
if (needDelete)
|
||||
{
|
||||
if (getDeleteHandler()) getDeleteHandler()->requestDelete(this);
|
||||
if (getDeleteHandler()) deletUsingDeleteHandler();
|
||||
else delete this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
/** Java wrappers use the CBridgable base-class for referencing
|
||||
* and garbage collection.
|
||||
*/
|
||||
|
||||
@@ -72,8 +72,19 @@ class OSGUTIL_EXPORT RenderLeaf : public osg::Referenced
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
StateGraph* _parent;
|
||||
|
||||
#if 1
|
||||
osg::Drawable* _drawable;
|
||||
osg::Drawable* getDrawable() { return _drawable; }
|
||||
osg::Drawable* getDrawable() const { return _drawable; }
|
||||
#else
|
||||
osg::ref_ptr<osg::Drawable> _drawable;
|
||||
osg::Drawable* getDrawable() { return _drawable.get(); }
|
||||
osg::Drawable* getDrawable() const { return _drawable.get(); }
|
||||
#endif
|
||||
osg::ref_ptr<osg::RefMatrix> _projection;
|
||||
osg::ref_ptr<osg::RefMatrix> _modelview;
|
||||
float _depth;
|
||||
|
||||
Reference in New Issue
Block a user