Introduced preliminary osg::deleteAllGLObjects() and osg::discardAllGLObjects() functions and associated support into Texture and BufferObjects
This commit is contained in:
@@ -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 "<<this<<std::endl;
|
||||
}
|
||||
|
||||
GLBufferObject::~GLBufferObject()
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Destucting BufferObject "<<this<<std::endl;
|
||||
}
|
||||
|
||||
void GLBufferObject::bindBuffer()
|
||||
@@ -541,6 +544,37 @@ void GLBufferObjectSet::handlePendingOrphandedGLBufferObjects()
|
||||
checkConsistency();
|
||||
}
|
||||
|
||||
void GLBufferObjectSet::deleteAllGLBufferObjects()
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"GLBufferObjectSet::deleteAllGLBufferObjects() not implemented yet."<<std::endl;
|
||||
}
|
||||
|
||||
void GLBufferObjectSet::discardAllGLBufferObjects()
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"GLBufferObjectSet::discardAllGLBufferObjects()"<<std::endl;
|
||||
|
||||
GLBufferObject* to = _head;
|
||||
while(to!=0)
|
||||
{
|
||||
ref_ptr<GLBufferObject> glbo = to;
|
||||
|
||||
to = to->_next;
|
||||
|
||||
ref_ptr<BufferObject> 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()"<<std::endl;
|
||||
|
||||
// clean up the pending orphans.
|
||||
handlePendingOrphandedGLBufferObjects();
|
||||
|
||||
osg::notify(osg::NOTICE)<<" _orphanedGLBufferObjects.size() = "<<_orphanedGLBufferObjects.size()<<std::endl;
|
||||
osg::notify(osg::NOTICE)<<" _pendingOrphanedGLBufferObjects.size() = "<<_pendingOrphanedGLBufferObjects.size()<<std::endl;
|
||||
|
||||
|
||||
unsigned int numDiscarded = _orphanedGLBufferObjects.size();
|
||||
|
||||
_numOfGLBufferObjects -= numDiscarded;
|
||||
@@ -832,7 +875,7 @@ void GLBufferObjectSet::addToBack(GLBufferObject* to)
|
||||
|
||||
void GLBufferObjectSet::orphan(GLBufferObject* to)
|
||||
{
|
||||
// osg::notify(osg::NOTICE)<<"GLBufferObjectSet::orphan("<<to<<")"<<std::endl;
|
||||
osg::notify(osg::NOTICE)<<"GLBufferObjectSet::orphan("<<to<<")"<<std::endl;
|
||||
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> 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("<<to<<") _pendingOrphanedGLBufferObjects.size()="<<_pendingOrphanedGLBufferObjects.size()<<std::endl;
|
||||
osg::notify(osg::NOTICE)<<" _orphanedGLBufferObjects.size()="<<_orphanedGLBufferObjects.size()<<std::endl;
|
||||
#endif
|
||||
@@ -969,6 +1012,28 @@ void GLBufferObjectManager::handlePendingOrphandedGLBufferObjects()
|
||||
}
|
||||
}
|
||||
|
||||
void GLBufferObjectManager::deleteAllGLBufferObjects()
|
||||
{
|
||||
ElapsedTime elapsedTime(&(getDeleteTime()));
|
||||
|
||||
for(GLBufferObjectSetMap::iterator itr = _glBufferObjectSetMap.begin();
|
||||
itr != _glBufferObjectSetMap.end();
|
||||
++itr)
|
||||
{
|
||||
(*itr).second->deleteAllGLBufferObjects();
|
||||
}
|
||||
}
|
||||
|
||||
void GLBufferObjectManager::discardAllGLBufferObjects()
|
||||
{
|
||||
for(GLBufferObjectSetMap::iterator itr = _glBufferObjectSetMap.begin();
|
||||
itr != _glBufferObjectSetMap.end();
|
||||
++itr)
|
||||
{
|
||||
(*itr).second->discardAllGLBufferObjects();
|
||||
}
|
||||
}
|
||||
|
||||
void GLBufferObjectManager::flushAllDeletedGLBufferObjects()
|
||||
{
|
||||
ElapsedTime elapsedTime(&(getDeleteTime()));
|
||||
@@ -1056,6 +1121,16 @@ GLBufferObject* GLBufferObject::createGLBufferObject(unsigned int contextID, con
|
||||
return GLBufferObjectManager::getGLBufferObjectManager(contextID)->generateGLBufferObject(bufferObject);
|
||||
}
|
||||
|
||||
void GLBufferObject::deleteAllBufferObjects(unsigned int contextID)
|
||||
{
|
||||
GLBufferObjectManager::getGLBufferObjectManager(contextID)->deleteAllGLBufferObjects();
|
||||
}
|
||||
|
||||
void GLBufferObject::discardAllBufferObjects(unsigned int contextID)
|
||||
{
|
||||
GLBufferObjectManager::getGLBufferObjectManager(contextID)->discardAllGLBufferObjects();
|
||||
}
|
||||
|
||||
void GLBufferObject::flushAllDeletedBufferObjects(unsigned int contextID)
|
||||
{
|
||||
GLBufferObjectManager::getGLBufferObjectManager(contextID)->flushAllDeletedGLBufferObjects();
|
||||
@@ -1118,6 +1193,7 @@ void BufferObject::resizeGLObjectBuffers(unsigned int maxSize)
|
||||
|
||||
void BufferObject::releaseGLObjects(State* state) const
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"BufferObject::releaseGLObjects("<<state<<")"<<std::endl;
|
||||
if (state)
|
||||
{
|
||||
unsigned int contextID = state->getContextID();
|
||||
@@ -1133,6 +1209,7 @@ void BufferObject::releaseGLObjects(State* state) const
|
||||
{
|
||||
if (_glBufferObjects[i].valid())
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<" GLBufferObject::releaseGLBufferObject("<<i<<", _glBufferObjects["<<i<<"]="<<_glBufferObjects[i].get()<<")"<<std::endl;
|
||||
GLBufferObject::releaseGLBufferObject(i, _glBufferObjects[i].get());
|
||||
_glBufferObjects[i] = 0;
|
||||
}
|
||||
|
||||
@@ -55,16 +55,43 @@ void osg::flushAllDeletedGLObjects(unsigned int contextID)
|
||||
osg::VertexProgram::flushDeletedVertexProgramObjects(contextID,currentTime,availableTime);
|
||||
#endif
|
||||
|
||||
osg::GLBufferObject::flushDeletedBufferObjects(contextID,currentTime,availableTime);
|
||||
osg::GLBufferObject::flushAllDeletedBufferObjects(contextID);
|
||||
osg::Texture::flushAllDeletedTextureObjects(contextID);
|
||||
|
||||
osg::FrameBufferObject::flushDeletedFrameBufferObjects(contextID,currentTime,availableTime);
|
||||
osg::Program::flushDeletedGlPrograms(contextID,currentTime,availableTime);
|
||||
osg::RenderBuffer::flushDeletedRenderBuffers(contextID,currentTime,availableTime);
|
||||
osg::Shader::flushDeletedGlShaders(contextID,currentTime,availableTime);
|
||||
osg::Texture::flushAllDeletedTextureObjects(contextID);
|
||||
osg::OcclusionQueryNode::flushDeletedQueryObjects(contextID,currentTime,availableTime);
|
||||
}
|
||||
|
||||
void osg::discardAllDeletedGLObjects(unsigned int contextID)
|
||||
|
||||
void osg::deleteAllGLObjects(unsigned int contextID)
|
||||
{
|
||||
double currentTime = DBL_MAX;
|
||||
double availableTime = DBL_MAX;
|
||||
|
||||
#ifdef OSG_GL_DISPLAYLISTS_AVAILABLE
|
||||
osg::Drawable::flushAllDeletedDisplayLists(contextID);
|
||||
#endif
|
||||
|
||||
#ifdef OSG_GL_FIXED_FUNCTION_AVAILABLE
|
||||
osg::FragmentProgram::flushDeletedFragmentProgramObjects(contextID,currentTime,availableTime);
|
||||
osg::VertexProgram::flushDeletedVertexProgramObjects(contextID,currentTime,availableTime);
|
||||
#endif
|
||||
|
||||
osg::GLBufferObject::deleteAllBufferObjects(contextID);
|
||||
osg::Texture::deleteAllTextureObjects(contextID);
|
||||
|
||||
osg::FrameBufferObject::flushDeletedFrameBufferObjects(contextID,currentTime,availableTime);
|
||||
osg::Program::flushDeletedGlPrograms(contextID,currentTime,availableTime);
|
||||
osg::RenderBuffer::flushDeletedRenderBuffers(contextID,currentTime,availableTime);
|
||||
osg::Shader::flushDeletedGlShaders(contextID,currentTime,availableTime);
|
||||
osg::OcclusionQueryNode::flushDeletedQueryObjects(contextID,currentTime,availableTime);
|
||||
}
|
||||
|
||||
|
||||
void osg::discardAllGLObjects(unsigned int contextID)
|
||||
{
|
||||
#ifdef OSG_GL_DISPLAYLISTS_AVAILABLE
|
||||
osg::Drawable::discardAllDeletedDisplayLists(contextID);
|
||||
@@ -75,11 +102,12 @@ void osg::discardAllDeletedGLObjects(unsigned int contextID)
|
||||
osg::VertexProgram::discardDeletedVertexProgramObjects(contextID);
|
||||
#endif
|
||||
|
||||
osg::GLBufferObject::discardAllDeletedBufferObjects(contextID);
|
||||
osg::GLBufferObject::discardAllBufferObjects(contextID);
|
||||
osg::Texture::discardAllTextureObjects(contextID);
|
||||
|
||||
osg::FrameBufferObject::discardDeletedFrameBufferObjects(contextID);
|
||||
osg::Program::discardDeletedGlPrograms(contextID);
|
||||
osg::RenderBuffer::discardDeletedRenderBuffers(contextID);
|
||||
osg::Shader::discardDeletedGlShaders(contextID);
|
||||
osg::Texture::discardAllDeletedTextureObjects(contextID);
|
||||
osg::OcclusionQueryNode::discardDeletedQueryObjects(contextID);
|
||||
}
|
||||
|
||||
@@ -531,11 +531,11 @@ void GraphicsContext::close(bool callCloseImplementation)
|
||||
if (makeCurrent())
|
||||
{
|
||||
|
||||
osg::notify(osg::INFO)<<"Doing Flush"<<std::endl;
|
||||
osg::notify(osg::INFO)<<"Doing delete of GL objects"<<std::endl;
|
||||
|
||||
osg::flushAllDeletedGLObjects(_state->getContextID());
|
||||
osg::deleteAllGLObjects(_state->getContextID());
|
||||
|
||||
osg::notify(osg::INFO)<<"Done Flush "<<std::endl;
|
||||
osg::notify(osg::INFO)<<"Done delete of GL objects"<<std::endl;
|
||||
|
||||
_state->reset();
|
||||
|
||||
@@ -557,7 +557,7 @@ void GraphicsContext::close(bool callCloseImplementation)
|
||||
{
|
||||
osg::notify(osg::INFO)<<"Doing discard of deleted OpenGL objects."<<std::endl;
|
||||
|
||||
osg::discardAllDeletedGLObjects(_state->getContextID());
|
||||
osg::discardAllGLObjects(_state->getContextID());
|
||||
}
|
||||
|
||||
if (_state.valid())
|
||||
|
||||
@@ -72,6 +72,11 @@ unsigned int Texture::getMinimumNumberOfTextureObjectsToRetainInCache()
|
||||
|
||||
#define USE_NEW_TEXTURE_POOL 1
|
||||
|
||||
Texture::TextureObject::~TextureObject()
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Texture::TextureObject::~TextureObject() "<<this<<std::endl;
|
||||
}
|
||||
|
||||
void Texture::TextureObject::bind()
|
||||
{
|
||||
glBindTexture( _profile._target, _id);
|
||||
@@ -218,7 +223,7 @@ bool Texture::TextureObjectSet::checkConsistency() const
|
||||
|
||||
void Texture::TextureObjectSet::handlePendingOrphandedTextureObjects()
|
||||
{
|
||||
// osg::notify(osg::NOTICE)<<"handlePendingOrphandedTextureObjects()"<<_pendingOrphanedTextureObjects.size()<<std::endl;
|
||||
osg::notify(osg::NOTICE)<<"handlePendingOrphandedTextureObjects()"<<_pendingOrphanedTextureObjects.size()<<std::endl;
|
||||
|
||||
if (_pendingOrphanedTextureObjects.empty()) return;
|
||||
|
||||
@@ -253,8 +258,42 @@ void Texture::TextureObjectSet::handlePendingOrphandedTextureObjects()
|
||||
checkConsistency();
|
||||
}
|
||||
|
||||
|
||||
void Texture::TextureObjectSet::deleteAllTextureObjects()
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Texture::TextureObjectSet::deleteAllTextureObjects() not implemented yet."<<std::endl;
|
||||
}
|
||||
|
||||
void Texture::TextureObjectSet::discardAllTextureObjects()
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Texture::TextureObjectSet::discardAllTextureObjects()."<<std::endl;
|
||||
|
||||
TextureObject* to = _head;
|
||||
while(to!=0)
|
||||
{
|
||||
ref_ptr<TextureObject> glto = to;
|
||||
|
||||
to = to->_next;
|
||||
|
||||
ref_ptr<Texture> 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()"<<std::endl;
|
||||
|
||||
for(TextureObjectList::iterator itr = _orphanedTextureObjects.begin();
|
||||
itr != _orphanedTextureObjects.end();
|
||||
++itr)
|
||||
@@ -280,6 +319,15 @@ void Texture::TextureObjectSet::flushAllDeletedTextureObjects()
|
||||
|
||||
void Texture::TextureObjectSet::discardAllDeletedTextureObjects()
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Texture::TextureObjectSet::discardAllDeletedTextureObjects()"<<std::endl;
|
||||
|
||||
// clean up the pending orphans.
|
||||
handlePendingOrphandedTextureObjects();
|
||||
|
||||
osg::notify(osg::NOTICE)<<" _orphanedTextureObjects.size() = "<<_orphanedTextureObjects.size()<<std::endl;
|
||||
osg::notify(osg::NOTICE)<<" _pendingOrphanedTextureObjects.size() = "<<_pendingOrphanedTextureObjects.size()<<std::endl;
|
||||
|
||||
|
||||
unsigned int numDiscarded = _orphanedTextureObjects.size();
|
||||
|
||||
_numOfTextureObjects -= numDiscarded;
|
||||
@@ -299,7 +347,7 @@ void Texture::TextureObjectSet::discardAllDeletedTextureObjects()
|
||||
|
||||
void Texture::TextureObjectSet::flushDeletedTextureObjects(double currentTime, double& availableTime)
|
||||
{
|
||||
// osg::notify(osg::NOTICE)<<"Texture::TextureObjectSet::flushDeletedTextureObjects(..) Not properly implemented yet"<<std::endl;
|
||||
// osg::notify(osg::NOTICE)<<"Texture::TextureObjectSet::flushDeletedTextureObjects(..)"<<std::endl;
|
||||
|
||||
// if nothing to delete return
|
||||
if (_orphanedTextureObjects.empty()) return;
|
||||
@@ -696,8 +744,36 @@ void Texture::TextureObjectManager::handlePendingOrphandedTextureObjects()
|
||||
}
|
||||
}
|
||||
|
||||
void Texture::TextureObjectManager::deleteAllTextureObjects()
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Texture::TextureObjectManager::deleteAllTextureObjects() _contextID="<<_contextID<<std::endl;
|
||||
|
||||
ElapsedTime elapsedTime(&(getDeleteTime()));
|
||||
|
||||
for(TextureSetMap::iterator itr = _textureSetMap.begin();
|
||||
itr != _textureSetMap.end();
|
||||
++itr)
|
||||
{
|
||||
(*itr).second->deleteAllTextureObjects();
|
||||
}
|
||||
}
|
||||
|
||||
void Texture::TextureObjectManager::discardAllTextureObjects()
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Texture::TextureObjectManager::discardAllTextureObjects() _contextID="<<_contextID<<" _numActiveTextureObjects="<<_numActiveTextureObjects<<std::endl;
|
||||
|
||||
for(TextureSetMap::iterator itr = _textureSetMap.begin();
|
||||
itr != _textureSetMap.end();
|
||||
++itr)
|
||||
{
|
||||
(*itr).second->discardAllTextureObjects();
|
||||
}
|
||||
}
|
||||
|
||||
void Texture::TextureObjectManager::flushAllDeletedTextureObjects()
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Texture::TextureObjectManager::flushAllDeletedTextureObjects() _contextID="<<_contextID<<std::endl;
|
||||
|
||||
ElapsedTime elapsedTime(&(getDeleteTime()));
|
||||
|
||||
for(TextureSetMap::iterator itr = _textureSetMap.begin();
|
||||
@@ -710,6 +786,8 @@ void Texture::TextureObjectManager::flushAllDeletedTextureObjects()
|
||||
|
||||
void Texture::TextureObjectManager::discardAllDeletedTextureObjects()
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Texture::TextureObjectManager::discardAllDeletedTextureObjects() _contextID="<<_contextID<<" _numActiveTextureObjects="<<_numActiveTextureObjects<<std::endl;
|
||||
|
||||
for(TextureSetMap::iterator itr = _textureSetMap.begin();
|
||||
itr != _textureSetMap.end();
|
||||
++itr)
|
||||
@@ -798,6 +876,16 @@ Texture::TextureObject* Texture::generateTextureObject(const Texture* texture, u
|
||||
return getTextureObjectManager(contextID)->generateTextureObject(texture,target,numMipmapLevels,internalFormat,width,height,depth,border);
|
||||
}
|
||||
|
||||
void Texture::deleteAllTextureObjects(unsigned int contextID)
|
||||
{
|
||||
getTextureObjectManager(contextID)->deleteAllTextureObjects();
|
||||
}
|
||||
|
||||
void Texture::discardAllTextureObjects(unsigned int contextID)
|
||||
{
|
||||
getTextureObjectManager(contextID)->discardAllTextureObjects();
|
||||
}
|
||||
|
||||
void Texture::flushAllDeletedTextureObjects(unsigned int contextID)
|
||||
{
|
||||
getTextureObjectManager(contextID)->flushAllDeletedTextureObjects();
|
||||
|
||||
Reference in New Issue
Block a user