Introduced new osg::discardDeletedOpenGLObjects() methods, and usage of it in

GrpahicsContext::close() to handle cases where deletingOpenGLObjects is no possible,
such as when GraphicsWindowEmbedded is used.
This commit is contained in:
Robert Osfield
2008-01-08 13:24:29 +00:00
parent f3448d3307
commit ff565128af
27 changed files with 216 additions and 29 deletions

View File

@@ -48,8 +48,6 @@ void BufferObject::deleteBufferObject(unsigned int contextID,GLuint globj)
}
}
/** flush all the cached display list which need to be deleted
* in the OpenGL context related to contextID.*/
void BufferObject::flushDeletedBufferObjects(unsigned int contextID,double /*currentTime*/, double& availableTime)
{
// if no time available don't try to flush objects.
@@ -86,6 +84,13 @@ void BufferObject::flushDeletedBufferObjects(unsigned int contextID,double /*cur
availableTime -= elapsedTime;
}
void BufferObject::discardDeletedBufferObjects(unsigned int contextID)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_mutex_deletedBufferObjectCache);
DisplayListMap& dll = s_deletedBufferObjectCache[contextID];
dll.clear();
}
BufferObject::BufferObject():
_target(0),

View File

@@ -116,6 +116,14 @@ void Drawable::flushAllDeletedDisplayLists(unsigned int contextID)
dll.clear();
}
void Drawable::discardAllDeletedDisplayLists(unsigned int contextID)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_mutex_deletedDisplayListCache);
DisplayListMap& dll = s_deletedDisplayListCache[contextID];
dll.clear();
}
void Drawable::flushDeletedDisplayLists(unsigned int contextID, double& availableTime)
{
// if no time available don't try to flush objects.
@@ -206,8 +214,6 @@ void Drawable::deleteVertexBufferObject(unsigned int contextID,GLuint globj)
}
}
/** flush all the cached display lists which need to be deleted
* in the OpenGL context related to contextID.*/
void Drawable::flushDeletedVertexBufferObjects(unsigned int contextID,double /*currentTime*/, double& availableTime)
{
// if no time available don't try to flush objects.
@@ -244,6 +250,13 @@ void Drawable::flushDeletedVertexBufferObjects(unsigned int contextID,double /*c
availableTime -= elapsedTime;
}
void Drawable::discardDeletedVertexBufferObjects(unsigned int contextID)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_mutex_deletedVertexBufferObjectCache);
DisplayListMap& dll = s_deletedVertexBufferObjectCache[contextID];
dll.clear();
}
Drawable::Drawable()
:Object(true)

View File

@@ -73,6 +73,13 @@ void FragmentProgram::flushDeletedFragmentProgramObjects(unsigned int contextID,
availableTime -= elapsedTime;
}
void FragmentProgram::discardDeletedFragmentProgramObjects(unsigned int contextID)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_mutex_deletedFragmentProgramObjectCache);
FragmentProgramObjectList& vpol = s_deletedFragmentProgramObjectCache[contextID];
vpol.clear();
}
FragmentProgram::FragmentProgram()
{

View File

@@ -132,6 +132,13 @@ void RenderBuffer::flushDeletedRenderBuffers(unsigned int contextID,double /*cur
availableTime -= elapsedTime;
}
void RenderBuffer::discardDeletedRenderBuffers(unsigned int contextID)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_mutex_deletedRenderBufferCache);
RenderBufferHandleList& pList = s_deletedRenderBufferCache[contextID];
pList.clear();
}
RenderBuffer::RenderBuffer()
: Object(),
@@ -532,6 +539,14 @@ void FrameBufferObject::flushDeletedFrameBufferObjects(unsigned int contextID,do
availableTime -= elapsedTime;
}
void FrameBufferObject::discardDeletedFrameBufferObjects(unsigned int contextID)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_mutex_deletedFrameBufferObjectCache);
FrameBufferObjectHandleList& pList = s_deletedFrameBufferObjectCache[contextID];
pList.clear();
}
FrameBufferObject::FrameBufferObject()

View File

@@ -22,31 +22,44 @@
void osg::flushDeletedGLObjects(unsigned int contextID, double currentTime, double& availableTime)
{
osg::FrameBufferObject::flushDeletedFrameBufferObjects(contextID,currentTime,availableTime);
osg::RenderBuffer::flushDeletedRenderBuffers(contextID,currentTime,availableTime);
osg::Texture::flushDeletedTextureObjects(contextID,currentTime,availableTime);
osg::BufferObject::flushDeletedBufferObjects(contextID,currentTime,availableTime);
osg::Drawable::flushDeletedDisplayLists(contextID,availableTime);
osg::Drawable::flushDeletedVertexBufferObjects(contextID,currentTime,availableTime);
osg::VertexProgram::flushDeletedVertexProgramObjects(contextID,currentTime,availableTime);
osg::FragmentProgram::flushDeletedFragmentProgramObjects(contextID,currentTime,availableTime);
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::BufferObject::flushDeletedBufferObjects(contextID,currentTime,availableTime);
osg::Texture::flushDeletedTextureObjects(contextID,currentTime,availableTime);
osg::VertexProgram::flushDeletedVertexProgramObjects(contextID,currentTime,availableTime);
}
void osg::flushAllDeletedGLObjects(unsigned int contextID)
{
double currentTime = DBL_MAX;
double availableTime = DBL_MAX;
osg::FrameBufferObject::flushDeletedFrameBufferObjects(contextID,currentTime,availableTime);
osg::RenderBuffer::flushDeletedRenderBuffers(contextID,currentTime,availableTime);
osg::Texture::flushAllDeletedTextureObjects(contextID);
osg::BufferObject::flushDeletedBufferObjects(contextID,currentTime,availableTime);
osg::Drawable::flushAllDeletedDisplayLists(contextID);
osg::Drawable::flushDeletedVertexBufferObjects(contextID,currentTime,availableTime);
osg::VertexProgram::flushDeletedVertexProgramObjects(contextID,currentTime,availableTime);
osg::FragmentProgram::flushDeletedFragmentProgramObjects(contextID,currentTime,availableTime);
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::BufferObject::flushDeletedBufferObjects(contextID,currentTime,availableTime);
osg::Texture::flushAllDeletedTextureObjects(contextID);
osg::VertexProgram::flushDeletedVertexProgramObjects(contextID,currentTime,availableTime);
}
void osg::discardAllDeletedGLObjects(unsigned int contextID)
{
osg::BufferObject::discardDeletedBufferObjects(contextID);
osg::Drawable::discardAllDeletedDisplayLists(contextID);
osg::Drawable::discardDeletedVertexBufferObjects(contextID);
osg::FragmentProgram::discardDeletedFragmentProgramObjects(contextID);
osg::FrameBufferObject::discardDeletedFrameBufferObjects(contextID);
osg::Program::discardDeletedGlPrograms(contextID);
osg::RenderBuffer::discardDeletedRenderBuffers(contextID);
osg::Shader::discardDeletedGlShaders(contextID);
osg::Texture::discardAllDeletedTextureObjects(contextID);
osg::VertexProgram::discardDeletedVertexProgramObjects(contextID);
}

View File

@@ -16,6 +16,7 @@
#include <osg/GraphicsContext>
#include <osg/Camera>
#include <osg/View>
#include <osg/GLObjects>
#include <osg/FrameBufferObject>
#include <osg/Program>
@@ -464,21 +465,9 @@ void GraphicsContext::close(bool callCloseImplementation)
osg::notify(osg::INFO)<<"Doing Flush"<<std::endl;
// flush all the OpenGL object buffer for this context.
double availableTime = 100.0f;
double currentTime = _state->getFrameStamp()?_state->getFrameStamp()->getReferenceTime():0.0;
osg::flushAllDeletedGLObjects(_state->getContextID());
osg::FrameBufferObject::flushDeletedFrameBufferObjects(_state->getContextID(),currentTime,availableTime);
osg::RenderBuffer::flushDeletedRenderBuffers(_state->getContextID(),currentTime,availableTime);
osg::Texture::flushAllDeletedTextureObjects(_state->getContextID());
osg::Drawable::flushAllDeletedDisplayLists(_state->getContextID());
osg::Drawable::flushDeletedVertexBufferObjects(_state->getContextID(),currentTime,availableTime);
osg::VertexProgram::flushDeletedVertexProgramObjects(_state->getContextID(),currentTime,availableTime);
osg::FragmentProgram::flushDeletedFragmentProgramObjects(_state->getContextID(),currentTime,availableTime);
osg::Program::flushDeletedGlPrograms(_state->getContextID(),currentTime,availableTime);
osg::Shader::flushDeletedGlShaders(_state->getContextID(),currentTime,availableTime);
osg::notify(osg::INFO)<<"Done Flush "<<availableTime<<std::endl;
osg::notify(osg::INFO)<<"Done Flush "<<std::endl;
_state->reset();
@@ -486,12 +475,23 @@ void GraphicsContext::close(bool callCloseImplementation)
}
else
{
osg::notify(osg::INFO)<<"makeCurrent did not succedd, could not do flush/deletion of OpenGL objects."<<std::endl;
osg::notify(osg::INFO)<<"makeCurrent did not succeed, could not do flush/deletion of OpenGL objects."<<std::endl;
}
}
if (callCloseImplementation) closeImplementation();
// now discard any deleted deleted OpenGL objects that the are still hanging around - such as due to
// the the flushDelete*() methods not being invoked, such as when using GraphicContextEmbedded where makeCurrent
// does not work.
if (_state.valid())
{
osg::notify(osg::INFO)<<"Doing discard of deleted OpenGL objects."<<std::endl;
osg::discardAllDeletedGLObjects(_state->getContextID());
}
if (_state.valid())
{
decrementContextIDUsageCount(_state->getContextID());

View File

@@ -1977,6 +1977,13 @@ void Program::flushDeletedGlPrograms(unsigned int contextID,double /*currentTime
availableTime -= elapsedTime;
}
void Program::discardDeletedGlPrograms(unsigned int contextID)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_mutex_deletedGlProgramCache);
GlProgramHandleList& pList = s_deletedGlProgramCache[contextID];
pList.clear();
}
///////////////////////////////////////////////////////////////////////////
// osg::Program

View File

@@ -83,6 +83,13 @@ void Shader::flushDeletedGlShaders(unsigned int contextID,double /*currentTime*/
availableTime -= elapsedTime;
}
void Shader::discardDeletedGlShaders(unsigned int contextID)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_mutex_deletedGlShaderCache);
GlShaderHandleList& pList = s_deletedGlShaderCache[contextID];
pList.clear();
}
///////////////////////////////////////////////////////////////////////////
// osg::Shader

View File

@@ -101,6 +101,8 @@ public:
void flushAllTextureObjects(unsigned int contextID);
void discardAllTextureObjects(unsigned int contextID);
void flushTextureObjects(unsigned int contextID,double currentTime, double& availableTime);
void setExpiryDelay(double expiryDelay) { _expiryDelay = expiryDelay; }
@@ -238,6 +240,14 @@ void TextureObjectManager::flushAllTextureObjects(unsigned int contextID)
tol.clear();
}
void TextureObjectManager::discardAllTextureObjects(unsigned int contextID)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
Texture::TextureObjectList& tol = _textureObjectListMap[contextID];
tol.clear();
}
void TextureObjectManager::flushTextureObjects(unsigned int contextID,double currentTime, double& availableTime)
{
// if no time available don't try to flush objects.
@@ -334,6 +344,11 @@ void Texture::flushAllDeletedTextureObjects(unsigned int contextID)
if (getTextureObjectManager()) getTextureObjectManager()->flushAllTextureObjects(contextID);
}
void Texture::discardAllDeletedTextureObjects(unsigned int contextID)
{
if (getTextureObjectManager()) getTextureObjectManager()->discardAllTextureObjects(contextID);
}
void Texture::flushDeletedTextureObjects(unsigned int contextID,double currentTime, double& availbleTime)
{
if (getTextureObjectManager()) getTextureObjectManager()->flushTextureObjects(contextID, currentTime, availbleTime);

View File

@@ -73,6 +73,13 @@ void VertexProgram::flushDeletedVertexProgramObjects(unsigned int contextID,doub
availableTime -= elapsedTime;
}
void VertexProgram::discardDeletedVertexProgramObjects(unsigned int contextID)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_mutex_deletedVertexProgramObjectCache);
VertexProgramObjectList& vpol = s_deletedVertexProgramObjectCache[contextID];
vpol.clear();
}
VertexProgram::VertexProgram()
{

View File

@@ -119,6 +119,10 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::BufferObject)
__void__flushDeletedBufferObjects__unsigned_int__double__double_R1_S,
"flush all the cached display list which need to be deleted in the OpenGL context related to contextID. ",
"");
I_StaticMethod1(void, discardDeletedBufferObjects, IN, unsigned int, contextID,
__void__discardDeletedBufferObjects__unsigned_int_S,
"dicard all the cached display list which need to be deleted in the OpenGL context related to contextID. ",
"Note, unlike flush no OpenGL calls are made, instead the handles are all removed. this call is useful for when an OpenGL context has been destroyed. ");
I_StaticMethod2(osg::BufferObject::Extensions *, getExtensions, IN, unsigned int, contextID, IN, bool, createIfNotInitalized,
__Extensions_P1__getExtensions__unsigned_int__bool_S,
"Function to call to get the extension of a specified context. ",

View File

@@ -408,6 +408,10 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::Drawable)
__void__flushAllDeletedDisplayLists__unsigned_int_S,
"Flush all the cached display list which need to be deleted in the OpenGL context related to contextID. ",
"");
I_StaticMethod1(void, discardAllDeletedDisplayLists, IN, unsigned int, contextID,
__void__discardAllDeletedDisplayLists__unsigned_int_S,
"Flush all the cached display list which need to be deleted in the OpenGL context related to contextID. ",
"Note, unlike flush no OpenGL calls are made, instead the handles are all removed. this call is useful for when an OpenGL context has been destroyed. ");
I_StaticMethod2(void, flushDeletedDisplayLists, IN, unsigned int, contextID, IN, double &, availableTime,
__void__flushDeletedDisplayLists__unsigned_int__double_R1_S,
"Flush the cached display list which need to be deleted in the OpenGL context related to contextID. ",
@@ -420,6 +424,10 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::Drawable)
__void__flushDeletedVertexBufferObjects__unsigned_int__double__double_R1_S,
"Flush all the cached vertex buffer objects which need to be deleted in the OpenGL context related to contextID. ",
"");
I_StaticMethod1(void, discardDeletedVertexBufferObjects, IN, unsigned int, contextID,
__void__discardDeletedVertexBufferObjects__unsigned_int_S,
"Flush all the cached vertex buffer objects which need to be deleted in the OpenGL context related to contextID. ",
"Note, unlike flush no OpenGL calls are made, instead the handles are all removed. this call is useful for when an OpenGL context has been destroyed. ");
I_StaticMethod2(osg::Drawable::Extensions *, getExtensions, IN, unsigned int, contextID, IN, bool, createIfNotInitalized,
__Extensions_P1__getExtensions__unsigned_int__bool_S,
"Function to call to get the extension of a specified context. ",

View File

@@ -173,6 +173,10 @@ BEGIN_OBJECT_REFLECTOR(osg::FragmentProgram)
__void__flushDeletedFragmentProgramObjects__unsigned_int__double__double_R1_S,
"flush all the cached fragment programs which need to be deleted in the OpenGL context related to contextID. ",
"");
I_StaticMethod1(void, discardDeletedFragmentProgramObjects, IN, unsigned int, contextID,
__void__discardDeletedFragmentProgramObjects__unsigned_int_S,
"discard all the cached fragment programs which need to be deleted in the OpenGL context related to contextID. ",
"Note, unlike flush no OpenGL calls are made, instead the handles are all removed. this call is useful for when an OpenGL context has been destroyed. ");
I_StaticMethod2(osg::FragmentProgram::Extensions *, getExtensions, IN, unsigned int, contextID, IN, bool, createIfNotInitalized,
__Extensions_P1__getExtensions__unsigned_int__bool_S,
"Function to call to get the extension of a specified context. ",

View File

@@ -237,6 +237,10 @@ BEGIN_OBJECT_REFLECTOR(osg::FrameBufferObject)
__void__flushDeletedFrameBufferObjects__unsigned_int__double__double_R1_S,
"flush all the cached FBOs which need to be deleted in the OpenGL context related to contextID. ",
"");
I_StaticMethod1(void, discardDeletedFrameBufferObjects, IN, unsigned int, contextID,
__void__discardDeletedFrameBufferObjects__unsigned_int_S,
"discard all the cached FBOs which need to be deleted in the OpenGL context related to contextID. ",
"");
I_ProtectedMethod0(void, dirtyAll,
Properties::NON_VIRTUAL,
Properties::NON_CONST,
@@ -347,6 +351,10 @@ BEGIN_OBJECT_REFLECTOR(osg::RenderBuffer)
__void__flushDeletedRenderBuffers__unsigned_int__double__double_R1_S,
"flush all the cached RenderBuffers which need to be deleted in the OpenGL context related to contextID. ",
"");
I_StaticMethod1(void, discardDeletedRenderBuffers, IN, unsigned int, contextID,
__void__discardDeletedRenderBuffers__unsigned_int_S,
"discard all the cached RenderBuffers which need to be deleted in the OpenGL context related to contextID. ",
"Note, unlike flush no OpenGL calls are made, instead the handles are all removed. this call is useful for when an OpenGL context has been destroyed. ");
I_ProtectedMethod0(void, dirtyAll,
Properties::NON_VIRTUAL,
Properties::CONST,

View File

@@ -195,6 +195,10 @@ BEGIN_OBJECT_REFLECTOR(osg::Program)
__void__flushDeletedGlPrograms__unsigned_int__double__double_R1_S,
"flush all the cached glPrograms which need to be deleted in the OpenGL context related to contextID. ",
"");
I_StaticMethod1(void, discardDeletedGlPrograms, IN, unsigned int, contextID,
__void__discardDeletedGlPrograms__unsigned_int_S,
"discard all the cached glPrograms which need to be deleted in the OpenGL context related to contextID. ",
"Note, unlike flush no OpenGL calls are made, instead the handles are all removed. this call is useful for when an OpenGL context has been destroyed. ");
I_SimpleProperty(const osg::Program::AttribBindingList &, AttribBindingList,
__C5_AttribBindingList_R1__getAttribBindingList,
0);

