Updated to DatabasePager support

This commit is contained in:
Robert Osfield
2004-09-21 21:33:52 +00:00
parent 0d884d66eb
commit 54b45ce3bc
21 changed files with 404 additions and 219 deletions

View File

@@ -116,6 +116,7 @@ class SG_EXPORT Drawable : public Object
{
public:
static unsigned int s_numberDrawablesReusedLastInLastFrame;
static unsigned int s_numberNewDrawablesInLastFrame;
static unsigned int s_numberDeletedDrawablesInLastFrame;
@@ -352,8 +353,15 @@ class SG_EXPORT Drawable : public Object
virtual void drawImplementation(State& state) const = 0;
/** Return a OpenGL display list handle a newly generated or reused from display list cache. */
static GLuint generateDisplayList(unsigned int contextID, unsigned int sizeHint = 0);
/** Set the minimum number of display lists to retain in the deleted display list cache. */
static void setMinimumNumberOfDisplayListsToRetainInCache(unsigned int minimum);
/** Get the minimum number of display lists to retain in the deleted display list cache. */
static unsigned int getMinimumNumberOfDisplayListsToRetainInCache();
/** use deleteDisplayList instead of glDeleteList to allow
* OpenGL display list to be cached until they can be deleted
* by the OpenGL context in which they were created, specified
@@ -362,7 +370,11 @@ class SG_EXPORT Drawable : public Object
/** flush all the cached display list which need to be deleted
* in the OpenGL context related to contextID.*/
static void flushDeletedDisplayLists(unsigned int contextID,double currentTime, double& availableTime);
static void flushAllDeletedDisplayLists(unsigned int contextID);
/** flush the cached display list which need to be deleted
* in the OpenGL context related to contextID.*/
static void flushDeletedDisplayLists(unsigned int contextID,double& availableTime);
/** use deleteVertexBufferObject instead of glDeleteList to allow
* OpenGL buffer objects to be cached until they can be deleted
@@ -764,7 +776,7 @@ inline void Drawable::draw(State& state) const
else if (_useDisplayList)
{
#ifdef USE_SEPARATE_COMPILE_AND_EXECUTE
globj = generateDisplayList(contextID, getGLObjectSizeHint()); // glGenLists( 1 );
globj = generateDisplayList(contextID, getGLObjectSizeHint());
glNewList( globj, GL_COMPILE );
if (_drawCallback.valid())
_drawCallback->drawImplementation(state,this);
@@ -774,7 +786,7 @@ inline void Drawable::draw(State& state) const
glCallList( globj);
#else
globj = generateDisplayList(contextID, getGLObjectSizeHint()); // glGenLists( 1 );
globj = generateDisplayList(contextID, getGLObjectSizeHint());
glNewList( globj, GL_COMPILE_AND_EXECUTE );
if (_drawCallback.valid())
_drawCallback->drawImplementation(state,this);

View File

@@ -20,8 +20,6 @@
#include <typeinfo>
#define THREAD_SAFE_GLOBJECT_DELETE_LISTS 1
namespace osg {

View File

@@ -24,11 +24,6 @@
#include <list>
#include <map>
#ifdef THREAD_SAFE_GLOBJECT_DELETE_LISTS
#include <OpenThreads/ScopedLock>
#include <OpenThreads/Mutex>
#endif
// If not defined by gl.h use the definition found in:
// http://oss.sgi.com/projects/ogl-sample/registry/EXT/texture_filter_anisotropic.txt
#ifndef GL_TEXTURE_MAX_ANISOTROPY_EXT
@@ -651,80 +646,36 @@ class SG_EXPORT Texture : public osg::StateAttribute
* in the specified TextureObjectListMap. */
void takeTextureObjects(TextureObjectListMap& toblm);
static TextureObject* generateTextureObject(unsigned int contextID,GLenum target);
static TextureObject* generateTextureObject(unsigned int contextID,
GLenum target,
GLint numMipmapLevels,
GLenum internalFormat,
GLsizei width,
GLsizei height,
GLsizei depth,
GLint border);
/** Set the minimum number of texture objects to retain in the deleted display list cache. */
static void setMinimumNumberOfTextureObjectsToRetainInCache(unsigned int minimum);
/** Get the minimum number of display lists to retain in the deleted display list cache. */
static unsigned int getMinimumNumberOfTextureObjectsToRetainInCache();
static void flushAllDeletedTextureObjects(unsigned int contextID);
static void flushDeletedTextureObjects(unsigned int contextID,double currentTime, double& availableTime);
protected:
typedef buffered_object< ref_ptr<TextureObject> > TextureObjectBuffer;
mutable TextureObjectBuffer _textureObjectBuffer;
class SG_EXPORT TextureObjectManager : public osg::Referenced
{
public:
TextureObjectManager():
_expiryDelay(0.0) {}
virtual TextureObject* generateTextureObject(unsigned int contextID,GLenum target);
virtual TextureObject* generateTextureObject(unsigned int contextID,
GLenum target,
GLint numMipmapLevels,
GLenum internalFormat,
GLsizei width,
GLsizei height,
GLsizei depth,
GLint border);
virtual TextureObject* reuseTextureObject(unsigned int contextID,
GLenum target,
GLint numMipmapLevels,
GLenum internalFormat,
GLsizei width,
GLsizei height,
GLsizei depth,
GLint border);
inline TextureObject* reuseOrGenerateTextureObject(unsigned int contextID,
GLenum target,
GLint numMipmapLevels,
GLenum internalFormat,
GLsizei width,
GLsizei height,
GLsizei depth,
GLint border)
{
TextureObject* to = reuseTextureObject(contextID,target,numMipmapLevels,internalFormat,width,height,depth,border);
if (to) return to;
else return generateTextureObject(contextID,target,numMipmapLevels,internalFormat,width,height,depth,border);
}
virtual void addTextureObjects(TextureObjectListMap& toblm);
virtual void addTextureObjectsFrom(Texture& texture);
virtual void flushTextureObjects(unsigned int contextID,double currentTime, double& availableTime);
void setExpiryDelay(double expiryDelay) { _expiryDelay = expiryDelay; }
double getExpiryDelay() const { return _expiryDelay; }
/** How long to keep unused texture objects before deletion. */
double _expiryDelay;
TextureObjectListMap _textureObjectListMap;
#ifdef THREAD_SAFE_GLOBJECT_DELETE_LISTS
// mutex to keep access serialized.
OpenThreads::Mutex _mutex;
#endif
};
static void setTextureObjectManager(TextureObjectManager* tom);
static TextureObjectManager* getTextureObjectManager();
static void flushTextureObjects(unsigned int contextID,double currentTime, double& availableTime);
};
}

