diff --git a/include/osg/BufferObject b/include/osg/BufferObject index 13c1cb6e1..4a8980592 100644 --- a/include/osg/BufferObject +++ b/include/osg/BufferObject @@ -238,6 +238,8 @@ class OSG_EXPORT GLBufferObject : public Referenced * by contextID.*/ static void deleteBufferObject(unsigned int contextID,GLuint globj); + static void deleteAllBufferObjects(unsigned int contextID); + static void discardAllBufferObjects(unsigned int contextID); static void flushAllDeletedBufferObjects(unsigned int contextID); static void discardAllDeletedBufferObjects(unsigned int contextID); static void flushDeletedBufferObjects(unsigned int contextID,double currentTime, double& availbleTime); @@ -315,7 +317,7 @@ class OSG_EXPORT GLBufferObject : public Referenced static void setExtensions(unsigned int contextID,Extensions* extensions); protected: - + virtual ~GLBufferObject(); unsigned int _contextID; @@ -351,6 +353,9 @@ class OSG_EXPORT GLBufferObjectSet : public Referenced GLBufferObjectSet(GLBufferObjectManager* parent, const BufferObjectProfile& profile); void handlePendingOrphandedGLBufferObjects(); + + void deleteAllGLBufferObjects(); + void discardAllGLBufferObjects(); void flushAllDeletedGLBufferObjects(); void discardAllDeletedGLBufferObjects(); void flushDeletedGLBufferObjects(double currentTime, double& availableTime); @@ -419,6 +424,9 @@ class OSG_EXPORT GLBufferObjectManager : public osg::Referenced GLBufferObject* generateGLBufferObject(const osg::BufferObject* bufferObject); void handlePendingOrphandedGLBufferObjects(); + + void deleteAllGLBufferObjects(); + void discardAllGLBufferObjects(); void flushAllDeletedGLBufferObjects(); void discardAllDeletedGLBufferObjects(); void flushDeletedGLBufferObjects(double currentTime, double& availableTime); diff --git a/include/osg/GLObjects b/include/osg/GLObjects index 32689deef..a7570ed33 100644 --- a/include/osg/GLObjects +++ b/include/osg/GLObjects @@ -26,13 +26,24 @@ extern OSG_EXPORT void flushDeletedGLObjects(unsigned int contextID, double curr * Note, must be called from a thread which has current the graphics context associated with contextID. */ extern OSG_EXPORT void flushAllDeletedGLObjects(unsigned int contextID); +/** Do a GL delete all OpenGL objects. + * Note, must be called from a thread which has current the graphics context associated with contextID. */ +extern OSG_EXPORT void deleteAllGLObjects(unsigned int contextID); + /** Discard all deleted OpenGL objects. - * Note, unlike flushAllDeletedObjectObjects discard does not - * do any OpenGL calls so can be called from any thread, but as a consequence it - * also doesn't remove the associated OpenGL resource so discard should only be + * Note, unlike flushAllDeletedObjectObjects discard does not + * do any OpenGL calls so can be called from any thread, but as a consequence it + * also doesn't remove the associated OpenGL resource so discard should only be * called when the associated graphics context is being/has been closed. */ extern OSG_EXPORT void discardAllDeletedGLObjects(unsigned int contextID); +/** Discard all OpenGL objects. + * Note, unlike deletedAllObjectObjects discard does not + * do any OpenGL calls so can be called from any thread, but as a consequence it + * also doesn't remove the associated OpenGL resource so discard should only be + * called when the associated graphics context is being/has been closed. */ +extern OSG_EXPORT void discardAllGLObjects(unsigned int contextID); + } #endif diff --git a/include/osg/Texture b/include/osg/Texture index 15b348881..acb405a92 100644 --- a/include/osg/Texture +++ b/include/osg/Texture @@ -983,6 +983,7 @@ class OSG_EXPORT Texture : public osg::StateAttribute _profile.match(target,numMipmapLevels,internalFormat,width,height,depth,border); } + void bind(); inline GLenum id() const { return _id; } @@ -1019,6 +1020,10 @@ class OSG_EXPORT Texture : public osg::StateAttribute bool _allocated; unsigned int _frameLastUsed; double _timeStamp; + + protected: + virtual ~TextureObject(); + }; typedef std::list< ref_ptr > TextureObjectList; @@ -1029,6 +1034,9 @@ class OSG_EXPORT Texture : public osg::StateAttribute TextureObjectSet(TextureObjectManager* parent, const TextureProfile& profile); void handlePendingOrphandedTextureObjects(); + + void deleteAllTextureObjects(); + void discardAllTextureObjects(); void flushAllDeletedTextureObjects(); void discardAllDeletedTextureObjects(); void flushDeletedTextureObjects(double currentTime, double& availableTime); @@ -1104,6 +1112,8 @@ class OSG_EXPORT Texture : public osg::StateAttribute GLsizei depth, GLint border); void handlePendingOrphandedTextureObjects(); + void deleteAllTextureObjects(); + void discardAllTextureObjects(); void flushAllDeletedTextureObjects(); void discardAllDeletedTextureObjects(); void flushDeletedTextureObjects(double currentTime, double& availableTime); @@ -1173,12 +1183,11 @@ class OSG_EXPORT Texture : public osg::StateAttribute /** Get the minimum number of display lists to retain in the deleted display list cache. */ static unsigned int getMinimumNumberOfTextureObjectsToRetainInCache(); + static void deleteAllTextureObjects(unsigned int contextID); + static void discardAllTextureObjects(unsigned int contextID); static void flushAllDeletedTextureObjects(unsigned int contextID); - static void discardAllDeletedTextureObjects(unsigned int contextID); - static void flushDeletedTextureObjects(unsigned int contextID,double currentTime, double& availableTime); - static void releaseTextureObject(unsigned int contextID, TextureObject* to); protected: diff --git a/src/osg/BufferObject.cpp b/src/osg/BufferObject.cpp index 9159a7acc..e127295c3 100644 --- a/src/osg/BufferObject.cpp +++ b/src/osg/BufferObject.cpp @@ -60,10 +60,13 @@ GLBufferObject::GLBufferObject(unsigned int contextID, BufferObject* bufferObjec assign(bufferObject); _extensions = GLBufferObject::getExtensions(contextID, true); _extensions->glGenBuffers(1, &_glObjectID); + + osg::notify(osg::NOTICE)<<"Constucting BufferObject "< glbo = to; + + to = to->_next; + + ref_ptr original_BufferObject = glbo->getBufferObject(); + if (original_BufferObject.valid()) + { + // detect the GLBufferObject from the BufferObject + original_BufferObject->setGLBufferObject(_contextID,0); + } + } + + // the linked list should now be empty + _head = 0; + + _pendingOrphanedGLBufferObjects.clear(); + _orphanedGLBufferObjects.clear(); +} + void GLBufferObjectSet::flushAllDeletedGLBufferObjects() { for(GLBufferObjectList::iterator itr = _orphanedGLBufferObjects.begin(); @@ -566,6 +600,15 @@ void GLBufferObjectSet::flushAllDeletedGLBufferObjects() void GLBufferObjectSet::discardAllDeletedGLBufferObjects() { + osg::notify(osg::NOTICE)<<"GLBufferObjectSet::discardAllDeletedGLBufferObjects()"< lock(_mutex); @@ -846,7 +889,7 @@ void GLBufferObjectSet::orphan(GLBufferObject* to) // to avoid having to mutex the process of appling active TO's. _pendingOrphanedGLBufferObjects.push_back(to); -#if 0 +#if 1 osg::notify(osg::NOTICE)<<"GLBufferObjectSet::orphan("<getContextID(); @@ -1133,6 +1209,7 @@ void BufferObject::releaseGLObjects(State* state) const { if (_glBufferObjects[i].valid()) { + osg::notify(osg::NOTICE)<<" GLBufferObject::releaseGLBufferObject("<getContextID()); + osg::deleteAllGLObjects(_state->getContextID()); - osg::notify(osg::INFO)<<"Done Flush "<reset(); @@ -557,7 +557,7 @@ void GraphicsContext::close(bool callCloseImplementation) { osg::notify(osg::INFO)<<"Doing discard of deleted OpenGL objects."<getContextID()); + osg::discardAllGLObjects(_state->getContextID()); } if (_state.valid()) diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index ac689a4b9..7934fff7a 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -72,6 +72,11 @@ unsigned int Texture::getMinimumNumberOfTextureObjectsToRetainInCache() #define USE_NEW_TEXTURE_POOL 1 +Texture::TextureObject::~TextureObject() +{ + osg::notify(osg::NOTICE)<<"Texture::TextureObject::~TextureObject() "< glto = to; + + to = to->_next; + + ref_ptr original_texture = glto->getTexture(); + + if (original_texture.valid()) + { + original_texture->setTextureObject(_contextID,0); + } + } + + // the linked list should now be empty + _head = 0; + + _pendingOrphanedTextureObjects.clear(); + _orphanedTextureObjects.clear(); +} + void Texture::TextureObjectSet::flushAllDeletedTextureObjects() { + // osg::notify(osg::NOTICE)<<"Texture::TextureObjectSet::flushAllDeletedTextureObjects()"<