diff --git a/modules/globebrowsing/globes/chunkedlodglobe.cpp b/modules/globebrowsing/globes/chunkedlodglobe.cpp index ca8e6be1f1..86128e7a04 100644 --- a/modules/globebrowsing/globes/chunkedlodglobe.cpp +++ b/modules/globebrowsing/globes/chunkedlodglobe.cpp @@ -97,6 +97,7 @@ namespace openspace { minDistToCamera = INFINITY; ChunkNode::renderedPatches = 0; + _leftRoot->render(data); _rightRoot->render(data); @@ -112,6 +113,7 @@ namespace openspace { void ChunkedLodGlobe::update(const UpdateData& data) { _patchRenderer->update(); + } const Ellipsoid& ChunkedLodGlobe::ellipsoid() const diff --git a/modules/globebrowsing/globes/chunkindex.h b/modules/globebrowsing/globes/chunkindex.h index 80226aa1e1..0f70e6f690 100644 --- a/modules/globebrowsing/globes/chunkindex.h +++ b/modules/globebrowsing/globes/chunkindex.h @@ -48,7 +48,7 @@ using HashKey = unsigned long; struct ChunkIndex { - + int x, y, level; diff --git a/modules/globebrowsing/globes/renderableglobe.cpp b/modules/globebrowsing/globes/renderableglobe.cpp index baac1ecf10..04734bafbf 100644 --- a/modules/globebrowsing/globes/renderableglobe.cpp +++ b/modules/globebrowsing/globes/renderableglobe.cpp @@ -96,7 +96,7 @@ namespace openspace { colorTextureDictionary.getValue("FilePath", path); std::shared_ptr colorTextureProvider = std::shared_ptr(new TileProvider( - path, 5000, 1024)); + path, 5000, 1024, 60)); _tileProviderManager->addColorTexture(name, colorTextureProvider); } @@ -113,7 +113,7 @@ namespace openspace { heightMapDictionary.getValue("FilePath", path); std::shared_ptr heightMapProvider = std::shared_ptr(new TileProvider( - path, 5000, 256)); + path, 5000, 256, 60)); _tileProviderManager->addHeightMap(name, heightMapProvider); } diff --git a/modules/globebrowsing/other/concurrentjobmanager.h b/modules/globebrowsing/other/concurrentjobmanager.h index 1a994a3a7f..33cd150b5a 100644 --- a/modules/globebrowsing/other/concurrentjobmanager.h +++ b/modules/globebrowsing/other/concurrentjobmanager.h @@ -83,6 +83,12 @@ namespace openspace { } } + void clearEnqueuedJobs() { + while (_incomingJobs.size()) { + _incomingJobs.pop(); + } + } + std::shared_ptr> popFinishedJob() { ghoul_assert(_finishedJobs.size() > 0, "There is no finished job to pop!"); return _finishedJobs.pop(); diff --git a/modules/globebrowsing/other/tileprovider.cpp b/modules/globebrowsing/other/tileprovider.cpp index a8ef467eb4..58d98915d5 100644 --- a/modules/globebrowsing/other/tileprovider.cpp +++ b/modules/globebrowsing/other/tileprovider.cpp @@ -48,9 +48,12 @@ namespace openspace { TileProvider::TileProvider( const std::string& filePath, int tileCacheSize, - int minimumPixelSize) + int minimumPixelSize, + int framesUntilRequestFlush) : _filePath(filePath) , _tileCache(tileCacheSize) // setting cache size + , _framesSinceLastRequestFlush(0) + , _framesUntilRequestFlush(framesUntilRequestFlush) { // Set a temporary texture std::string fileName = "textures/earth_bluemarble.jpg"; @@ -101,11 +104,20 @@ namespace openspace { } TileProvider::~TileProvider(){ + clearRequestQueue(); delete _gdalDataSet; } void TileProvider::prerender() { + initTexturesFromLoadedData(); + + if (_framesSinceLastRequestFlush++ > _framesUntilRequestFlush) { + clearRequestQueue(); + } + } + + void TileProvider::initTexturesFromLoadedData() { while (_tileLoadManager.numFinishedJobs() > 0) { auto finishedJob = _tileLoadManager.popFinishedJob(); std::shared_ptr uninitedTex = @@ -116,6 +128,12 @@ namespace openspace { } } + void TileProvider::clearRequestQueue() { + _tileLoadManager.clearEnqueuedJobs(); + _queuedTileRequests.clear(); + _framesSinceLastRequestFlush = 0; + } + Tile TileProvider::getMostHiResTile(ChunkIndex chunkIndex) { std::shared_ptr tex = nullptr; @@ -187,14 +205,16 @@ namespace openspace { return _tileCache.get(hashkey); } else { - // enque load job - std::shared_ptr job = std::shared_ptr( - new TextureTileLoadJob(this, chunkIndex)); + bool tileHasBeenQueued = _queuedTileRequests.find(hashkey) != _queuedTileRequests.end(); + if (!tileHasBeenQueued) { + // enque load job + std::shared_ptr job = std::shared_ptr( + new TextureTileLoadJob(this, chunkIndex)); - _tileLoadManager.enqueueJob(job); + _tileLoadManager.enqueueJob(job); - // map key to nullptr while tile is loaded - _tileCache.put(hashkey, nullptr); + _queuedTileRequests.insert(hashkey); + } return nullptr; } } diff --git a/modules/globebrowsing/other/tileprovider.h b/modules/globebrowsing/other/tileprovider.h index 4117b5898d..6a5f46dcf8 100644 --- a/modules/globebrowsing/other/tileprovider.h +++ b/modules/globebrowsing/other/tileprovider.h @@ -28,6 +28,7 @@ #include "gdal_priv.h" #include +#include #include #include // absPath @@ -69,7 +70,8 @@ namespace openspace { */ class TileProvider { public: - TileProvider(const std::string& fileName, int tileCacheSize, int minimumPixelSize); + TileProvider(const std::string& fileName, int tileCacheSize, int minimumPixelSize, + int framesUntilRequestFlush); ~TileProvider(); Tile getMostHiResTile(ChunkIndex chunkIndex); @@ -84,6 +86,13 @@ namespace openspace { friend class TextureTileLoadJob; + + + ////////////////////////////////////////////////////////////////////////////////// + // Helper functions // + ////////////////////////////////////////////////////////////////////////////////// + + /** Fetches all the needeed texture data from the GDAL dataset. */ @@ -96,9 +105,26 @@ namespace openspace { std::shared_ptr initializeTexture( std::shared_ptr uninitedTexture); - LRUCache> _tileCache; - const std::string _filePath; + void clearRequestQueue(); + + void initTexturesFromLoadedData(); + + + + + ////////////////////////////////////////////////////////////////////////////////// + // Member variables // + ////////////////////////////////////////////////////////////////////////////////// + + + LRUCache> _tileCache; + std::set _queuedTileRequests; + + int _framesSinceLastRequestFlush; + int _framesUntilRequestFlush; + + const std::string _filePath; static bool hasInitializedGDAL; GDALDataset* _gdalDataSet; diff --git a/modules/globebrowsing/rendering/culling.cpp b/modules/globebrowsing/rendering/culling.cpp index 9e50a7accb..a8dd94c96d 100644 --- a/modules/globebrowsing/rendering/culling.cpp +++ b/modules/globebrowsing/rendering/culling.cpp @@ -24,7 +24,6 @@ #include -#include #include @@ -48,7 +47,7 @@ namespace openspace { } - const AABB3 viewFrustum = AABB3(vec3(-1, -1, 0), vec3(1, 1, 1e35)); + const AABB3 FrustumCuller::viewFrustum(vec3(-1, -1, 0), vec3(1, 1, 1e35)); bool FrustumCuller::isVisible( @@ -147,7 +146,7 @@ namespace openspace { } - return bounds.intersects(viewFrustum); + return bounds.intersects(FrustumCuller::viewFrustum); /* vec2 center = bounds.center(); diff --git a/modules/globebrowsing/rendering/culling.h b/modules/globebrowsing/rendering/culling.h index b47661908a..f7d6e92f33 100644 --- a/modules/globebrowsing/rendering/culling.h +++ b/modules/globebrowsing/rendering/culling.h @@ -34,6 +34,8 @@ #include #include +#include + namespace openspace { @@ -52,9 +54,6 @@ namespace openspace { class FrustumCuller { public: - - - FrustumCuller(); ~FrustumCuller();