From 528cda803293d5ebb5cb1d42c533001b1d5bd7d8 Mon Sep 17 00:00:00 2001 From: bzzt Date: Wed, 20 Feb 2019 13:37:00 +0000 Subject: [PATCH] Prevent layers duplication when a terrain chunk crosses plugin borders --- components/esmterrain/storage.cpp | 41 ++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/components/esmterrain/storage.cpp b/components/esmterrain/storage.cpp index f69cbb133..c8d31c41c 100644 --- a/components/esmterrain/storage.cpp +++ b/components/esmterrain/storage.cpp @@ -387,25 +387,42 @@ namespace ESMTerrain const int blendmapImageSize = blendmapSize * imageScaleFactor; LandCache cache; - std::map textureIndicesMap; + std::map textureIndicesMap; - for (int y=0; y::iterator found = textureIndicesMap.find(id); + std::map::iterator found = textureIndicesMap.find(id); if (found == textureIndicesMap.end()) { - found = textureIndicesMap.insert(std::make_pair(id, textureIndicesMap.size())).first; - layerList.push_back(getLayerInfo(getTextureName(id))); - osg::ref_ptr image (new osg::Image); - image->allocateImage(blendmapImageSize, blendmapImageSize, 1, GL_ALPHA, GL_UNSIGNED_BYTE); - unsigned char* pData = image->data(); - memset(pData, 0, image->getTotalDataSize()); - blendmaps.push_back(image); + unsigned int layerIndex = layerList.size(); + Terrain::LayerInfo info = getLayerInfo(getTextureName(id)); + + // look for existing diffuse map, which may be present when several plugins use the same texture + for (unsigned int i=0; i= layerList.size()) + { + osg::ref_ptr image (new osg::Image); + image->allocateImage(blendmapImageSize, blendmapImageSize, 1, GL_ALPHA, GL_UNSIGNED_BYTE); + unsigned char* pData = image->data(); + memset(pData, 0, image->getTotalDataSize()); + blendmaps.emplace_back(image); + layerList.emplace_back(info); + } } - int layerIndex = found->second; + unsigned int layerIndex = found->second; unsigned char* pData = blendmaps[layerIndex]->data(); int realY = (blendmapSize - y - 1)*imageScaleFactor; int realX = x*imageScaleFactor;