diff --git a/components/esmterrain/storage.cpp b/components/esmterrain/storage.cpp index 1f4d1b7cf..1463d5e6a 100644 --- a/components/esmterrain/storage.cpp +++ b/components/esmterrain/storage.cpp @@ -314,7 +314,7 @@ namespace ESMTerrain } Storage::UniqueTextureId Storage::getVtexIndexAt(int cellX, int cellY, - int x, int y) + int x, int y, osg::ref_ptr land) { // For the first/last row/column, we need to get the texture from the neighbour cell // to get consistent blending at the borders @@ -323,22 +323,27 @@ namespace ESMTerrain { --cellX; x += ESM::Land::LAND_TEXTURE_SIZE; + land = NULL; } while (x >= ESM::Land::LAND_TEXTURE_SIZE) { ++cellX; x -= ESM::Land::LAND_TEXTURE_SIZE; + land = NULL; } while (y >= ESM::Land::LAND_TEXTURE_SIZE) // Y appears to be wrapped from the other side because why the hell not? { ++cellY; y -= ESM::Land::LAND_TEXTURE_SIZE; + land = NULL; } assert(x land = getLand(cellX, cellY); + if (!land) + land = getLand(cellX, cellY); + const ESM::Land::LandData *data = land ? land->getData(ESM::Land::DATA_VTEX) : 0; if (data) { @@ -393,10 +398,12 @@ namespace ESMTerrain // So we're always adding _land_default.dds as the base layer here, even if it's not referenced in this cell. textureIndices.insert(std::make_pair(0,0)); + osg::ref_ptr land = getLand(cellX, cellY); + for (int y=colStart; ysecond; int blendIndex = (pack ? static_cast(std::floor((layerIndex - 1) / 4.f)) : layerIndex - 1); diff --git a/components/esmterrain/storage.hpp b/components/esmterrain/storage.hpp index e159313c5..8c4ec230f 100644 --- a/components/esmterrain/storage.hpp +++ b/components/esmterrain/storage.hpp @@ -117,7 +117,7 @@ namespace ESMTerrain typedef std::pair UniqueTextureId; UniqueTextureId getVtexIndexAt(int cellX, int cellY, - int x, int y); + int x, int y, osg::ref_ptr land); std::string getTextureName (UniqueTextureId id); std::map mLayerInfoMap;