From 88c61ed2b6dabb11ae2760cf3095fd2004a4e031 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 2 Aug 2015 17:57:50 +0200 Subject: [PATCH 1/2] Fix NotifyDrawCompletedCallback in single threaded mode --- apps/openmw/mwrender/renderingmanager.cpp | 29 ++++++++++++++++++----- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index c861119b5..54c6315fc 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -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 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); From 664ae079db5db64e91ed152c0d69651a03ca066d Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 2 Aug 2015 18:05:15 +0200 Subject: [PATCH 2/2] Improve setting of culling mask for the savegame screenshot camera --- apps/openmw/mwrender/renderingmanager.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 54c6315fc..b01095f12 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -466,9 +466,6 @@ namespace MWRender void RenderingManager::screenshot(osg::Image *image, int w, int h) { - int oldCullMask = mViewer->getCamera()->getCullMask(); - mViewer->getCamera()->setCullMask(oldCullMask & (~Mask_GUI)); - osg::ref_ptr rttCamera (new osg::Camera); rttCamera->setNodeMask(Mask_RenderToTexture); rttCamera->attach(osg::Camera::COLOR_BUFFER, image); @@ -492,6 +489,7 @@ namespace MWRender image->setPixelFormat(texture->getInternalFormat()); rttCamera->addChild(mLightRoot); + rttCamera->setCullMask(mViewer->getCamera()->getCullMask() & (~Mask_GUI)); mRootNode->addChild(rttCamera); @@ -506,8 +504,6 @@ namespace MWRender rttCamera->removeChildren(0, rttCamera->getNumChildren()); rttCamera->setGraphicsContext(NULL); mRootNode->removeChild(rttCamera); - - mViewer->getCamera()->setCullMask(oldCullMask); } osg::Vec4f RenderingManager::getScreenBounds(const MWWorld::Ptr& ptr)