forked from teamnwah/openmw-tes3coop
Fix NotifyDrawCompletedCallback in single threaded mode
This commit is contained in:
parent
e73c115ff5
commit
88c61ed2b6
1 changed files with 23 additions and 6 deletions
|
@ -437,12 +437,31 @@ namespace MWRender
|
||||||
class NotifyDrawCompletedCallback : public osg::Camera::DrawCallback
|
class NotifyDrawCompletedCallback : public osg::Camera::DrawCallback
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
NotifyDrawCompletedCallback()
|
||||||
|
: mDone(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
virtual void operator () (osg::RenderInfo& renderInfo) const
|
virtual void operator () (osg::RenderInfo& renderInfo) const
|
||||||
{
|
{
|
||||||
|
mMutex.lock();
|
||||||
|
mDone = true;
|
||||||
|
mMutex.unlock();
|
||||||
mCondition.signal();
|
mCondition.signal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void waitTillDone()
|
||||||
|
{
|
||||||
|
mMutex.lock();
|
||||||
|
if (mDone)
|
||||||
|
return;
|
||||||
|
mCondition.wait(&mMutex);
|
||||||
|
mMutex.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
mutable OpenThreads::Condition mCondition;
|
mutable OpenThreads::Condition mCondition;
|
||||||
|
mutable OpenThreads::Mutex mMutex;
|
||||||
|
mutable bool mDone;
|
||||||
};
|
};
|
||||||
|
|
||||||
void RenderingManager::screenshot(osg::Image *image, int w, int h)
|
void RenderingManager::screenshot(osg::Image *image, int w, int h)
|
||||||
|
@ -476,15 +495,13 @@ namespace MWRender
|
||||||
|
|
||||||
mRootNode->addChild(rttCamera);
|
mRootNode->addChild(rttCamera);
|
||||||
|
|
||||||
mViewer->frame(mViewer->getFrameStamp()->getSimulationTime());
|
|
||||||
|
|
||||||
// The draw needs to complete before we can copy back our image.
|
// The draw needs to complete before we can copy back our image.
|
||||||
osg::ref_ptr<NotifyDrawCompletedCallback> callback (new NotifyDrawCompletedCallback);
|
osg::ref_ptr<NotifyDrawCompletedCallback> callback (new NotifyDrawCompletedCallback);
|
||||||
rttCamera->setFinalDrawCallback(callback);
|
rttCamera->setFinalDrawCallback(callback);
|
||||||
OpenThreads::Mutex m;
|
|
||||||
m.lock();
|
mViewer->frame(mViewer->getFrameStamp()->getSimulationTime());
|
||||||
callback->mCondition.wait(&m);
|
|
||||||
m.unlock();
|
callback->waitTillDone();
|
||||||
|
|
||||||
rttCamera->removeChildren(0, rttCamera->getNumChildren());
|
rttCamera->removeChildren(0, rttCamera->getNumChildren());
|
||||||
rttCamera->setGraphicsContext(NULL);
|
rttCamera->setGraphicsContext(NULL);
|
||||||
|
|
Loading…
Reference in a new issue