View File

@@ -198,11 +198,11 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl
}
/** Turn the compilation of rendering objects for specfied graphics context on (true) or off(false).*/
void setCompileGLObjectsForContexID(unsigned int contextID, bool on);
/** Turn the compilation of rendering objects for specfied graphics context on (true) or off(false). */
void setCompileGLObjectsForContextID(unsigned int contextID, bool on);
/** Get whether the compilation of rendering objects for specfied graphics context on (true) or off(false).*/
bool getCompileGLObjectsForContexID(unsigned int contextID);
/** Get whether the compilation of rendering objects for specfied graphics context on (true) or off(false). */
bool getCompileGLObjectsForContextID(unsigned int contextID);
/** Compile the rendering objects (display lists,texture objects, VBO's) on loaded subgraph.
* note, should only be called from the draw thread.*/
@@ -249,6 +249,10 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl
virtual ~DatabasePager();
OpenThreads::Mutex _run_mutex;
bool _startThreadCalled;
osg::ref_ptr<Block> _databasePagerThreadBlock;
inline void updateDatabasePagerThreadBlock()

View File

@@ -414,7 +414,10 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced, public osg::CullSetting
/** Do draw traversal of draw bins generated by cull traversal.*/
virtual void draw();
/** Flush all the OpenGL objects, such as texture objects, display lists etc.*/
/** Flush all deleted OpenGL objects, such as texture objects, display lists etc.*/
virtual void flushAllDeletedGLObjects();
/** Flush deleted OpenGL objects, such as texture objects, display lists etc within specified available time.*/
virtual void flushDeletedGLObjects(double& availableTime);
protected: