diff --git a/modules/globebrowsing/CMakeLists.txt b/modules/globebrowsing/CMakeLists.txt index 857d3e7f37..1a78c34378 100644 --- a/modules/globebrowsing/CMakeLists.txt +++ b/modules/globebrowsing/CMakeLists.txt @@ -51,7 +51,8 @@ set(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/other/distanceswitch.h ${CMAKE_CURRENT_SOURCE_DIR}/other/patchcoverageprovider.h ${CMAKE_CURRENT_SOURCE_DIR}/other/tileprovider.h - ${CMAKE_CURRENT_SOURCE_DIR}/other/texturedataprovider.h + ${CMAKE_CURRENT_SOURCE_DIR}/other/tiledataset.h + ${CMAKE_CURRENT_SOURCE_DIR}/other/asynctilereader.h ${CMAKE_CURRENT_SOURCE_DIR}/other/lrucache.h ${CMAKE_CURRENT_SOURCE_DIR}/other/concurrentjobmanager.h ${CMAKE_CURRENT_SOURCE_DIR}/other/threadpool.h @@ -87,7 +88,8 @@ set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/other/distanceswitch.cpp ${CMAKE_CURRENT_SOURCE_DIR}/other/patchcoverageprovider.cpp ${CMAKE_CURRENT_SOURCE_DIR}/other/tileprovider.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/other/texturedataprovider.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/other/tiledataset.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/other/asynctilereader.cpp ${CMAKE_CURRENT_SOURCE_DIR}/other/lrucache.inl ${CMAKE_CURRENT_SOURCE_DIR}/other/concurrentjobmanager.inl ${CMAKE_CURRENT_SOURCE_DIR}/other/threadpool.cpp diff --git a/modules/globebrowsing/other/asynctexturedataprovider.cpp b/modules/globebrowsing/other/asynctexturedataprovider.cpp new file mode 100644 index 0000000000..3885aecd1a --- /dev/null +++ b/modules/globebrowsing/other/asynctexturedataprovider.cpp @@ -0,0 +1,113 @@ + /***************************************************************************************** +* * +* OpenSpace * +* * +* Copyright (c) 2014-2016 * +* * +* Permission is hereby granted, free of charge, to any person obtaining a copy of this * +* software and associated documentation files (the "Software"), to deal in the Software * +* without restriction, including without limitation the rights to use, copy, modify, * +* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * +* permit persons to whom the Software is furnished to do so, subject to the following * +* conditions: * +* * +* The above copyright notice and this permission notice shall be included in all copies * +* or substantial portions of the Software. * +* * +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * +* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * +* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * +* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * +* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * +* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * +****************************************************************************************/ + + +#include +#include // abspath +#include + +#include +#include +#include + +namespace { + const std::string _loggerCat = "AsyncTextureDataProvider"; +} + + + +namespace openspace { + + + AsyncTileDataProvider::AsyncTileDataProvider(const std::string& filename, int minNumPixels, ThreadPool& pool) + : _textureDataProvider(std::shared_ptr(new TileDataset(filename, minNumPixels))) + , _concurrentJobManager(pool) + { + + } + + AsyncTileDataProvider::AsyncTileDataProvider( + std::shared_ptr textureDataProvider, + ThreadPool& pool) + : _textureDataProvider(textureDataProvider) + , _concurrentJobManager(pool) + { + + } + + AsyncTileDataProvider::~AsyncTileDataProvider() { + + } + + + std::shared_ptr AsyncTileDataProvider::getTextureDataProvider() const { + return _textureDataProvider; + } + + bool AsyncTileDataProvider::enqueueTextureData(const ChunkIndex& chunkIndex) { + if (satisfiesEnqueueCriteria(chunkIndex)) { + std::shared_ptr job = std::shared_ptr( + new TileLoadJob(_textureDataProvider, chunkIndex)); + + _concurrentJobManager.enqueueJob(job); + _enqueuedTileRequests[chunkIndex.hashKey()] = chunkIndex; + return true; + } + return false; + } + + bool AsyncTileDataProvider::hasLoadedTextureData() const{ + return _concurrentJobManager.numFinishedJobs() > 0; + } + + std::shared_ptr AsyncTileDataProvider::nextTileIOResult() { + auto tileIOResult = _concurrentJobManager.popFinishedJob()->product(); + HashKey key = tileIOResult->rawTileData->chunkIndex.hashKey(); + if (_enqueuedTileRequests.find(key) != _enqueuedTileRequests.end()) { + _enqueuedTileRequests.erase(key); + } + return tileIOResult; + } + + + bool AsyncTileDataProvider::satisfiesEnqueueCriteria(const ChunkIndex& chunkIndex) const { + auto it = _enqueuedTileRequests.begin(); + auto end = _enqueuedTileRequests.end(); + for (; it != end; it++) { + const ChunkIndex& otherChunk = it->second; + if (chunkIndex.level == otherChunk.level && + chunkIndex.manhattan(otherChunk) < 1) { + return false; + } + } + return true; + } + + + void AsyncTileDataProvider::clearRequestQueue() { + _concurrentJobManager.clearEnqueuedJobs(); + _enqueuedTileRequests.clear(); + } + +} // namespace openspace diff --git a/modules/globebrowsing/other/asynctilereader.cpp b/modules/globebrowsing/other/asynctilereader.cpp new file mode 100644 index 0000000000..05ae7a6714 --- /dev/null +++ b/modules/globebrowsing/other/asynctilereader.cpp @@ -0,0 +1,113 @@ + /***************************************************************************************** +* * +* OpenSpace * +* * +* Copyright (c) 2014-2016 * +* * +* Permission is hereby granted, free of charge, to any person obtaining a copy of this * +* software and associated documentation files (the "Software"), to deal in the Software * +* without restriction, including without limitation the rights to use, copy, modify, * +* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * +* permit persons to whom the Software is furnished to do so, subject to the following * +* conditions: * +* * +* The above copyright notice and this permission notice shall be included in all copies * +* or substantial portions of the Software. * +* * +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * +* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * +* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * +* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * +* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * +* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * +****************************************************************************************/ + + +#include +#include // abspath +#include + +#include +#include +#include + +namespace { + const std::string _loggerCat = "AsyncTextureDataProvider"; +} + + + +namespace openspace { + + + AsyncTileDataProvider::AsyncTileDataProvider(const std::string& filename, int minNumPixels, ThreadPool& pool) + : _textureDataProvider(std::shared_ptr(new TileDataset(filename, minNumPixels))) + , _concurrentJobManager(pool) + { + + } + + AsyncTileDataProvider::AsyncTileDataProvider( + std::shared_ptr textureDataProvider, + ThreadPool& pool) + : _textureDataProvider(textureDataProvider) + , _concurrentJobManager(pool) + { + + } + + AsyncTileDataProvider::~AsyncTileDataProvider() { + + } + + + std::shared_ptr AsyncTileDataProvider::getTextureDataProvider() const { + return _textureDataProvider; + } + + bool AsyncTileDataProvider::enqueueTextureData(const ChunkIndex& chunkIndex) { + if (satisfiesEnqueueCriteria(chunkIndex)) { + std::shared_ptr job = std::shared_ptr( + new TileLoadJob(_textureDataProvider, chunkIndex)); + + _concurrentJobManager.enqueueJob(job); + _enqueuedTileRequests[chunkIndex.hashKey()] = chunkIndex; + return true; + } + return false; + } + + bool AsyncTileDataProvider::hasLoadedTextureData() const{ + return _concurrentJobManager.numFinishedJobs() > 0; + } + + std::shared_ptr AsyncTileDataProvider::nextTileIOResult() { + auto tileIOResult = _concurrentJobManager.popFinishedJob()->product(); + HashKey key = tileIOResult->rawTileData->chunkIndex.hashKey(); + if (_enqueuedTileRequests.find(key) != _enqueuedTileRequests.end()) { + _enqueuedTileRequests.erase(key); + } + return tileIOResult; + } + + + bool AsyncTileDataProvider::satisfiesEnqueueCriteria(const ChunkIndex& chunkIndex) const { + auto it = _enqueuedTileRequests.begin(); + auto end = _enqueuedTileRequests.end(); + for (; it != end; it++) { + const ChunkIndex& otherChunk = it->second; + if (chunkIndex.level == otherChunk.level && + chunkIndex.manhattan(otherChunk) < 1) { + return false; + } + } + return true; + } + + + void AsyncTileDataProvider::clearRequestQueue() { + _concurrentJobManager.clearEnqueuedJobs(); + _enqueuedTileRequests.clear(); + } + +} // namespace openspace diff --git a/modules/globebrowsing/other/asynctilereader.h b/modules/globebrowsing/other/asynctilereader.h new file mode 100644 index 0000000000..740f071192 --- /dev/null +++ b/modules/globebrowsing/other/asynctilereader.h @@ -0,0 +1,121 @@ +/***************************************************************************************** +* * +* OpenSpace * +* * +* Copyright (c) 2014-2016 * +* * +* Permission is hereby granted, free of charge, to any person obtaining a copy of this * +* software and associated documentation files (the "Software"), to deal in the Software * +* without restriction, including without limitation the rights to use, copy, modify, * +* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * +* permit persons to whom the Software is furnished to do so, subject to the following * +* conditions: * +* * +* The above copyright notice and this permission notice shall be included in all copies * +* or substantial portions of the Software. * +* * +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * +* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * +* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * +* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * +* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * +* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * +****************************************************************************************/ + + +#ifndef __ASYNC_TILE_DATA_PROVIDER_H__ +#define __ASYNC_TILE_DATA_PROVIDER_H__ + +//#include + +#include + +#include + +#include +#include +#include + +#include +#include +#include + + + +namespace openspace { + + + + struct TileLoadJob : public Job { + TileLoadJob(std::shared_ptr textureDataProvider, + const ChunkIndex& chunkIndex) + : _textureDataProvider(textureDataProvider) + , _chunkIndex(chunkIndex) + { + + } + + virtual ~TileLoadJob() { } + + virtual void execute() { + _uninitedTexture = _textureDataProvider->readTileData(_chunkIndex); + } + + + + virtual std::shared_ptr product() { + return _uninitedTexture; + } + + + private: + ChunkIndex _chunkIndex; + std::shared_ptr _textureDataProvider; + std::shared_ptr _uninitedTexture; + }; + + + + + + class AsyncTileDataProvider { + public: + + AsyncTileDataProvider(const std::string& filename, int minNumPixels, ThreadPool& pool); + AsyncTileDataProvider(std::shared_ptr textureDataProvider, + ThreadPool& pool); + + ~AsyncTileDataProvider(); + + + + bool enqueueTextureData(const ChunkIndex& chunkIndex); + bool hasLoadedTextureData() const; + std::shared_ptr nextTileIOResult(); + + void clearRequestQueue(); + + std::shared_ptr getTextureDataProvider() const; + + protected: + + virtual bool satisfiesEnqueueCriteria(const ChunkIndex&) const; + + private: + + std::shared_ptr _textureDataProvider; + ConcurrentJobManager _concurrentJobManager; + std::unordered_map _enqueuedTileRequests; + + + }; + + + +} // namespace openspace + + + + + +#endif // __ASYNC_TILE_DATA_PROVIDER_H__ \ No newline at end of file diff --git a/modules/globebrowsing/other/concurrentjobmanager.h b/modules/globebrowsing/other/concurrentjobmanager.h index 785ebfca30..1438a2c8a4 100644 --- a/modules/globebrowsing/other/concurrentjobmanager.h +++ b/modules/globebrowsing/other/concurrentjobmanager.h @@ -90,7 +90,7 @@ namespace openspace { return _finishedJobs.pop(); } - size_t numFinishedJobs() { + size_t numFinishedJobs() const{ return _finishedJobs.size(); } diff --git a/modules/globebrowsing/other/concurrentqueue.h b/modules/globebrowsing/other/concurrentqueue.h index 7b1f27e7ed..2694fc2de7 100644 --- a/modules/globebrowsing/other/concurrentqueue.h +++ b/modules/globebrowsing/other/concurrentqueue.h @@ -77,7 +77,7 @@ public: _cond.notify_one(); } - size_t size() { + size_t size() const{ std::unique_lock mlock(_mutex); size_t s = _queue.size(); mlock.unlock(); @@ -87,8 +87,8 @@ public: private: std::queue _queue; - std::mutex _mutex; - std::condition_variable _cond; + mutable std::mutex _mutex; + mutable std::condition_variable _cond; }; } diff --git a/modules/globebrowsing/other/texturedataprovider.cpp b/modules/globebrowsing/other/tiledataset.cpp similarity index 91% rename from modules/globebrowsing/other/texturedataprovider.cpp rename to modules/globebrowsing/other/tiledataset.cpp index 5f520c444c..03cb0914cf 100644 --- a/modules/globebrowsing/other/texturedataprovider.cpp +++ b/modules/globebrowsing/other/tiledataset.cpp @@ -27,12 +27,12 @@ #include // abspath #include -#include +#include #include #include namespace { - const std::string _loggerCat = "TextureDataProvider"; + const std::string _loggerCat = "TileDataset"; } @@ -40,9 +40,9 @@ namespace { namespace openspace { // INIT THIS TO FALSE AFTER REMOVED FROM TILEPROVIDER - bool TextureDataProvider::GdalHasBeenInitialized = false; + bool TileDataset::GdalHasBeenInitialized = false; - TextureDataProvider::TextureDataProvider(const std::string& fileName, int minimumPixelSize) + TileDataset::TileDataset(const std::string& fileName, int minimumPixelSize) : _minimumPixelSize(minimumPixelSize) { @@ -59,18 +59,18 @@ namespace openspace { } - TextureDataProvider::~TextureDataProvider() { + TileDataset::~TileDataset() { delete _dataset; } - int TextureDataProvider::calculateTileLevelDifference(GDALDataset* dataset, int minimumPixelSize) { + int TileDataset::calculateTileLevelDifference(GDALDataset* dataset, int minimumPixelSize) { GDALRasterBand* firstBand = dataset->GetRasterBand(1); int numOverviews = firstBand->GetOverviewCount(); int sizeLevel0 = firstBand->GetOverview(numOverviews - 1)->GetXSize(); return log2(minimumPixelSize) - log2(sizeLevel0); } - TileDepthTransform TextureDataProvider::calculateTileDepthTransform() { + TileDepthTransform TileDataset::calculateTileDepthTransform() { GDALRasterBand* firstBand = _dataset->GetRasterBand(1); GDALDataType gdalType = firstBand->GetRasterDataType(); @@ -83,17 +83,17 @@ namespace openspace { return transform; } - int TextureDataProvider::getMaximumLevel() const { + int TileDataset::getMaximumLevel() const { int numOverviews = _dataset->GetRasterBand(1)->GetOverviewCount(); int maximumLevel = numOverviews - 1 - _tileLevelDifference; return maximumLevel; } - TileDepthTransform TextureDataProvider::getDepthTransform() const { + TileDepthTransform TileDataset::getDepthTransform() const { return _depthTransform; } - std::shared_ptr TextureDataProvider::getTextureData(ChunkIndex chunkIndex) + std::shared_ptr TileDataset::readTileData(ChunkIndex chunkIndex) { GdalDataRegion region(_dataset, chunkIndex, _tileLevelDifference); DataLayout dataLayout(_dataset, region); @@ -135,7 +135,7 @@ namespace openspace { } - std::shared_ptr TextureDataProvider::createRawTileData(const GdalDataRegion& region, + std::shared_ptr TileDataset::createRawTileData(const GdalDataRegion& region, const DataLayout& dataLayout, const char* imageData) { @@ -168,7 +168,7 @@ namespace openspace { - size_t TextureDataProvider::numberOfBytes(GDALDataType gdalType) { + size_t TileDataset::numberOfBytes(GDALDataType gdalType) { switch (gdalType) { case GDT_Byte: return sizeof(GLubyte); case GDT_UInt16: return sizeof(GLushort); @@ -184,7 +184,7 @@ namespace openspace { } - glm::uvec2 TextureDataProvider::geodeticToPixel(GDALDataset* dataSet, const Geodetic2& geo) { + glm::uvec2 TileDataset::geodeticToPixel(GDALDataset* dataSet, const Geodetic2& geo) { double padfTransform[6]; CPLErr err = dataSet->GetGeoTransform(padfTransform); @@ -222,7 +222,7 @@ namespace openspace { } - RawTileData::TextureFormat TextureDataProvider::getTextureFormat( + RawTileData::TextureFormat TileDataset::getTextureFormat( int rasterCount, GDALDataType gdalType) { RawTileData::TextureFormat format; @@ -292,7 +292,7 @@ namespace openspace { - GLuint TextureDataProvider::getOpenGLDataType(GDALDataType gdalType) { + GLuint TileDataset::getOpenGLDataType(GDALDataType gdalType) { switch (gdalType) { case GDT_Byte: return GL_UNSIGNED_BYTE; case GDT_UInt16: return GL_UNSIGNED_SHORT; @@ -308,7 +308,7 @@ namespace openspace { } - TextureDataProvider::GdalDataRegion::GdalDataRegion(GDALDataset * dataSet, + TileDataset::GdalDataRegion::GdalDataRegion(GDALDataset * dataSet, const ChunkIndex& chunkIndex, int tileLevelDifference) : chunkIndex(chunkIndex) { @@ -352,7 +352,7 @@ namespace openspace { } - TextureDataProvider::DataLayout::DataLayout(GDALDataset* dataSet, const GdalDataRegion& region) { + TileDataset::DataLayout::DataLayout(GDALDataset* dataSet, const GdalDataRegion& region) { // Assume all raster bands have the same data type gdalType = dataSet->GetRasterBand(1)->GetRasterDataType(); bytesPerDatum = numberOfBytes(gdalType); diff --git a/modules/globebrowsing/other/texturedataprovider.h b/modules/globebrowsing/other/tiledataset.h similarity index 94% rename from modules/globebrowsing/other/texturedataprovider.h rename to modules/globebrowsing/other/tiledataset.h index 0bf8030946..a5fbd94c49 100644 --- a/modules/globebrowsing/other/texturedataprovider.h +++ b/modules/globebrowsing/other/tiledataset.h @@ -22,8 +22,8 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#ifndef __TEXTURE_DATA_PROVIDER_H__ -#define __TEXTURE_DATA_PROVIDER_H__ +#ifndef __TILE_DATASET_H__ +#define __TILE_DATASET_H__ //#include @@ -86,14 +86,14 @@ namespace openspace { - class TextureDataProvider { + class TileDataset { public: - TextureDataProvider(const std::string& fileName, int minimumPixelSize); - ~TextureDataProvider(); + TileDataset(const std::string& fileName, int minimumPixelSize); + ~TileDataset(); - std::shared_ptr getTextureData(ChunkIndex chunkIndex); + std::shared_ptr readTileData(ChunkIndex chunkIndex); int getMaximumLevel() const; @@ -184,4 +184,4 @@ namespace openspace { -#endif // __TEXTURE_DATA_PROVIDER_H__ \ No newline at end of file +#endif // __TILE_DATASET_H__ \ No newline at end of file diff --git a/modules/globebrowsing/other/tileprovider.cpp b/modules/globebrowsing/other/tileprovider.cpp index c099342090..aee4773056 100644 --- a/modules/globebrowsing/other/tileprovider.cpp +++ b/modules/globebrowsing/other/tileprovider.cpp @@ -54,12 +54,10 @@ namespace openspace { int tileCacheSize, int minimumPixelSize, int framesUntilRequestFlush) - : _filePath(filePath) - , _tileCache(tileCacheSize) // setting cache size + : _tileCache(tileCacheSize) // setting cache size , _framesSinceLastRequestFlush(0) , _framesUntilRequestFlush(framesUntilRequestFlush) - , _tileLoadManager(TileProviderManager::tileRequestThreadPool) - , _rawTextureTileDataProvider(filePath, minimumPixelSize) + , _asyncTextureDataProvider(filePath, minimumPixelSize, TileProviderManager::tileRequestThreadPool) { // Set a temporary texture std::string fileName = "textures/earth_bluemarble.jpg"; @@ -75,7 +73,6 @@ namespace openspace { _defaultTexture->setFilter(ghoul::opengl::Texture::FilterMode::Linear); _defaultTexture->setWrapping(ghoul::opengl::Texture::WrappingMode::ClampToBorder); } - } TileProvider::~TileProvider(){ @@ -84,30 +81,21 @@ namespace openspace { void TileProvider::prerender() { - //_rawTextureTileDataProvider.updateAsyncRequests(); initTexturesFromLoadedData(); - if (_framesSinceLastRequestFlush++ > _framesUntilRequestFlush) { clearRequestQueue(); } } void TileProvider::initTexturesFromLoadedData() { - while (_tileLoadManager.numFinishedJobs() > 0) { - std::shared_ptr tileIOResult= _tileLoadManager.popFinishedJob()->product(); + while (_asyncTextureDataProvider.hasLoadedTextureData()) { + std::shared_ptr tileIOResult = _asyncTextureDataProvider.nextTileIOResult(); initializeAndAddToCache(tileIOResult); } - /* - while (_rawTextureTileDataProvider.hasTextureTileData()) { - auto rawTextureTile = _rawTextureTileDataProvider.nextTextureTile(); - initializeAndAddToCache(rawTextureTile); - } - */ } void TileProvider::clearRequestQueue() { - _tileLoadManager.clearEnqueuedJobs(); - _queuedTileRequests.clear(); + _asyncTextureDataProvider.clearRequestQueue(); _framesSinceLastRequestFlush = 0; } @@ -117,7 +105,7 @@ namespace openspace { uvTransform.uvOffset = glm::vec2(0, 0); uvTransform.uvScale = glm::vec2(1, 1); - int maximumLevel = _rawTextureTileDataProvider.getMaximumLevel(); + int maximumLevel = _asyncTextureDataProvider.getTextureDataProvider()->getMaximumLevel(); while(chunkIndex.level > maximumLevel){ transformFromParent(chunkIndex, uvTransform); @@ -146,7 +134,7 @@ namespace openspace { // As we didn't have this tile, push it to the request queue // post order enqueueing tiles --> enqueue tiles at low levels first - enqueueTileRequest(chunkIndex); + _asyncTextureDataProvider.enqueueTextureData(chunkIndex); return tile; } @@ -175,51 +163,21 @@ namespace openspace { return _tileCache.get(hashkey).texture; } else { - enqueueTileRequest(chunkIndex); + _asyncTextureDataProvider.enqueueTextureData(chunkIndex); return nullptr; } } - bool TileProvider::enqueueTileRequest(const ChunkIndex& chunkIndex) { - HashKey key = chunkIndex.hashKey(); - auto it = _queuedTileRequests.begin(); - auto end = _queuedTileRequests.end(); - for (; it != end; it++) { - const ChunkIndex& otherChunk = it->second; - if (chunkIndex.level == otherChunk.level && - chunkIndex.manhattan(otherChunk) < 1) { - return false; - } - } - - - std::shared_ptr job = std::shared_ptr( - new TextureTileLoadJob(this, chunkIndex)); - _tileLoadManager.enqueueJob(job); - _queuedTileRequests[key] = chunkIndex; - - return true; - } - - std::shared_ptr TileProvider::getDefaultTexture() { return _defaultTexture; } TileDepthTransform TileProvider::depthTransform() { - return _rawTextureTileDataProvider.getDepthTransform(); + return _asyncTextureDataProvider.getTextureDataProvider()->getDepthTransform(); } - std::shared_ptr TileProvider::syncDownloadData( - const ChunkIndex& chunkIndex) { - - std::shared_ptr res = _rawTextureTileDataProvider.getTextureData(chunkIndex); - - return res; - } - void TileProvider::initializeAndAddToCache(std::shared_ptr tileIOResult) { std::shared_ptr tileData = tileIOResult->rawTileData; diff --git a/modules/globebrowsing/other/tileprovider.h b/modules/globebrowsing/other/tileprovider.h index f1eb237da4..9609a2f783 100644 --- a/modules/globebrowsing/other/tileprovider.h +++ b/modules/globebrowsing/other/tileprovider.h @@ -37,8 +37,7 @@ #include #include -#include -#include +#include ////////////////////////////////////////////////////////////////////////////////////////// // TILE PROVIDER // @@ -92,7 +91,7 @@ namespace openspace { private: - friend class TextureTileLoadJob; + friend class TileLoadJob; @@ -104,11 +103,7 @@ namespace openspace { void transformFromParent(const ChunkIndex& ci, TileUvTransform& uv) const; - /** - Fetches all the needeed texture data from the GDAL dataset. - */ - std::shared_ptr syncDownloadData( - const ChunkIndex& chunkIndex); + /** Creates an OpenGL texture and pushes the data to the GPU. @@ -116,8 +111,6 @@ namespace openspace { void initializeAndAddToCache( std::shared_ptr uninitedTexture); - bool enqueueTileRequest(const ChunkIndex& ci); - void clearRequestQueue(); void initTexturesFromLoadedData(); @@ -131,17 +124,12 @@ namespace openspace { ////////////////////////////////////////////////////////////////////////////////// LRUCache _tileCache; - std::unordered_map _queuedTileRequests; int _framesSinceLastRequestFlush; int _framesUntilRequestFlush; - const std::string _filePath; - - TextureDataProvider _rawTextureTileDataProvider; - - ConcurrentJobManager _tileLoadManager; + AsyncTileDataProvider _asyncTextureDataProvider; std::shared_ptr _defaultTexture; @@ -155,38 +143,4 @@ namespace openspace { - - - - - -namespace openspace { - - using namespace ghoul::opengl; - - struct TextureTileLoadJob : public Job { - TextureTileLoadJob(TileProvider * tileProvider, const ChunkIndex& chunkIndex) - : _tileProvider(tileProvider) - , _chunkIndex(chunkIndex) { - - } - - virtual ~TextureTileLoadJob() { } - - virtual void execute() { - _uninitedTexture = _tileProvider->syncDownloadData(_chunkIndex); - } - - virtual std::shared_ptr product() { - return _uninitedTexture; - } - - - private: - ChunkIndex _chunkIndex; - TileProvider * _tileProvider; - std::shared_ptr _uninitedTexture; - }; -} - #endif // __TILE_PROVIDER_H__ \ No newline at end of file