|
|
|
@ -15,6 +15,8 @@
|
|
|
|
|
#include <components/settings/settings.hpp>
|
|
|
|
|
#include <components/files/memorystream.hpp>
|
|
|
|
|
|
|
|
|
|
#include <components/sceneutil/workqueue.hpp>
|
|
|
|
|
|
|
|
|
|
#include <components/esm/globalmap.hpp>
|
|
|
|
|
|
|
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
@ -95,8 +97,132 @@ namespace
|
|
|
|
|
namespace MWRender
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
GlobalMap::GlobalMap(osg::Group* root)
|
|
|
|
|
class CreateMapWorkItem : public SceneUtil::WorkItem
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
CreateMapWorkItem(int width, int height, int minX, int minY, int maxX, int maxY, int cellSize, const MWWorld::Store<ESM::Land>& landStore)
|
|
|
|
|
: mWidth(width), mHeight(height), mMinX(minX), mMinY(minY), mMaxX(maxX), mMaxY(maxY), mCellSize(cellSize), mLandStore(landStore)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void doWork()
|
|
|
|
|
{
|
|
|
|
|
osg::ref_ptr<osg::Image> image = new osg::Image;
|
|
|
|
|
image->allocateImage(mWidth, mHeight, 1, GL_RGB, GL_UNSIGNED_BYTE);
|
|
|
|
|
unsigned char* data = image->data();
|
|
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Image> alphaImage = new osg::Image;
|
|
|
|
|
alphaImage->allocateImage(mWidth, mHeight, 1, GL_ALPHA, GL_UNSIGNED_BYTE);
|
|
|
|
|
unsigned char* alphaData = alphaImage->data();
|
|
|
|
|
|
|
|
|
|
for (int x = mMinX; x <= mMaxX; ++x)
|
|
|
|
|
{
|
|
|
|
|
for (int y = mMinY; y <= mMaxY; ++y)
|
|
|
|
|
{
|
|
|
|
|
const ESM::Land* land = mLandStore.search (x,y);
|
|
|
|
|
|
|
|
|
|
for (int cellY=0; cellY<mCellSize; ++cellY)
|
|
|
|
|
{
|
|
|
|
|
for (int cellX=0; cellX<mCellSize; ++cellX)
|
|
|
|
|
{
|
|
|
|
|
int vertexX = static_cast<int>(float(cellX)/float(mCellSize) * 9);
|
|
|
|
|
int vertexY = static_cast<int>(float(cellY) / float(mCellSize) * 9);
|
|
|
|
|
|
|
|
|
|
int texelX = (x-mMinX) * mCellSize + cellX;
|
|
|
|
|
int texelY = (y-mMinY) * mCellSize + cellY;
|
|
|
|
|
|
|
|
|
|
unsigned char r,g,b;
|
|
|
|
|
|
|
|
|
|
float y2 = 0;
|
|
|
|
|
if (land && (land->mDataTypes & ESM::Land::DATA_WNAM))
|
|
|
|
|
y2 = (land->mWnam[vertexY * 9 + vertexX] << 4) / 2048.f;
|
|
|
|
|
else
|
|
|
|
|
y2 = (SCHAR_MIN << 4) / 2048.f;
|
|
|
|
|
if (y2 < 0)
|
|
|
|
|
{
|
|
|
|
|
r = static_cast<unsigned char>(14 * y2 + 38);
|
|
|
|
|
g = static_cast<unsigned char>(20 * y2 + 56);
|
|
|
|
|
b = static_cast<unsigned char>(18 * y2 + 51);
|
|
|
|
|
}
|
|
|
|
|
else if (y2 < 0.3f)
|
|
|
|
|
{
|
|
|
|
|
if (y2 < 0.1f)
|
|
|
|
|
y2 *= 8.f;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
y2 -= 0.1f;
|
|
|
|
|
y2 += 0.8f;
|
|
|
|
|
}
|
|
|
|
|
r = static_cast<unsigned char>(66 - 32 * y2);
|
|
|
|
|
g = static_cast<unsigned char>(48 - 23 * y2);
|
|
|
|
|
b = static_cast<unsigned char>(33 - 16 * y2);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
y2 -= 0.3f;
|
|
|
|
|
y2 *= 1.428f;
|
|
|
|
|
r = static_cast<unsigned char>(34 - 29 * y2);
|
|
|
|
|
g = static_cast<unsigned char>(25 - 20 * y2);
|
|
|
|
|
b = static_cast<unsigned char>(17 - 12 * y2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data[texelY * mWidth * 3 + texelX * 3] = r;
|
|
|
|
|
data[texelY * mWidth * 3 + texelX * 3+1] = g;
|
|
|
|
|
data[texelY * mWidth * 3 + texelX * 3+2] = b;
|
|
|
|
|
|
|
|
|
|
alphaData[texelY * mWidth+ texelX] = (y2 < 0) ? static_cast<unsigned char>(0) : static_cast<unsigned char>(255);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mBaseTexture = new osg::Texture2D;
|
|
|
|
|
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);
|
|
|
|
|
mBaseTexture->setImage(image);
|
|
|
|
|
mBaseTexture->setResizeNonPowerOfTwoHint(false);
|
|
|
|
|
|
|
|
|
|
mAlphaTexture = new osg::Texture2D;
|
|
|
|
|
mAlphaTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
|
|
|
|
|
mAlphaTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
|
|
|
|
|
mAlphaTexture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR);
|
|
|
|
|
mAlphaTexture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
|
|
|
|
|
mAlphaTexture->setImage(alphaImage);
|
|
|
|
|
mAlphaTexture->setResizeNonPowerOfTwoHint(false);
|
|
|
|
|
|
|
|
|
|
mOverlayImage = new osg::Image;
|
|
|
|
|
mOverlayImage->allocateImage(mWidth, mHeight, 1, GL_RGBA, GL_UNSIGNED_BYTE);
|
|
|
|
|
assert(mOverlayImage->isDataContiguous());
|
|
|
|
|
|
|
|
|
|
memset(mOverlayImage->data(), 0, mOverlayImage->getTotalSizeInBytes());
|
|
|
|
|
|
|
|
|
|
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->setResizeNonPowerOfTwoHint(false);
|
|
|
|
|
mOverlayTexture->setInternalFormat(GL_RGBA);
|
|
|
|
|
mOverlayTexture->setTextureSize(mWidth, mHeight);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int mWidth, mHeight;
|
|
|
|
|
int mMinX, mMinY, mMaxX, mMaxY;
|
|
|
|
|
int mCellSize;
|
|
|
|
|
const MWWorld::Store<ESM::Land>& mLandStore;
|
|
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Texture2D> mBaseTexture;
|
|
|
|
|
osg::ref_ptr<osg::Texture2D> mAlphaTexture;
|
|
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Image> mOverlayImage;
|
|
|
|
|
osg::ref_ptr<osg::Texture2D> mOverlayTexture;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
GlobalMap::GlobalMap(osg::Group* root, SceneUtil::WorkQueue* workQueue)
|
|
|
|
|
: mRoot(root)
|
|
|
|
|
, mWorkQueue(workQueue)
|
|
|
|
|
, mWidth(0)
|
|
|
|
|
, mHeight(0)
|
|
|
|
|
, mMinX(0), mMaxX(0)
|
|
|
|
@ -114,7 +240,7 @@ namespace MWRender
|
|
|
|
|
removeCamera(*it);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GlobalMap::render (Loading::Listener* loadingListener)
|
|
|
|
|
void GlobalMap::render ()
|
|
|
|
|
{
|
|
|
|
|
const MWWorld::ESMStore &esmStore =
|
|
|
|
|
MWBase::Environment::get().getWorld()->getStore();
|
|
|
|
@ -136,112 +262,8 @@ namespace MWRender
|
|
|
|
|
mWidth = mCellSize*(mMaxX-mMinX+1);
|
|
|
|
|
mHeight = mCellSize*(mMaxY-mMinY+1);
|
|
|
|
|
|
|
|
|
|
loadingListener->loadingOn();
|
|
|
|
|
loadingListener->setLabel("Creating map");
|
|
|
|
|
loadingListener->setProgressRange((mMaxX-mMinX+1) * (mMaxY-mMinY+1));
|
|
|
|
|
loadingListener->setProgress(0);
|
|
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Image> image = new osg::Image;
|
|
|
|
|
image->allocateImage(mWidth, mHeight, 1, GL_RGB, GL_UNSIGNED_BYTE);
|
|
|
|
|
unsigned char* data = image->data();
|
|
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Image> alphaImage = new osg::Image;
|
|
|
|
|
alphaImage->allocateImage(mWidth, mHeight, 1, GL_ALPHA, GL_UNSIGNED_BYTE);
|
|
|
|
|
unsigned char* alphaData = alphaImage->data();
|
|
|
|
|
|
|
|
|
|
for (int x = mMinX; x <= mMaxX; ++x)
|
|
|
|
|
{
|
|
|
|
|
for (int y = mMinY; y <= mMaxY; ++y)
|
|
|
|
|
{
|
|
|
|
|
ESM::Land* land = esmStore.get<ESM::Land>().search (x,y);
|
|
|
|
|
|
|
|
|
|
if (land)
|
|
|
|
|
{
|
|
|
|
|
int mask = ESM::Land::DATA_WNAM;
|
|
|
|
|
if (!land->isDataLoaded(mask))
|
|
|
|
|
land->loadData(mask);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ESM::Land::LandData *landData =
|
|
|
|
|
land ? land->getLandData (ESM::Land::DATA_WNAM) : 0;
|
|
|
|
|
|
|
|
|
|
for (int cellY=0; cellY<mCellSize; ++cellY)
|
|
|
|
|
{
|
|
|
|
|
for (int cellX=0; cellX<mCellSize; ++cellX)
|
|
|
|
|
{
|
|
|
|
|
int vertexX = static_cast<int>(float(cellX)/float(mCellSize) * 9);
|
|
|
|
|
int vertexY = static_cast<int>(float(cellY) / float(mCellSize) * 9);
|
|
|
|
|
|
|
|
|
|
int texelX = (x-mMinX) * mCellSize + cellX;
|
|
|
|
|
int texelY = (y-mMinY) * mCellSize + cellY;
|
|
|
|
|
|
|
|
|
|
unsigned char r,g,b;
|
|
|
|
|
|
|
|
|
|
float y2 = 0;
|
|
|
|
|
if (landData)
|
|
|
|
|
y2 = (landData->mWnam[vertexY * 9 + vertexX] << 4) / 2048.f;
|
|
|
|
|
else
|
|
|
|
|
y2 = (SCHAR_MIN << 4) / 2048.f;
|
|
|
|
|
if (y2 < 0)
|
|
|
|
|
{
|
|
|
|
|
r = static_cast<unsigned char>(14 * y2 + 38);
|
|
|
|
|
g = static_cast<unsigned char>(20 * y2 + 56);
|
|
|
|
|
b = static_cast<unsigned char>(18 * y2 + 51);
|
|
|
|
|
}
|
|
|
|
|
else if (y2 < 0.3f)
|
|
|
|
|
{
|
|
|
|
|
if (y2 < 0.1f)
|
|
|
|
|
y2 *= 8.f;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
y2 -= 0.1f;
|
|
|
|
|
y2 += 0.8f;
|
|
|
|
|
}
|
|
|
|
|
r = static_cast<unsigned char>(66 - 32 * y2);
|
|
|
|
|
g = static_cast<unsigned char>(48 - 23 * y2);
|
|
|
|
|
b = static_cast<unsigned char>(33 - 16 * y2);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
y2 -= 0.3f;
|
|
|
|
|
y2 *= 1.428f;
|
|
|
|
|
r = static_cast<unsigned char>(34 - 29 * y2);
|
|
|
|
|
g = static_cast<unsigned char>(25 - 20 * y2);
|
|
|
|
|
b = static_cast<unsigned char>(17 - 12 * y2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data[texelY * mWidth * 3 + texelX * 3] = r;
|
|
|
|
|
data[texelY * mWidth * 3 + texelX * 3+1] = g;
|
|
|
|
|
data[texelY * mWidth * 3 + texelX * 3+2] = b;
|
|
|
|
|
|
|
|
|
|
alphaData[texelY * mWidth+ texelX] = (y2 < 0) ? static_cast<unsigned char>(0) : static_cast<unsigned char>(255);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
loadingListener->increaseProgress();
|
|
|
|
|
if (land)
|
|
|
|
|
land->unloadData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mBaseTexture = new osg::Texture2D;
|
|
|
|
|
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);
|
|
|
|
|
mBaseTexture->setImage(image);
|
|
|
|
|
mBaseTexture->setResizeNonPowerOfTwoHint(false);
|
|
|
|
|
|
|
|
|
|
mAlphaTexture = new osg::Texture2D;
|
|
|
|
|
mAlphaTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
|
|
|
|
|
mAlphaTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
|
|
|
|
|
mAlphaTexture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR);
|
|
|
|
|
mAlphaTexture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
|
|
|
|
|
mAlphaTexture->setImage(alphaImage);
|
|
|
|
|
mAlphaTexture->setResizeNonPowerOfTwoHint(false);
|
|
|
|
|
|
|
|
|
|
clear();
|
|
|
|
|
|
|
|
|
|
loadingListener->loadingOff();
|
|
|
|
|
mWorkItem = new CreateMapWorkItem(mWidth, mHeight, mMinX, mMinY, mMaxX, mMaxY, mCellSize, esmStore.get<ESM::Land>());
|
|
|
|
|
mWorkQueue->addWorkItem(mWorkItem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GlobalMap::worldPosToImageSpace(float x, float z, float& imageX, float& imageY)
|
|
|
|
@ -346,6 +368,8 @@ namespace MWRender
|
|
|
|
|
|
|
|
|
|
void GlobalMap::exploreCell(int cellX, int cellY, osg::ref_ptr<osg::Texture2D> localMapTexture)
|
|
|
|
|
{
|
|
|
|
|
ensureLoaded();
|
|
|
|
|
|
|
|
|
|
if (!localMapTexture)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
@ -360,25 +384,9 @@ namespace MWRender
|
|
|
|
|
|
|
|
|
|
void GlobalMap::clear()
|
|
|
|
|
{
|
|
|
|
|
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());
|
|
|
|
|
ensureLoaded();
|
|
|
|
|
|
|
|
|
|
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->setResizeNonPowerOfTwoHint(false);
|
|
|
|
|
mOverlayTexture->setInternalFormat(GL_RGBA);
|
|
|
|
|
mOverlayTexture->setTextureSize(mWidth, mHeight);
|
|
|
|
|
}
|
|
|
|
|
memset(mOverlayImage->data(), 0, mOverlayImage->getTotalSizeInBytes());
|
|
|
|
|
|
|
|
|
|
mPendingImageDest.clear();
|
|
|
|
|
|
|
|
|
@ -389,6 +397,8 @@ namespace MWRender
|
|
|
|
|
|
|
|
|
|
void GlobalMap::write(ESM::GlobalMap& map)
|
|
|
|
|
{
|
|
|
|
|
ensureLoaded();
|
|
|
|
|
|
|
|
|
|
map.mBounds.mMinX = mMinX;
|
|
|
|
|
map.mBounds.mMaxX = mMaxX;
|
|
|
|
|
map.mBounds.mMinY = mMinY;
|
|
|
|
@ -429,6 +439,8 @@ namespace MWRender
|
|
|
|
|
|
|
|
|
|
void GlobalMap::read(ESM::GlobalMap& map)
|
|
|
|
|
{
|
|
|
|
|
ensureLoaded();
|
|
|
|
|
|
|
|
|
|
const ESM::GlobalMap::Bounds& bounds = map.mBounds;
|
|
|
|
|
|
|
|
|
|
if (bounds.mMaxX-bounds.mMinX < 0)
|
|
|
|
@ -525,14 +537,33 @@ namespace MWRender
|
|
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Texture2D> GlobalMap::getBaseTexture()
|
|
|
|
|
{
|
|
|
|
|
ensureLoaded();
|
|
|
|
|
return mBaseTexture;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Texture2D> GlobalMap::getOverlayTexture()
|
|
|
|
|
{
|
|
|
|
|
ensureLoaded();
|
|
|
|
|
return mOverlayTexture;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GlobalMap::ensureLoaded()
|
|
|
|
|
{
|
|
|
|
|
if (mWorkItem)
|
|
|
|
|
{
|
|
|
|
|
mWorkItem->waitTillDone();
|
|
|
|
|
|
|
|
|
|
mOverlayImage = mWorkItem->mOverlayImage;
|
|
|
|
|
mBaseTexture = mWorkItem->mBaseTexture;
|
|
|
|
|
mAlphaTexture = mWorkItem->mAlphaTexture;
|
|
|
|
|
mOverlayTexture = mWorkItem->mOverlayTexture;
|
|
|
|
|
|
|
|
|
|
requestOverlayTextureUpdate(0, 0, mWidth, mHeight, osg::ref_ptr<osg::Texture2D>(), true, false);
|
|
|
|
|
|
|
|
|
|
mWorkItem = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GlobalMap::markForRemoval(osg::Camera *camera)
|
|
|
|
|
{
|
|
|
|
|
CameraVector::iterator found = std::find(mActiveCameras.begin(), mActiveCameras.end(), camera);
|
|
|
|
@ -561,6 +592,7 @@ namespace MWRender
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ensureLoaded();
|
|
|
|
|
mOverlayImage->copySubImage(imageDest.mX, imageDest.mY, 0, imageDest.mImage);
|
|
|
|
|
|
|
|
|
|
it = mPendingImageDest.erase(it);
|
|
|
|
|