Clean up and fixes to GraphicThread class, and osgcamera example.

This commit is contained in:
Robert Osfield
2005-08-30 14:41:08 +00:00
parent 3810d3b850
commit aba3b4fa67
7 changed files with 73 additions and 67 deletions

View File

@@ -113,25 +113,13 @@ void GraphicsContext::decrementContextIDUsageCount(unsigned int contextID)
GraphicsContext::GraphicsContext():
_closeOnDestruction(true),
_threadOfLastMakeCurrent(0)
{
}
GraphicsContext::~GraphicsContext()
{
// switch off the graphics thread...
setGraphicsThread(0);
if (_state.valid())
{
decrementContextIDUsageCount(_state->getContextID());
}
if (_closeOnDestruction)
{
close();
}
close(false);
}
/** Realise the GraphicsContext.*/
@@ -151,18 +139,25 @@ bool GraphicsContext::realize()
}
}
void GraphicsContext::close()
void GraphicsContext::close(bool callCloseImplementation)
{
// switch off the graphics thread...
setGraphicsThread(0);
closeImplementation();
if (callCloseImplementation) closeImplementation();
if (_state.valid())
{
decrementContextIDUsageCount(_state->getContextID());
_state = 0;
}
}
void GraphicsContext::makeCurrent()
{
osg::notify(osg::NOTICE)<<"Doing GraphicsContext::makeCurrent"<<(unsigned int)OpenThreads::Thread::CurrentThread()<<std::endl;
osg::notify(osg::INFO)<<"Doing GraphicsContext::makeCurrent"<<(unsigned int)OpenThreads::Thread::CurrentThread()<<std::endl;
ReleaseContext_Block_MakeCurrentOperation* rcbmco = 0;
@@ -177,7 +172,7 @@ void GraphicsContext::makeCurrent()
if (!isCurrent()) _mutex.lock();
osg::notify(osg::NOTICE)<<"Calling GraphicsContext::makeCurrentImplementation"<<(unsigned int)OpenThreads::Thread::CurrentThread()<<std::endl;
osg::notify(osg::INFO)<<"Calling GraphicsContext::makeCurrentImplementation"<<(unsigned int)OpenThreads::Thread::CurrentThread()<<std::endl;
makeCurrentImplementation();
@@ -190,7 +185,7 @@ void GraphicsContext::makeCurrent()
rcbmco->release();
}
osg::notify(osg::NOTICE)<<"Done GraphicsContext::makeCurrentImplementation"<<(unsigned int)OpenThreads::Thread::CurrentThread()<<std::endl;
osg::notify(osg::INFO)<<"Done GraphicsContext::makeCurrentImplementation"<<(unsigned int)OpenThreads::Thread::CurrentThread()<<std::endl;
}
void GraphicsContext::makeContextCurrent(GraphicsContext* readContext)
@@ -211,18 +206,18 @@ void GraphicsContext::swapBuffers()
{
if (isCurrent())
{
osg::notify(osg::NOTICE)<<"Doing GraphicsContext::swapBuffers() call to swapBuffersImplementation() "<<(unsigned int)OpenThreads::Thread::CurrentThread()<<std::endl;
osg::notify(osg::INFO)<<"Doing GraphicsContext::swapBuffers() call to swapBuffersImplementation() "<<(unsigned int)OpenThreads::Thread::CurrentThread()<<std::endl;
swapBuffersImplementation();
}
else if (_graphicsThread.valid() &&
_threadOfLastMakeCurrent == _graphicsThread.get())
{
osg::notify(osg::NOTICE)<<"Doing GraphicsContext::swapBuffers() registering SwapBuffersOperation"<<(unsigned int)OpenThreads::Thread::CurrentThread()<<std::endl;
osg::notify(osg::INFO)<<"Doing GraphicsContext::swapBuffers() registering SwapBuffersOperation"<<(unsigned int)OpenThreads::Thread::CurrentThread()<<std::endl;
_graphicsThread->add(new SwapBuffersOperation);
}
else
{
osg::notify(osg::NOTICE)<<"Doing GraphicsContext::swapBuffers() makeCurrent;swapBuffersImplementation;releaseContext"<<(unsigned int)OpenThreads::Thread::CurrentThread()<<std::endl;
osg::notify(osg::INFO)<<"Doing GraphicsContext::swapBuffers() makeCurrent;swapBuffersImplementation;releaseContext"<<(unsigned int)OpenThreads::Thread::CurrentThread()<<std::endl;
makeCurrent();
swapBuffersImplementation();
releaseContext();
@@ -256,7 +251,7 @@ void GraphicsContext::setGraphicsThread(GraphicsThread* gt)
{
_graphicsThread->_graphicsContext = this;
if (!_graphicsThread->isRunning() && isRealized())
if (!_graphicsThread->isRunning())
{
_graphicsThread->startThread();
}

View File

@@ -25,7 +25,6 @@ struct BlockOperation : public GraphicsThread::Operation, public Block
virtual void operator () (GraphicsContext*)
{
//osg::notify(osg::NOTICE)<<"BlockOperation doing release"<<(unsigned int)this<<std::endl;
glFlush();
release();
}
@@ -41,14 +40,14 @@ GraphicsThread::GraphicsThread():
GraphicsThread::~GraphicsThread()
{
osg::notify(osg::NOTICE)<<"Destructing graphics thread"<<std::endl;
osg::notify(osg::INFO)<<"Destructing graphics thread"<<std::endl;
cancel();
}
int GraphicsThread::cancel()
{
osg::notify(osg::NOTICE)<<"Cancelling graphics thread"<<std::endl;
osg::notify(osg::INFO)<<"Cancelling graphics thread"<<std::endl;
int result = 0;
if( isRunning() )
@@ -68,7 +67,7 @@ int GraphicsThread::cancel()
{
// commenting out debug info as it was cashing crash on exit, presumable
// due to osg::notify or std::cout destructing earlier than this destructor.
osg::notify(osg::NOTICE)<<"Waiting for GraphicsThread to cancel"<<std::endl;
osg::notify(osg::INFO)<<"Waiting for GraphicsThread to cancel"<<std::endl;
OpenThreads::Thread::YieldCurrentThread();
}
}
@@ -78,7 +77,7 @@ int GraphicsThread::cancel()
void GraphicsThread::add(Operation* operation, bool waitForCompletion)
{
osg::notify(osg::NOTICE)<<"Doing add"<<std::endl;
osg::notify(osg::INFO)<<"Doing add"<<std::endl;
BlockOperation* block = 0;
@@ -110,11 +109,16 @@ void GraphicsThread::run()
// make the graphics context current.
if (_graphicsContext)
{
osg::notify(osg::NOTICE)<<"Doing make current"<<std::endl;
if (!_graphicsContext->isRealized())
{
_graphicsContext->realize();
}
osg::notify(osg::INFO)<<"Doing make current"<<std::endl;
_graphicsContext->makeCurrent();
}
osg::notify(osg::NOTICE)<<"Doing run"<<std::endl;
osg::notify(osg::INFO)<<"Doing run"<<std::endl;
bool firstTime = true;

View File

@@ -161,6 +161,7 @@ GraphicsContextImplementation::GraphicsContextImplementation(Producer::RenderSur
GraphicsContextImplementation::~GraphicsContextImplementation()
{
if (_closeOnDestruction) close();
}
bool GraphicsContextImplementation::realizeImplementation()
@@ -187,13 +188,24 @@ bool GraphicsContextImplementation::realizeImplementation()
void GraphicsContextImplementation::makeCurrentImplementation()
{
if (!_rs) return;
if (!_rs)
{
osg::notify(osg::NOTICE)<<"Error: GraphicsContextImplementation::makeCurrentImplementation() no RenderSurface."<<std::endl;
return;
}
osg::notify(osg::NOTICE)<<"GraphicsContextImplementation::makeCurrentImplementation()"<<std::endl;
if (!isRealized())
{
osg::notify(osg::NOTICE)<<"Error: GraphicsContextImplementation::makeCurrentImplementation() not Realized."<<std::endl;
return;
}
osg::notify(osg::INFO)<<"GraphicsContextImplementation::makeCurrentImplementation()"<<std::endl;
_rs->setReadDrawable( 0 );
_rs->makeCurrent();
// comment out right now, as Producer's setReadDrawable() is doing a call for us.
// _rs->makeCurrent();
}
void GraphicsContextImplementation::makeContextCurrentImplementation(GraphicsContext* readContext)
@@ -206,8 +218,13 @@ void GraphicsContextImplementation::makeContextCurrentImplementation(GraphicsCon
{
_rs->setReadDrawable( readContextImplemention->getRenderSurface() );
}
else
{
_rs->setReadDrawable( 0 );
}
_rs->makeCurrent();
// comment out right now, as Producer's setReadDrawable() is doing a call for us.
// _rs->makeCurrent();
}
void GraphicsContextImplementation::closeImplementation()

View File

@@ -1332,9 +1332,11 @@ void CullVisitor::apply(osg::CameraNode& camera)
rtts->setGraphicsContext(context.get());
// context->createGraphicsThread();
#if 0
context->createGraphicsThread();
#else
context->realize();
#endif
}
}