mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-03 20:45:33 +00:00
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
|
||||
{
|
||||
public:
|
||||
NotifyDrawCompletedCallback()
|
||||
: mDone(false)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void operator () (osg::RenderInfo& renderInfo) const
|
||||
{
|
||||
mMutex.lock();
|
||||
mDone = true;
|
||||
mMutex.unlock();
|
||||
mCondition.signal();
|
||||
}
|
||||
|
||||
void waitTillDone()
|
||||
{
|
||||
mMutex.lock();
|
||||
if (mDone)
|
||||
return;
|
||||
mCondition.wait(&mMutex);
|
||||
mMutex.unlock();
|
||||
}
|
||||
|
||||
mutable OpenThreads::Condition mCondition;
|
||||
mutable OpenThreads::Mutex mMutex;
|
||||
mutable bool mDone;
|
||||
};
|
||||
|
||||
void RenderingManager::screenshot(osg::Image *image, int w, int h)
|
||||
|
@ -476,15 +495,13 @@ namespace MWRender
|
|||
|
||||
mRootNode->addChild(rttCamera);
|
||||
|
||||
mViewer->frame(mViewer->getFrameStamp()->getSimulationTime());
|
||||
|
||||
// The draw needs to complete before we can copy back our image.
|
||||
osg::ref_ptr<NotifyDrawCompletedCallback> callback (new NotifyDrawCompletedCallback);
|
||||
rttCamera->setFinalDrawCallback(callback);
|
||||
OpenThreads::Mutex m;
|
||||
m.lock();
|
||||
callback->mCondition.wait(&m);
|
||||
m.unlock();
|
||||
|
||||
mViewer->frame(mViewer->getFrameStamp()->getSimulationTime());
|
||||
|
||||
callback->waitTillDone();
|
||||
|
||||
rttCamera->removeChildren(0, rttCamera->getNumChildren());
|
||||
rttCamera->setGraphicsContext(NULL);
|
||||
|
|
Loading…
Reference in a new issue