diff --git a/modules/globebrowsing/other/tileprovider.cpp b/modules/globebrowsing/other/tileprovider.cpp index 373c6463b5..57b463f559 100644 --- a/modules/globebrowsing/other/tileprovider.cpp +++ b/modules/globebrowsing/other/tileprovider.cpp @@ -81,9 +81,10 @@ namespace openspace { } - Tile TileProvider::getHighestResolutionTile( - ChunkIndex chunkIndex, - TileUvTransform uvTransform) { + Tile TileProvider::getHighestResolutionTile(ChunkIndex chunkIndex, int nthHighest) { + TileUvTransform uvTransform; + uvTransform.uvOffset = glm::vec2(0, 0); + uvTransform.uvScale = glm::vec2(1, 1); int maximumLevel = _asyncTextureDataProvider->getTextureDataProvider()->getMaximumLevel(); @@ -92,30 +93,22 @@ namespace openspace { chunkIndex = chunkIndex.parent(); } - return getOrEnqueueHighestResolutionTile(chunkIndex, uvTransform); - } - - Tile TileProvider::getHighestResolutionParentTile(ChunkIndex chunkIndex, int levelOffset) { - TileUvTransform uvTransform; - uvTransform.uvOffset = glm::vec2(0, 0); - uvTransform.uvScale = glm::vec2(1, 1); - - for (int i = 0; i < levelOffset && chunkIndex.level > 1; i++) { - transformFromParent(chunkIndex, uvTransform); - chunkIndex = chunkIndex.parent(); - } - - Tile toReturn = getHighestResolutionTile(chunkIndex, uvTransform); - return toReturn; + return getOrEnqueueHighestResolutionTile(chunkIndex, uvTransform, nthHighest); } Tile TileProvider::getOrEnqueueHighestResolutionTile(const ChunkIndex& chunkIndex, - TileUvTransform& uvTransform) + TileUvTransform& uvTransform, int nthHighest) { + HashKey key = chunkIndex.hashKey(); - if (_tileCache.exist(key) && _tileCache.get(key).ioError == CPLErr::CE_None) { - std::shared_ptr texture = _tileCache.get(key).texture; - return { texture, uvTransform }; + bool goodTileExists = _tileCache.exist(key) && _tileCache.get(key).ioError == CPLErr::CE_None; + if (goodTileExists) { + if (nthHighest > 0) { + transformFromParent(chunkIndex, uvTransform); + return getOrEnqueueHighestResolutionTile( + chunkIndex.parent(), uvTransform, nthHighest - 1); + } + else return { _tileCache.get(key).texture, uvTransform }; } else if (chunkIndex.level < 1) { return { nullptr, uvTransform }; @@ -124,7 +117,7 @@ namespace openspace { // We don't have the tile for the requested level // --> check if the parent has a tile we can use transformFromParent(chunkIndex, uvTransform); - Tile tile = getOrEnqueueHighestResolutionTile(chunkIndex.parent(), uvTransform); + Tile tile = getOrEnqueueHighestResolutionTile(chunkIndex.parent(), uvTransform, nthHighest); // As we didn't have this tile, push it to the request queue // post order enqueueing tiles --> enqueue tiles at low levels first diff --git a/modules/globebrowsing/other/tileprovider.h b/modules/globebrowsing/other/tileprovider.h index b92fe03f24..b69f2c06df 100644 --- a/modules/globebrowsing/other/tileprovider.h +++ b/modules/globebrowsing/other/tileprovider.h @@ -46,28 +46,27 @@ namespace openspace { using namespace ghoul::opengl; - - + struct TileUvTransform { glm::vec2 uvOffset; glm::vec2 uvScale; }; - - - + struct Tile { std::shared_ptr texture; TileUvTransform uvTransform; }; - - + struct MetaTexture { std::shared_ptr texture; CPLErr ioError; }; + + + /** Provides tiles through GDAL datasets which can be defined with xml files for example for wms. @@ -78,36 +77,26 @@ namespace openspace { TileProvider(std::shared_ptr tileReader, int tileCacheSize, int framesUntilFlushRequestQueue); - ~TileProvider(); - Tile getHighestResolutionTile(ChunkIndex chunkIndex, - TileUvTransform uvTransform = {glm::vec2(0.0f,0.0f), glm::vec2(1.0f,1.0f)}); - /** - \param levelOffset gives a tile from a parent chunk with that particular - offset. For example levelOffset = 1 gives the first parent and levelOffset = 2 - gives the grand parent. - */ - Tile getHighestResolutionParentTile(ChunkIndex chunkIndex, int levelOffset = 1); + + Tile getHighestResolutionTile(ChunkIndex chunkIndex, int nthHighest = 0); - std::shared_ptr getOrStartFetchingTile(ChunkIndex chunkIndex); TileDepthTransform depthTransform(); void prerender(); - static ThreadPool threadPool; - private: - friend class TileLoadJob; - - ////////////////////////////////////////////////////////////////////////////////// // Helper functions // ////////////////////////////////////////////////////////////////////////////////// - Tile getOrEnqueueHighestResolutionTile(const ChunkIndex& ci, TileUvTransform& uvTransform); + Tile getOrEnqueueHighestResolutionTile(const ChunkIndex& ci, + TileUvTransform& uvTransform, int nthHighest); + + std::shared_ptr getOrStartFetchingTile(ChunkIndex chunkIndex); void transformFromParent(const ChunkIndex& ci, TileUvTransform& uv) const; diff --git a/modules/globebrowsing/rendering/patchrenderer.cpp b/modules/globebrowsing/rendering/patchrenderer.cpp index d3eee02d6e..2b2bc420d1 100644 --- a/modules/globebrowsing/rendering/patchrenderer.cpp +++ b/modules/globebrowsing/rendering/patchrenderer.cpp @@ -166,18 +166,23 @@ namespace openspace { auto tileProvider = it->get(); // Get the texture that should be used for rendering Tile tile = tileProvider->getHighestResolutionTile(chunk.index()); - Tile tileParent1 = tileProvider->getHighestResolutionParentTile(chunk.index(), 1); - Tile tileParent2 = tileProvider->getHighestResolutionParentTile(chunk.index(), 2); - - if (tile.texture == nullptr || - tileParent1.texture == nullptr || - tileParent2.texture == nullptr) - { + Tile tileParent1 = tileProvider->getHighestResolutionTile(chunk.index(), 1); + Tile tileParent2 = tileProvider->getHighestResolutionTile(chunk.index(), 2); + + if (tile.texture == nullptr) { // don't render if no tile was available programObject->deactivate(); return; } + if (tileParent1.texture == nullptr) { + tileParent1 = tile; + } + if (tileParent2.texture == nullptr) { + tileParent2 = tileParent1; + } + + TileDepthTransform depthTransform = tileProvider->depthTransform(); // The texture needs a unit to sample from @@ -247,19 +252,23 @@ namespace openspace { auto tileProvider = it->get(); // Get the texture that should be used for rendering Tile tile = tileProvider->getHighestResolutionTile(chunk.index()); - Tile tileParent1 = tileProvider->getHighestResolutionParentTile(chunk.index(), 1); - Tile tileParent2 = tileProvider->getHighestResolutionParentTile(chunk.index(), 2); + Tile tileParent1 = tileProvider->getHighestResolutionTile(chunk.index(), 1); + Tile tileParent2 = tileProvider->getHighestResolutionTile(chunk.index(), 2); - if (tile.texture == nullptr || - tileParent1.texture == nullptr || - tileParent2.texture == nullptr) - { + if (tile.texture == nullptr) { // don't render if no tile was available programObject->deactivate(); return; } + if (tileParent1.texture == nullptr) { + tileParent1 = tile; + } + if (tileParent2.texture == nullptr) { + tileParent2 = tileParent1; + } + // The texture needs a unit to sample from texUnitColor[i].activate(); tile.texture->bind(); @@ -410,18 +419,22 @@ namespace openspace { auto tileProvider = it->get(); // Get the texture that should be used for rendering Tile tile = tileProvider->getHighestResolutionTile(chunk.index()); - Tile tileParent1 = tileProvider->getHighestResolutionParentTile(chunk.index(), 1); - Tile tileParent2 = tileProvider->getHighestResolutionParentTile(chunk.index(), 2); + Tile tileParent1 = tileProvider->getHighestResolutionTile(chunk.index(), 1); + Tile tileParent2 = tileProvider->getHighestResolutionTile(chunk.index(), 2); - if (tile.texture == nullptr || - tileParent1.texture == nullptr || - tileParent2.texture == nullptr) - { + if (tile.texture == nullptr) { // don't render if no tile was available programObject->deactivate(); return; } + if (tileParent1.texture == nullptr) { + tileParent1 = tile; + } + if (tileParent2.texture == nullptr) { + tileParent2 = tileParent1; + } + TileDepthTransform depthTransform = tileProvider->depthTransform(); // The texture needs a unit to sample from @@ -490,19 +503,23 @@ namespace openspace { auto tileProvider = it->get(); // Get the texture that should be used for rendering Tile tile = tileProvider->getHighestResolutionTile(chunk.index()); - Tile tileParent1 = tileProvider->getHighestResolutionParentTile(chunk.index(), 1); - Tile tileParent2 = tileProvider->getHighestResolutionParentTile(chunk.index(), 2); + Tile tileParent1 = tileProvider->getHighestResolutionTile(chunk.index(), 1); + Tile tileParent2 = tileProvider->getHighestResolutionTile(chunk.index(), 2); - if (tile.texture == nullptr || - tileParent1.texture == nullptr || - tileParent2.texture == nullptr) - { + if (tile.texture == nullptr) { // don't render if no tile was available programObject->deactivate(); return; } + if (tileParent1.texture == nullptr) { + tileParent1 = tile; + } + if (tileParent2.texture == nullptr) { + tileParent2 = tileParent1; + } + // The texture needs a unit to sample from texUnitColor[i].activate(); tile.texture->bind();