1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 09:35:28 +00:00

Merge branch '14' into 'master'

fix #5176

Closes #5176

See merge request OpenMW/openmw!153
This commit is contained in:
Alexei Dobrohotov 2019-10-19 09:52:25 +00:00
commit cde80d6f28
2 changed files with 35 additions and 26 deletions

View File

@ -74,17 +74,17 @@ namespace
{ {
if (mRendered) if (mRendered)
{ {
node->setNodeMask(0); if (mParent->copyResult(static_cast<osg::Camera*>(node), nv->getTraversalNumber()))
{
node->setNodeMask(0);
mParent->markForRemoval(static_cast<osg::Camera*>(node));
}
return; return;
} }
traverse(node, nv); traverse(node, nv);
if (!mRendered) mRendered = true;
{
mRendered = true;
mParent->markForRemoval(static_cast<osg::Camera*>(node));
}
} }
private: private:
@ -325,7 +325,7 @@ namespace MWRender
imageDest.mImage = image; imageDest.mImage = image;
imageDest.mX = x; imageDest.mX = x;
imageDest.mY = y; imageDest.mY = y;
mPendingImageDest.push_back(imageDest); mPendingImageDest[camera] = imageDest;
} }
// Create a quad rendering the updated texture // 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) void GlobalMap::markForRemoval(osg::Camera *camera)
{ {
CameraVector::iterator found = std::find(mActiveCameras.begin(), mActiveCameras.end(), camera); CameraVector::iterator found = std::find(mActiveCameras.begin(), mActiveCameras.end(), camera);
@ -585,21 +606,6 @@ namespace MWRender
removeCamera(camera); removeCamera(camera);
mCamerasPendingRemoval.clear(); 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) void GlobalMap::removeCamera(osg::Camera *cam)

View File

@ -3,6 +3,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <map>
#include <osg/ref_ptr> #include <osg/ref_ptr>
@ -60,6 +61,8 @@ namespace MWRender
void removeCamera(osg::Camera* cam); 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. * Mark a camera for cleanup in the next update. For internal use only.
*/ */
@ -95,18 +98,18 @@ namespace MWRender
{ {
ImageDest() ImageDest()
: mX(0), mY(0) : mX(0), mY(0)
, mFramesUntilDone(3) // wait an extra frame to ensure the draw thread has completed its frame. , mFrameDone(0)
{ {
} }
osg::ref_ptr<osg::Image> mImage; osg::ref_ptr<osg::Image> mImage;
int mX, mY; int mX, mY;
int mFramesUntilDone; unsigned int mFrameDone;
}; };
typedef std::vector<ImageDest> ImageDestVector; typedef std::map<osg::ref_ptr<osg::Camera>, ImageDest> ImageDestMap;
ImageDestVector mPendingImageDest; ImageDestMap mPendingImageDest;
std::vector< std::pair<int,int> > mExploredCells; std::vector< std::pair<int,int> > mExploredCells;