Flush tile request queue every X frame. Currently set to every 60 frame

This commit is contained in:
Erik Broberg
2016-05-16 13:12:52 -04:00
parent 276375a799
commit 6f953ecdfb
8 changed files with 71 additions and 19 deletions

View File

@@ -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

View File

@@ -48,7 +48,7 @@ using HashKey = unsigned long;
struct ChunkIndex {
int x, y, level;

View File

@@ -96,7 +96,7 @@ namespace openspace {
colorTextureDictionary.getValue("FilePath", path);
std::shared_ptr<TileProvider> colorTextureProvider =
std::shared_ptr<TileProvider>(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<TileProvider> heightMapProvider =
std::shared_ptr<TileProvider>(new TileProvider(
path, 5000, 256));
path, 5000, 256, 60));
_tileProviderManager->addHeightMap(name, heightMapProvider);
}

View File

@@ -83,6 +83,12 @@ namespace openspace {
}
}
void clearEnqueuedJobs() {
while (_incomingJobs.size()) {
_incomingJobs.pop();
}
}
std::shared_ptr<Job<P>> popFinishedJob() {
ghoul_assert(_finishedJobs.size() > 0, "There is no finished job to pop!");
return _finishedJobs.pop();

View File

@@ -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<UninitializedTextureTile> uninitedTex =
@@ -116,6 +128,12 @@ namespace openspace {
}
}
void TileProvider::clearRequestQueue() {
_tileLoadManager.clearEnqueuedJobs();
_queuedTileRequests.clear();
_framesSinceLastRequestFlush = 0;
}
Tile TileProvider::getMostHiResTile(ChunkIndex chunkIndex) {
std::shared_ptr<Texture> tex = nullptr;
@@ -187,14 +205,16 @@ namespace openspace {
return _tileCache.get(hashkey);
}
else {
// enque load job
std::shared_ptr<TextureTileLoadJob> job = std::shared_ptr<TextureTileLoadJob>(
new TextureTileLoadJob(this, chunkIndex));
bool tileHasBeenQueued = _queuedTileRequests.find(hashkey) != _queuedTileRequests.end();
if (!tileHasBeenQueued) {
// enque load job
std::shared_ptr<TextureTileLoadJob> job = std::shared_ptr<TextureTileLoadJob>(
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;
}
}

View File

@@ -28,6 +28,7 @@
#include "gdal_priv.h"
#include <openspace/engine/downloadmanager.h>
#include <set>
#include <ghoul/logging/logmanager.h>
#include <ghoul/filesystem/filesystem.h> // 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<Texture> initializeTexture(
std::shared_ptr<UninitializedTextureTile> uninitedTexture);
LRUCache<HashKey, std::shared_ptr<Texture>> _tileCache;
const std::string _filePath;
void clearRequestQueue();
void initTexturesFromLoadedData();
//////////////////////////////////////////////////////////////////////////////////
// Member variables //
//////////////////////////////////////////////////////////////////////////////////
LRUCache<HashKey, std::shared_ptr<Texture>> _tileCache;
std::set<HashKey> _queuedTileRequests;
int _framesSinceLastRequestFlush;
int _framesUntilRequestFlush;
const std::string _filePath;
static bool hasInitializedGDAL;
GDALDataset* _gdalDataSet;

View File

@@ -24,7 +24,6 @@
#include <modules/globebrowsing/rendering/culling.h>
#include <modules/globebrowsing/rendering/aabb.h>
#include <modules/globebrowsing/geodetics/ellipsoid.h>
@@ -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();

View File

@@ -34,6 +34,8 @@
#include <modules/globebrowsing/geodetics/geodetic2.h>
#include <modules/globebrowsing/geodetics/ellipsoid.h>
#include <modules/globebrowsing/rendering/aabb.h>
namespace openspace {
@@ -52,9 +54,6 @@ namespace openspace {
class FrustumCuller {
public:
FrustumCuller();
~FrustumCuller();