2012-09-20 13:56:37 +02:00
|
|
|
#include "globalmap.hpp"
|
|
|
|
|
2015-05-16 14:48:20 +02:00
|
|
|
#include <climits>
|
2012-09-20 18:23:27 +02:00
|
|
|
|
2015-05-16 14:48:20 +02:00
|
|
|
#include <osg/Image>
|
|
|
|
#include <osg/Texture2D>
|
2012-09-20 13:56:37 +02:00
|
|
|
|
2015-05-28 18:49:24 +02:00
|
|
|
#include <osgDB/WriteFile>
|
|
|
|
|
2013-08-27 15:48:13 +02:00
|
|
|
#include <components/loadinglistener/loadinglistener.hpp>
|
2015-01-31 23:27:34 +01:00
|
|
|
#include <components/settings/settings.hpp>
|
2015-05-28 18:49:24 +02:00
|
|
|
#include <components/files/memorystream.hpp>
|
2013-08-27 15:48:13 +02:00
|
|
|
|
2014-01-25 18:20:17 +01:00
|
|
|
#include <components/esm/globalmap.hpp>
|
|
|
|
|
2012-09-20 13:56:37 +02:00
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
#include "../mwbase/world.hpp"
|
|
|
|
|
2012-10-01 19:17:04 +04:00
|
|
|
#include "../mwworld/esmstore.hpp"
|
2012-09-20 13:56:37 +02:00
|
|
|
|
|
|
|
namespace MWRender
|
|
|
|
{
|
|
|
|
|
2015-05-16 14:48:20 +02:00
|
|
|
GlobalMap::GlobalMap()
|
2015-05-23 20:33:44 +02:00
|
|
|
: mWidth(0)
|
2013-07-31 18:46:32 +02:00
|
|
|
, mHeight(0)
|
2015-04-30 19:24:27 -05:00
|
|
|
, mMinX(0), mMaxX(0)
|
|
|
|
, mMinY(0), mMaxY(0)
|
|
|
|
|
2012-09-20 13:56:37 +02:00
|
|
|
{
|
2014-09-26 12:47:33 +02:00
|
|
|
mCellSize = Settings::Manager::getInt("global map cell size", "Map");
|
2012-09-20 13:56:37 +02:00
|
|
|
}
|
|
|
|
|
2014-08-14 19:01:03 +02:00
|
|
|
GlobalMap::~GlobalMap()
|
|
|
|
{
|
|
|
|
}
|
2012-09-20 13:56:37 +02:00
|
|
|
|
2013-08-27 15:48:13 +02:00
|
|
|
void GlobalMap::render (Loading::Listener* loadingListener)
|
2012-09-20 13:56:37 +02:00
|
|
|
{
|
2012-11-06 11:53:00 +04:00
|
|
|
const MWWorld::ESMStore &esmStore =
|
|
|
|
MWBase::Environment::get().getWorld()->getStore();
|
|
|
|
|
2012-09-21 16:26:04 +02:00
|
|
|
// get the size of the world
|
2012-11-06 11:53:00 +04:00
|
|
|
MWWorld::Store<ESM::Cell>::iterator it = esmStore.get<ESM::Cell>().extBegin();
|
2012-11-06 13:14:03 +04:00
|
|
|
for (; it != esmStore.get<ESM::Cell>().extEnd(); ++it)
|
2012-09-20 13:56:37 +02:00
|
|
|
{
|
2012-11-06 11:53:00 +04:00
|
|
|
if (it->getGridX() < mMinX)
|
|
|
|
mMinX = it->getGridX();
|
|
|
|
if (it->getGridX() > mMaxX)
|
|
|
|
mMaxX = it->getGridX();
|
|
|
|
if (it->getGridY() < mMinY)
|
|
|
|
mMinY = it->getGridY();
|
|
|
|
if (it->getGridY() > mMaxY)
|
|
|
|
mMaxY = it->getGridY();
|
2012-09-21 16:26:04 +02:00
|
|
|
}
|
2012-09-20 13:56:37 +02:00
|
|
|
|
2014-09-26 12:47:33 +02:00
|
|
|
mWidth = mCellSize*(mMaxX-mMinX+1);
|
|
|
|
mHeight = mCellSize*(mMaxY-mMinY+1);
|
2012-09-20 13:56:37 +02:00
|
|
|
|
2013-08-27 15:48:13 +02:00
|
|
|
loadingListener->loadingOn();
|
|
|
|
loadingListener->setLabel("Creating map");
|
|
|
|
loadingListener->setProgressRange((mMaxX-mMinX+1) * (mMaxY-mMinY+1));
|
|
|
|
loadingListener->setProgress(0);
|
|
|
|
|
2015-05-16 14:48:20 +02:00
|
|
|
osg::ref_ptr<osg::Image> image = new osg::Image;
|
|
|
|
image->allocateImage(mWidth, mHeight, 1, GL_RGB, GL_UNSIGNED_BYTE);
|
|
|
|
unsigned char* data = image->data();
|
2012-09-20 13:56:37 +02:00
|
|
|
|
2015-01-29 02:23:49 +01:00
|
|
|
for (int x = mMinX; x <= mMaxX; ++x)
|
|
|
|
{
|
|
|
|
for (int y = mMinY; y <= mMaxY; ++y)
|
2012-09-20 13:56:37 +02:00
|
|
|
{
|
2015-01-29 02:23:49 +01:00
|
|
|
ESM::Land* land = esmStore.get<ESM::Land>().search (x,y);
|
2012-09-20 13:56:37 +02:00
|
|
|
|
2015-01-29 02:23:49 +01:00
|
|
|
if (land)
|
|
|
|
{
|
2015-01-29 03:30:07 +01:00
|
|
|
int mask = ESM::Land::DATA_WNAM;
|
2015-01-29 02:23:49 +01:00
|
|
|
if (!land->isDataLoaded(mask))
|
|
|
|
land->loadData(mask);
|
|
|
|
}
|
2012-09-20 13:56:37 +02:00
|
|
|
|
2015-01-29 02:23:49 +01:00
|
|
|
for (int cellY=0; cellY<mCellSize; ++cellY)
|
|
|
|
{
|
|
|
|
for (int cellX=0; cellX<mCellSize; ++cellX)
|
2012-09-20 13:56:37 +02:00
|
|
|
{
|
2015-03-08 13:07:29 +13:00
|
|
|
int vertexX = static_cast<int>(float(cellX)/float(mCellSize) * 9);
|
|
|
|
int vertexY = static_cast<int>(float(cellY) / float(mCellSize) * 9);
|
2012-09-20 13:56:37 +02:00
|
|
|
|
|
|
|
|
2015-01-29 02:23:49 +01:00
|
|
|
int texelX = (x-mMinX) * mCellSize + cellX;
|
|
|
|
int texelY = (mHeight-1) - ((y-mMinY) * mCellSize + cellY);
|
2012-09-20 13:56:37 +02:00
|
|
|
|
2015-01-29 02:23:49 +01:00
|
|
|
unsigned char r,g,b;
|
2012-09-20 13:56:37 +02:00
|
|
|
|
2015-01-29 02:23:49 +01:00
|
|
|
float y = 0;
|
|
|
|
if (land && land->mDataTypes & ESM::Land::DATA_WNAM)
|
|
|
|
y = (land->mLandData->mWnam[vertexY * 9 + vertexX] << 4) / 2048.f;
|
|
|
|
else
|
|
|
|
y = (SCHAR_MIN << 4) / 2048.f;
|
|
|
|
if (y < 0)
|
|
|
|
{
|
2015-03-08 13:07:29 +13:00
|
|
|
r = static_cast<unsigned char>(14 * y + 38);
|
|
|
|
g = static_cast<unsigned char>(20 * y + 56);
|
|
|
|
b = static_cast<unsigned char>(18 * y + 51);
|
2015-01-29 02:23:49 +01:00
|
|
|
}
|
|
|
|
else if (y < 0.3f)
|
|
|
|
{
|
|
|
|
if (y < 0.1f)
|
|
|
|
y *= 8.f;
|
2012-09-20 13:56:37 +02:00
|
|
|
else
|
|
|
|
{
|
2015-03-08 13:07:29 +13:00
|
|
|
y -= 0.1f;
|
|
|
|
y += 0.8f;
|
2012-09-20 13:56:37 +02:00
|
|
|
}
|
2015-03-08 13:07:29 +13:00
|
|
|
r = static_cast<unsigned char>(66 - 32 * y);
|
|
|
|
g = static_cast<unsigned char>(48 - 23 * y);
|
|
|
|
b = static_cast<unsigned char>(33 - 16 * y);
|
2012-09-20 13:56:37 +02:00
|
|
|
}
|
2015-01-29 02:23:49 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
y -= 0.3f;
|
|
|
|
y *= 1.428f;
|
2015-03-08 13:07:29 +13:00
|
|
|
r = static_cast<unsigned char>(34 - 29 * y);
|
|
|
|
g = static_cast<unsigned char>(25 - 20 * y);
|
|
|
|
b = static_cast<unsigned char>(17 - 12 * y);
|
2015-01-29 02:23:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
data[texelY * mWidth * 3 + texelX * 3] = r;
|
|
|
|
data[texelY * mWidth * 3 + texelX * 3+1] = g;
|
|
|
|
data[texelY * mWidth * 3 + texelX * 3+2] = b;
|
2012-09-20 13:56:37 +02:00
|
|
|
}
|
|
|
|
}
|
2015-01-29 02:23:49 +01:00
|
|
|
loadingListener->increaseProgress();
|
2015-01-29 03:30:07 +01:00
|
|
|
if (land)
|
|
|
|
land->unloadData();
|
2012-09-20 13:56:37 +02:00
|
|
|
}
|
2015-01-29 02:23:49 +01:00
|
|
|
}
|
2012-09-20 13:56:37 +02:00
|
|
|
|
2015-05-16 14:48:20 +02:00
|
|
|
mBaseTexture = new osg::Texture2D;
|
2015-05-28 18:49:24 +02:00
|
|
|
mBaseTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
|
|
|
|
mBaseTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
|
|
|
|
mBaseTexture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR);
|
|
|
|
mBaseTexture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
|
2015-05-16 14:48:20 +02:00
|
|
|
mBaseTexture->setImage(image);
|
2015-05-28 18:49:24 +02:00
|
|
|
mBaseTexture->setResizeNonPowerOfTwoHint(false);
|
2012-11-16 19:34:09 +01:00
|
|
|
|
2014-01-25 13:34:56 +01:00
|
|
|
clear();
|
2013-08-27 15:48:13 +02:00
|
|
|
|
|
|
|
loadingListener->loadingOff();
|
2012-09-20 13:56:37 +02:00
|
|
|
}
|
|
|
|
|
2012-09-21 16:26:04 +02:00
|
|
|
void GlobalMap::worldPosToImageSpace(float x, float z, float& imageX, float& imageY)
|
|
|
|
{
|
|
|
|
imageX = float(x / 8192.f - mMinX) / (mMaxX - mMinX + 1);
|
|
|
|
|
2013-02-26 13:52:01 +01:00
|
|
|
imageY = 1.f-float(z / 8192.f - mMinY) / (mMaxY - mMinY + 1);
|
2012-09-21 16:26:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GlobalMap::cellTopLeftCornerToImageSpace(int x, int y, float& imageX, float& imageY)
|
|
|
|
{
|
|
|
|
imageX = float(x - mMinX) / (mMaxX - mMinX + 1);
|
|
|
|
|
|
|
|
// NB y + 1, because we want the top left corner, not bottom left where the origin of the cell is
|
|
|
|
imageY = 1.f-float(y - mMinY + 1) / (mMaxY - mMinY + 1);
|
|
|
|
}
|
|
|
|
|
2012-11-04 12:13:04 +01:00
|
|
|
void GlobalMap::exploreCell(int cellX, int cellY)
|
|
|
|
{
|
2015-05-16 14:48:20 +02:00
|
|
|
//float originX = static_cast<float>((cellX - mMinX) * mCellSize);
|
2012-11-16 19:34:09 +01:00
|
|
|
// NB y + 1, because we want the top left corner, not bottom left where the origin of the cell is
|
2015-05-16 14:48:20 +02:00
|
|
|
//float originY = static_cast<float>(mHeight - (cellY + 1 - mMinY) * mCellSize);
|
2012-11-04 12:13:04 +01:00
|
|
|
|
2012-11-16 19:34:09 +01:00
|
|
|
if (cellX > mMaxX || cellX < mMinX || cellY > mMaxY || cellY < mMinY)
|
|
|
|
return;
|
2012-09-21 16:26:04 +02:00
|
|
|
|
2015-05-16 14:48:20 +02:00
|
|
|
/*
|
2012-11-16 19:34:09 +01:00
|
|
|
Ogre::TexturePtr localMapTexture = Ogre::TextureManager::getSingleton().getByName("Cell_"
|
|
|
|
+ boost::lexical_cast<std::string>(cellX) + "_" + boost::lexical_cast<std::string>(cellY));
|
2012-11-04 12:13:04 +01:00
|
|
|
|
2012-11-16 19:34:09 +01:00
|
|
|
if (!localMapTexture.isNull())
|
2012-11-16 22:26:00 +01:00
|
|
|
{
|
2014-12-23 01:54:37 +01:00
|
|
|
int mapWidth = localMapTexture->getWidth();
|
|
|
|
int mapHeight = localMapTexture->getHeight();
|
2014-08-14 19:01:03 +02:00
|
|
|
mOverlayTexture->load();
|
2014-12-23 01:54:37 +01:00
|
|
|
mOverlayTexture->getBuffer()->blit(localMapTexture->getBuffer(), Ogre::Image::Box(0,0,mapWidth,mapHeight),
|
2015-03-08 13:07:29 +13:00
|
|
|
Ogre::Image::Box(static_cast<Ogre::uint32>(originX), static_cast<Ogre::uint32>(originY),
|
|
|
|
static_cast<Ogre::uint32>(originX + mCellSize), static_cast<Ogre::uint32>(originY + mCellSize)));
|
2014-08-14 19:01:03 +02:00
|
|
|
|
|
|
|
Ogre::Image backup;
|
|
|
|
std::vector<Ogre::uchar> data;
|
2014-09-26 12:47:33 +02:00
|
|
|
data.resize(mCellSize*mCellSize*4, 0);
|
|
|
|
backup.loadDynamicImage(&data[0], mCellSize, mCellSize, Ogre::PF_A8B8G8R8);
|
2014-08-14 19:01:03 +02:00
|
|
|
|
2014-12-23 01:54:37 +01:00
|
|
|
localMapTexture->getBuffer()->blitToMemory(Ogre::Image::Box(0,0,mapWidth,mapHeight), backup.getPixelBox());
|
2014-08-14 19:01:03 +02:00
|
|
|
|
2014-09-26 12:47:33 +02:00
|
|
|
for (int x=0; x<mCellSize; ++x)
|
|
|
|
for (int y=0; y<mCellSize; ++y)
|
2014-08-14 19:01:03 +02:00
|
|
|
{
|
|
|
|
assert (originX+x < mOverlayImage.getWidth());
|
|
|
|
assert (originY+y < mOverlayImage.getHeight());
|
|
|
|
assert (x < int(backup.getWidth()));
|
|
|
|
assert (y < int(backup.getHeight()));
|
2015-03-08 13:07:29 +13:00
|
|
|
mOverlayImage.setColourAt(backup.getColourAt(x, y, 0), static_cast<size_t>(originX + x), static_cast<size_t>(originY + y), 0);
|
2014-08-14 19:01:03 +02:00
|
|
|
}
|
2012-11-16 22:26:00 +01:00
|
|
|
}
|
2015-05-16 14:48:20 +02:00
|
|
|
*/
|
2012-11-04 12:13:04 +01:00
|
|
|
}
|
2014-01-25 13:34:56 +01:00
|
|
|
|
|
|
|
void GlobalMap::clear()
|
|
|
|
{
|
2015-05-28 18:49:24 +02:00
|
|
|
if (!mOverlayImage)
|
|
|
|
{
|
|
|
|
mOverlayImage = new osg::Image;
|
|
|
|
mOverlayImage->allocateImage(mWidth, mHeight, 1, GL_RGBA, GL_UNSIGNED_BYTE);
|
|
|
|
assert(mOverlayImage->isDataContiguous());
|
|
|
|
}
|
|
|
|
memset(mOverlayImage->data(), 0, mOverlayImage->getTotalSizeInBytes());
|
|
|
|
mOverlayImage->dirty();
|
2014-01-25 13:34:56 +01:00
|
|
|
|
2015-05-28 18:49:24 +02:00
|
|
|
if (!mOverlayTexture)
|
|
|
|
{
|
|
|
|
mOverlayTexture = new osg::Texture2D;
|
|
|
|
mOverlayTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
|
|
|
|
mOverlayTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
|
|
|
|
mOverlayTexture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR);
|
|
|
|
mOverlayTexture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
|
|
|
|
mOverlayTexture->setImage(mOverlayImage);
|
|
|
|
mOverlayTexture->setResizeNonPowerOfTwoHint(false);
|
|
|
|
}
|
2014-01-25 13:34:56 +01:00
|
|
|
}
|
2014-01-25 18:20:17 +01:00
|
|
|
|
2014-04-26 13:42:32 +02:00
|
|
|
void GlobalMap::write(ESM::GlobalMap& map)
|
2014-01-25 18:20:17 +01:00
|
|
|
{
|
|
|
|
map.mBounds.mMinX = mMinX;
|
|
|
|
map.mBounds.mMaxX = mMaxX;
|
|
|
|
map.mBounds.mMinY = mMinY;
|
|
|
|
map.mBounds.mMaxY = mMaxY;
|
|
|
|
|
2015-05-28 18:49:24 +02:00
|
|
|
std::ostringstream ostream;
|
|
|
|
osgDB::ReaderWriter* readerwriter = osgDB::Registry::instance()->getReaderWriterForExtension("png");
|
|
|
|
if (!readerwriter)
|
|
|
|
{
|
|
|
|
std::cerr << "Can't write map overlay: no png readerwriter found" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
osgDB::ReaderWriter::WriteResult result = readerwriter->writeImage(*mOverlayImage, ostream);
|
|
|
|
if (!result.success())
|
|
|
|
{
|
|
|
|
std::cerr << "Can't write map overlay: " << result.message() << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string data = ostream.str();
|
|
|
|
map.mImageData = std::vector<char>(data.begin(), data.end());
|
2014-01-25 18:20:17 +01:00
|
|
|
}
|
|
|
|
|
2015-05-28 18:49:24 +02:00
|
|
|
struct Box
|
|
|
|
{
|
|
|
|
int mLeft, mRight, mTop, mBottom;
|
|
|
|
|
|
|
|
Box(int left, int right, int top, int bottom)
|
|
|
|
: mLeft(left), mRight(right), mTop(top), mBottom(bottom)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-04-26 13:42:32 +02:00
|
|
|
void GlobalMap::read(ESM::GlobalMap& map)
|
2014-01-25 18:20:17 +01:00
|
|
|
{
|
2014-04-26 13:42:32 +02:00
|
|
|
const ESM::GlobalMap::Bounds& bounds = map.mBounds;
|
2014-01-26 15:18:31 +01:00
|
|
|
|
2015-01-29 02:23:49 +01:00
|
|
|
if (bounds.mMaxX-bounds.mMinX < 0)
|
2014-04-26 13:42:32 +02:00
|
|
|
return;
|
2015-01-29 02:23:49 +01:00
|
|
|
if (bounds.mMaxY-bounds.mMinY < 0)
|
2014-04-26 13:42:32 +02:00
|
|
|
return;
|
2014-01-25 18:20:17 +01:00
|
|
|
|
2014-04-26 13:42:32 +02:00
|
|
|
if (bounds.mMinX > bounds.mMaxX
|
|
|
|
|| bounds.mMinY > bounds.mMaxY)
|
|
|
|
throw std::runtime_error("invalid map bounds");
|
2014-01-25 18:20:17 +01:00
|
|
|
|
2015-05-28 18:49:24 +02:00
|
|
|
if (!map.mImageData.size())
|
|
|
|
return;
|
|
|
|
|
|
|
|
Files::IMemStream istream(&map.mImageData[0], map.mImageData.size());
|
|
|
|
|
|
|
|
osgDB::ReaderWriter* readerwriter = osgDB::Registry::instance()->getReaderWriterForExtension("png");
|
|
|
|
if (!readerwriter)
|
|
|
|
{
|
|
|
|
std::cerr << "Can't read map overlay: no png readerwriter found" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
osgDB::ReaderWriter::ReadResult result = readerwriter->readImage(istream);
|
|
|
|
if (!result.success())
|
|
|
|
{
|
|
|
|
std::cerr << "Can't read map overlay: " << result.message() << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Image> image = result.getImage();
|
|
|
|
int imageWidth = image->s();
|
|
|
|
int imageHeight = image->t();
|
2014-04-26 13:42:32 +02:00
|
|
|
|
|
|
|
int xLength = (bounds.mMaxX-bounds.mMinX+1);
|
|
|
|
int yLength = (bounds.mMaxY-bounds.mMinY+1);
|
|
|
|
|
|
|
|
// Size of one cell in image space
|
2015-05-28 18:49:24 +02:00
|
|
|
int cellImageSizeSrc = imageWidth / xLength;
|
|
|
|
if (int(imageHeight / yLength) != cellImageSizeSrc)
|
2014-04-26 13:42:32 +02:00
|
|
|
throw std::runtime_error("cell size must be quadratic");
|
|
|
|
|
|
|
|
// If cell bounds of the currently loaded content and the loaded savegame do not match,
|
|
|
|
// we need to resize source/dest boxes to accommodate
|
|
|
|
// This means nonexisting cells will be dropped silently
|
2014-09-26 12:47:33 +02:00
|
|
|
int cellImageSizeDst = mCellSize;
|
2014-04-26 13:42:32 +02:00
|
|
|
|
|
|
|
// Completely off-screen? -> no need to blit anything
|
|
|
|
if (bounds.mMaxX < mMinX
|
|
|
|
|| bounds.mMaxY < mMinY
|
|
|
|
|| bounds.mMinX > mMaxX
|
|
|
|
|| bounds.mMinY > mMaxY)
|
|
|
|
return;
|
2014-01-25 18:20:17 +01:00
|
|
|
|
2014-04-26 13:42:32 +02:00
|
|
|
int leftDiff = (mMinX - bounds.mMinX);
|
|
|
|
int topDiff = (bounds.mMaxY - mMaxY);
|
|
|
|
int rightDiff = (bounds.mMaxX - mMaxX);
|
|
|
|
int bottomDiff = (mMinY - bounds.mMinY);
|
2015-05-28 18:49:24 +02:00
|
|
|
|
|
|
|
Box srcBox ( std::max(0, leftDiff * cellImageSizeSrc),
|
2014-04-26 13:42:32 +02:00
|
|
|
std::max(0, topDiff * cellImageSizeSrc),
|
2015-05-28 18:49:24 +02:00
|
|
|
std::min(imageWidth, imageWidth - rightDiff * cellImageSizeSrc),
|
|
|
|
std::min(imageHeight, imageHeight - bottomDiff * cellImageSizeSrc));
|
2014-04-26 13:42:32 +02:00
|
|
|
|
2015-05-28 18:49:24 +02:00
|
|
|
Box destBox ( std::max(0, -leftDiff * cellImageSizeDst),
|
2014-04-26 13:42:32 +02:00
|
|
|
std::max(0, -topDiff * cellImageSizeDst),
|
2015-05-28 18:49:24 +02:00
|
|
|
std::min(mWidth, mWidth + rightDiff * cellImageSizeDst),
|
|
|
|
std::min(mHeight, mHeight + bottomDiff * cellImageSizeDst));
|
2014-08-14 19:01:03 +02:00
|
|
|
|
2015-05-28 18:49:24 +02:00
|
|
|
if (srcBox.mLeft == destBox.mLeft && srcBox.mRight == destBox.mRight
|
|
|
|
&& srcBox.mTop == destBox.mTop && srcBox.mBottom == destBox.mBottom
|
|
|
|
&& imageWidth == mWidth && imageHeight == mHeight)
|
|
|
|
{
|
|
|
|
mOverlayImage->copySubImage(0, 0, 0, image);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// TODO:
|
|
|
|
// Dimensions don't match. This could mean a changed map region, or a changed map resolution.
|
|
|
|
// In the latter case, we'll want to use filtering.
|
|
|
|
// Create a RTT Camera and draw the image onto mOverlayImage in the next frame?
|
|
|
|
}
|
|
|
|
mOverlayImage->dirty();
|
2015-05-16 14:48:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Texture2D> GlobalMap::getBaseTexture()
|
|
|
|
{
|
|
|
|
return mBaseTexture;
|
2014-01-25 18:20:17 +01:00
|
|
|
}
|
2015-05-28 18:49:24 +02:00
|
|
|
|
|
|
|
osg::ref_ptr<osg::Texture2D> GlobalMap::getOverlayTexture()
|
|
|
|
{
|
|
|
|
return mOverlayTexture;
|
|
|
|
}
|
2012-09-20 13:56:37 +02:00
|
|
|
}
|