View File

@@ -153,6 +153,10 @@ BEGIN_OBJECT_REFLECTOR(osg::Shader)
__void__flushDeletedGlShaders__unsigned_int__double__double_R1_S,
"flush all the cached glShaders which need to be deleted in the OpenGL context related to contextID. ",
"");
I_StaticMethod1(void, discardDeletedGlShaders, IN, unsigned int, contextID,
__void__discardDeletedGlShaders__unsigned_int_S,
"discard all the cached glShaders which need to be deleted in the OpenGL context related to contextID. ",
"Note, unlike flush no OpenGL calls are made, instead the handles are all removed. this call is useful for when an OpenGL context has been destroyed. ");
I_StaticMethod1(osg::Shader::Type, getTypeId, IN, const std::string &, tname,
__Shader_Type__getTypeId__C5_std_string_R1_S,
"",

View File

@@ -475,6 +475,10 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::Texture)
__void__flushAllDeletedTextureObjects__unsigned_int_S,
"",
"");
I_StaticMethod1(void, discardAllDeletedTextureObjects, IN, unsigned int, contextID,
__void__discardAllDeletedTextureObjects__unsigned_int_S,
"",
"");
I_StaticMethod3(void, flushDeletedTextureObjects, IN, unsigned int, contextID, IN, double, currentTime, IN, double &, availableTime,
__void__flushDeletedTextureObjects__unsigned_int__double__double_R1_S,
"",

View File

@@ -173,6 +173,10 @@ BEGIN_OBJECT_REFLECTOR(osg::VertexProgram)
__void__flushDeletedVertexProgramObjects__unsigned_int__double__double_R1_S,
"Flush all the cached vertex programs which need to be deleted in the OpenGL context related to contextID. ",
"");
I_StaticMethod1(void, discardDeletedVertexProgramObjects, IN, unsigned int, contextID,
__void__discardDeletedVertexProgramObjects__unsigned_int_S,
"discard all the cached vertex programs which need to be deleted in the OpenGL context related to contextID. ",
"Note, unlike flush no OpenGL calls are made, instead the handles are all removed. this call is useful for when an OpenGL context has been destroyed. ");
I_StaticMethod2(osg::VertexProgram::Extensions *, getExtensions, IN, unsigned int, contextID, IN, bool, createIfNotInitalized,
__Extensions_P1__getExtensions__unsigned_int__bool_S,
"Function to call to get the extension of a specified context. ",