diff --git a/apps/openmw/mwrender/globalmap.cpp b/apps/openmw/mwrender/globalmap.cpp index 57137d4157..72e8679eb1 100644 --- a/apps/openmw/mwrender/globalmap.cpp +++ b/apps/openmw/mwrender/globalmap.cpp @@ -74,17 +74,17 @@ namespace { if (mRendered) { - node->setNodeMask(0); + if (mParent->copyResult(static_cast(node), nv->getTraversalNumber())) + { + node->setNodeMask(0); + mParent->markForRemoval(static_cast(node)); + } return; } traverse(node, nv); - if (!mRendered) - { - mRendered = true; - mParent->markForRemoval(static_cast(node)); - } + mRendered = true; } private: @@ -325,7 +325,7 @@ namespace MWRender imageDest.mImage = image; imageDest.mX = x; imageDest.mY = y; - mPendingImageDest.push_back(imageDest); + mPendingImageDest[camera] = imageDest; } // Create a quad rendering the updated texture @@ -567,6 +567,27 @@ namespace MWRender } } + bool GlobalMap::copyResult(osg::Camera *camera, unsigned int frame) + { + ImageDestMap::iterator it = mPendingImageDest.find(camera); + if (it == mPendingImageDest.end()) + return true; + else + { + ImageDest& imageDest = it->second; + if (imageDest.mFrameDone == 0) imageDest.mFrameDone = frame+2; // wait an extra frame to ensure the draw thread has completed its frame. + if (imageDest.mFrameDone > frame) + { + ++it; + return false; + } + + mOverlayImage->copySubImage(imageDest.mX, imageDest.mY, 0, imageDest.mImage); + it = mPendingImageDest.erase(it); + return true; + } + } + void GlobalMap::markForRemoval(osg::Camera *camera) { CameraVector::iterator found = std::find(mActiveCameras.begin(), mActiveCameras.end(), camera); @@ -585,21 +606,6 @@ namespace MWRender removeCamera(camera); mCamerasPendingRemoval.clear(); - - for (ImageDestVector::iterator it = mPendingImageDest.begin(); it != mPendingImageDest.end();) - { - ImageDest& imageDest = *it; - if (--imageDest.mFramesUntilDone > 0) - { - ++it; - continue; - } - - ensureLoaded(); - mOverlayImage->copySubImage(imageDest.mX, imageDest.mY, 0, imageDest.mImage); - - it = mPendingImageDest.erase(it); - } } void GlobalMap::removeCamera(osg::Camera *cam) diff --git a/apps/openmw/mwrender/globalmap.hpp b/apps/openmw/mwrender/globalmap.hpp index f19f4a91fb..b359c852be 100644 --- a/apps/openmw/mwrender/globalmap.hpp +++ b/apps/openmw/mwrender/globalmap.hpp @@ -3,6 +3,7 @@ #include #include +#include #include @@ -60,6 +61,8 @@ namespace MWRender void removeCamera(osg::Camera* cam); + bool copyResult(osg::Camera* cam, unsigned int frame); + /** * Mark a camera for cleanup in the next update. For internal use only. */ @@ -95,18 +98,18 @@ namespace MWRender { ImageDest() : mX(0), mY(0) - , mFramesUntilDone(3) // wait an extra frame to ensure the draw thread has completed its frame. + , mFrameDone(0) { } osg::ref_ptr mImage; int mX, mY; - int mFramesUntilDone; + unsigned int mFrameDone; }; - typedef std::vector ImageDestVector; + typedef std::map, ImageDest> ImageDestMap; - ImageDestVector mPendingImageDest; + ImageDestMap mPendingImageDest; std::vector< std::pair > mExploredCells;