Various updates to support the new GraphicsThread class.

This commit is contained in:
Robert Osfield
2005-08-18 20:17:51 +00:00
parent 717a6dcf14
commit 51faa7e43a
9 changed files with 82 additions and 100 deletions

View File

@@ -45,6 +45,7 @@ CXXFILES =\
Geometry.cpp\
GLExtensions.cpp\
GraphicsContext.cpp\
GraphicsThread.cpp\
Group.cpp\
Image.cpp\
ImageStream.cpp\

View File

@@ -125,3 +125,43 @@ GraphicsContext::~GraphicsContext()
}
}
void GraphicsContext::makeCurrent()
{
ReleaseContext_Block_MakeCurrentOperation* rcbmco = 0;
if (_graphicsThread.valid() &&
_threadOfLastMakeCurrent == _graphicsThread.get())
{
// create a relase contex, block and make current operation to stop the graphics thread while we use the graphics context for ourselves
rcbmco = new ReleaseContext_Block_MakeCurrentOperation;
_graphicsThread->add(rcbmco);
}
if (!isCurrent()) _mutex.lock();
makeCurrentImplementation();
_threadOfLastMakeCurrent = OpenThreads::Thread::CurrentThread();
if (rcbmco)
{
// Let the "relase contex, block and make current operation" proceed, which will now move on to trying to aquire the graphics
// contex itself with a makeCurrent(), this will then block on the GraphicsContext mutex till releaseContext() releases it.
rcbmco->release();
}
}
void GraphicsContext::makeContextCurrent(GraphicsContext* readContext)
{
if (!isCurrent()) _mutex.lock();
makeContextCurrentImplementation(readContext);
_threadOfLastMakeCurrent = OpenThreads::Thread::CurrentThread();
}
void GraphicsContext::releaseContext()
{
_mutex.unlock();
}

View File

@@ -37,8 +37,8 @@ DatabasePager::DatabasePager()
_useFrameBlock = false;
_numFramesActive = 0;
_frameNumber = 0;
_frameBlock = new Block;
_databasePagerThreadBlock = new Block;
_frameBlock = new osg::Block;
_databasePagerThreadBlock = new osg::Block;
_threadPriorityDuringFrame = THREAD_PRIORITY_MIN;
_threadPriorityOutwithFrame = THREAD_PRIORITY_MIN;

View File

@@ -159,7 +159,7 @@ GraphicsContextImplementation::GraphicsContextImplementation(Producer::RenderSur
GraphicsContextImplementation::~GraphicsContextImplementation()
{
release();
close();
}
bool GraphicsContextImplementation::realize()
@@ -184,7 +184,7 @@ bool GraphicsContextImplementation::realize()
}
}
void GraphicsContextImplementation::makeCurrent()
void GraphicsContextImplementation::makeCurrentImplementation()
{
if (!_rs) return;
@@ -193,7 +193,7 @@ void GraphicsContextImplementation::makeCurrent()
_rs->makeCurrent();
}
void GraphicsContextImplementation::makeContextCurrent(GraphicsContext* readContext)
void GraphicsContextImplementation::makeContextCurrentImplementation(GraphicsContext* readContext)
{
if (!_rs) return;
@@ -207,7 +207,7 @@ void GraphicsContextImplementation::makeContextCurrent(GraphicsContext* readCont
_rs->makeCurrent();
}
void GraphicsContextImplementation::release()
void GraphicsContextImplementation::close()
{
if (!_rs) return;

View File

@@ -684,8 +684,7 @@ void Viewer::update()
// create an event to signal the new frame.
osg::ref_ptr<osgProducer::EventAdapter> frame_event = new osgProducer::EventAdapter;
// frame_event->adaptFrame(__frameStamp->getReferenceTime());
frame_event->adaptFrame(_kbmcb->getTime());
frame_event->adaptFrame(_frameStamp->getReferenceTime());
queue.push_back(frame_event);
if (_eventVisitor.valid())

View File

@@ -160,6 +160,10 @@ void RenderStage::draw(osg::State& state,RenderLeaf*& previous)
if (_graphicsContext.valid() && _graphicsContext != callingContext)
{
// show we release the context so that others can use it?? will do so right
// now as an experiment.
callingContext->releaseContext();
useState = _graphicsContext->getState();
useContext = _graphicsContext.get();
useContext->makeCurrent();