Added GraphicsContext::ResizedCallback and GraphicsContext::resizedImplementation.

Added message on non implementation of GraphicsContext::valid().
Added prelimary GraphicsContext clean up support.
This commit is contained in:
Robert Osfield
2007-01-08 16:20:10 +00:00
parent a3726fba66
commit 4a5eda6522
8 changed files with 143 additions and 10 deletions

View File

@@ -16,6 +16,12 @@
#include <osg/Camera>
#include <osg/View>
#include <osg/FrameBufferObject>
#include <osg/Program>
#include <osg/Drawable>
#include <osg/FragmentProgram>
#include <osg/VertexProgram>
#include <osg/Notify>
#include <map>
@@ -165,9 +171,71 @@ bool GraphicsContext::realize()
void GraphicsContext::close(bool callCloseImplementation)
{
osg::notify(osg::NOTICE)<<"close("<<callCloseImplementation<<")"<<this<<std::endl;
// switch off the graphics thread...
setGraphicsThread(0);
if (callCloseImplementation && _state.valid() && isRealized())
{
bool sharedContextExists = false;
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_contextIDMapMutex);
if (s_contextIDMap[_state->getContextID()]>1) sharedContextExists = true;
}
osg::notify(osg::NOTICE)<<"Closing still viable window "<<sharedContextExists<<" _state->getContextID()="<<_state->getContextID()<<std::endl;
#if 1
// release all the OpenGL objects in the scene graphs associted with this
for(Cameras::iterator itr = _cameras.begin();
itr != _cameras.end();
++itr)
{
Camera* camera = (*itr);
if (camera)
{
osg::notify(osg::NOTICE)<<"Releasing GL objects for Camera "<<camera<<std::endl;
#if 1
camera->releaseGLObjects(_state.get());
#else
camera->releaseGLObjects(0);
#endif
}
}
#endif
#if 1
osg::notify(osg::NOTICE)<<"Doing makeCurrent "<<std::endl;
makeCurrent();
osg::notify(osg::NOTICE)<<"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::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::NOTICE)<<"Done Flush "<<availableTime<<std::endl;
#endif
_state->reset();
releaseContext();
}
if (callCloseImplementation) closeImplementation();
if (_state.valid())
@@ -218,6 +286,7 @@ void GraphicsContext::makeContextCurrent(GraphicsContext* readContext)
void GraphicsContext::releaseContext()
{
_mutex.unlock();
_threadOfLastMakeCurrent = reinterpret_cast<OpenThreads::Thread*>(0xffff);
}
void GraphicsContext::swapBuffers()
@@ -392,7 +461,7 @@ void GraphicsContext::removeCamera(osg::Camera* camera)
}
}
void GraphicsContext::resized(int x, int y, int width, int height)
void GraphicsContext::resizedImplementation(int x, int y, int width, int height)
{
if (!_traits) return;

View File

@@ -218,11 +218,13 @@ void TextureObjectManager::flushAllTextureObjects(unsigned int contextID)
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
Texture::TextureObjectList& tol = _textureObjectListMap[contextID];
osg::notify(osg::NOTICE)<<"Flushing texture objects num="<<tol.size()<<" contextID="<<contextID<<std::endl;
for(Texture::TextureObjectList::iterator itr=tol.begin();
itr!=tol.end();
++itr)
{
osg::notify(osg::NOTICE)<<" deleting texture object "<<(*itr)->_id<<std::endl;
glDeleteTextures( 1L, &((*itr)->_id));
}
tol.clear();
@@ -1302,6 +1304,9 @@ void Texture::resizeGLObjectBuffers(unsigned int maxSize)
void Texture::releaseGLObjects(State* state) const
{
if (state) osg::notify(osg::NOTICE)<<"Texture::releaseGLObjects contextID="<<state->getContextID()<<std::endl;
else osg::notify(osg::NOTICE)<<"Texture::releaseGLObjects no State "<<std::endl;
if (!state) const_cast<Texture*>(this)->dirtyTextureObject();
else
{

View File

@@ -26,8 +26,14 @@ View::View()
View::~View()
{
// osg::notify(osg::NOTICE)<<"Destructing osg::View"<<std::endl;
osg::notify(osg::NOTICE)<<"Destructing osg::View"<<std::endl;
if (_camera.valid())
{
_camera->setView(0);
_camera->setCullCallback(0);
}
// detatch the cameras from this View to prevent dangling pointers
for(Slaves::iterator itr = _slaves.begin();
itr != _slaves.end();
@@ -38,7 +44,7 @@ View::~View()
cd._camera->setCullCallback(0);
}
// osg::notify(osg::NOTICE)<<"Done destructing osg::View"<<std::endl;
osg::notify(osg::NOTICE)<<"Done destructing osg::View"<<std::endl;
}

View File

@@ -44,7 +44,19 @@ Viewer::~Viewer()
_scene->setDatabasePager(0);
}
Contexts contexts;
getContexts(contexts);
// clear out all the previously assigned operations
for(Contexts::iterator citr = contexts.begin();
citr != contexts.end();
++citr)
{
(*citr)->close();
}
//osg::notify(osg::NOTICE)<<"finish Viewer::~Viewer()"<<std::endl;
}
bool Viewer::isRealized() const
@@ -858,6 +870,7 @@ void Viewer::renderingTraversals()
{
(*itr)->makeCurrent();
(*itr)->runOperations();
(*itr)->releaseContext();
}
}
@@ -876,6 +889,7 @@ void Viewer::renderingTraversals()
{
(*itr)->makeCurrent();
(*itr)->swapBuffers();
(*itr)->releaseContext();
}
}