mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-06 03:29:44 -06:00
132 lines
5.1 KiB
C++
132 lines
5.1 KiB
C++
/*****************************************************************************************
|
|
* *
|
|
* OpenSpace *
|
|
* *
|
|
* Copyright (c) 2014-2017 *
|
|
* *
|
|
* 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 __OPENSPACE_MODULE_GLOBEBROWSING___ASYNC_TILE_DATAPROVIDER___H__
|
|
#define __OPENSPACE_MODULE_GLOBEBROWSING___ASYNC_TILE_DATAPROVIDER___H__
|
|
|
|
#include <modules/globebrowsing/globebrowsingmodule.h>
|
|
|
|
#include <modules/globebrowsing/other/prioritizingconcurrentjobmanager.h>
|
|
#include <modules/globebrowsing/other/pixelbuffercontainer.h>
|
|
#include <modules/globebrowsing/tile/tileindex.h>
|
|
|
|
#include <ghoul/misc/boolean.h>
|
|
#include <ghoul/opengl/ghoul_gl.h>
|
|
|
|
#include <map>
|
|
#include <set>
|
|
#include <unordered_map>
|
|
|
|
namespace openspace::globebrowsing {
|
|
|
|
//class GlobeBrowsingModule;
|
|
struct RawTile;
|
|
class RawTileDataReader;
|
|
|
|
/**
|
|
* The responsibility of this class is to enqueue tile requests and fetching finished
|
|
* <code>RawTile</code>s that has been asynchronously loaded.
|
|
*/
|
|
class AsyncTileDataProvider {
|
|
public:
|
|
/**
|
|
* \param textureDataProvider is the reader that will be used for the asynchronos
|
|
* tile loading.
|
|
*/
|
|
AsyncTileDataProvider(const std::string& name,
|
|
std::shared_ptr<RawTileDataReader> textureDataProvider);
|
|
|
|
/**
|
|
* Creates a job which asynchronously loads a raw tile. This job is enqueued.
|
|
*/
|
|
bool enqueueTileIO(const TileIndex& tileIndex);
|
|
|
|
/**
|
|
* Get all finished jobs.
|
|
*/
|
|
std::vector<std::shared_ptr<RawTile>> getRawTiles();
|
|
|
|
/**
|
|
* Get one finished job.
|
|
*/
|
|
std::shared_ptr<RawTile> popFinishedRawTile();
|
|
|
|
void update();
|
|
void reset();
|
|
void prepairToBeDeleted();
|
|
|
|
bool shouldBeDeleted();
|
|
|
|
std::shared_ptr<RawTileDataReader> getRawTileDataReader() const;
|
|
float noDataValueAsFloat() const;
|
|
|
|
protected:
|
|
using ResetRawTileDataReader = ghoul::Boolean;
|
|
|
|
enum class ResetMode {
|
|
ShouldResetAll,
|
|
ShouldResetAllButRawTileDataReader,
|
|
ShouldBeDeleted,
|
|
ShouldNotReset
|
|
};
|
|
|
|
/**
|
|
* \returns true if tile of index <code>tileIndex</code> is not already enqueued.
|
|
*/
|
|
bool satisfiesEnqueueCriteria(const TileIndex& tileIndex);
|
|
|
|
/**
|
|
* An unfinished job is a load tile job that has been popped from the thread pool due
|
|
* to its low priority. Once it has been popped, it is marked as unfinished and needs
|
|
* to be explicitly ended.
|
|
*/
|
|
void endUnfinishedJobs();
|
|
|
|
void endEnqueuedJobs();
|
|
|
|
void updatePboUsage();
|
|
|
|
void performReset(ResetRawTileDataReader resetRawTileDataReader);
|
|
|
|
private:
|
|
const std::string _name;
|
|
GlobeBrowsingModule* _globeBrowsingModule;
|
|
/// The reader used for asynchronous reading
|
|
std::shared_ptr<RawTileDataReader> _rawTileDataReader;
|
|
|
|
PrioritizingConcurrentJobManager<RawTile, TileIndex::TileHashKey>
|
|
_concurrentJobManager;
|
|
|
|
/// nullptr if pbo is not used for texture uploading. Otherwise initialized.
|
|
std::unique_ptr<PixelBufferContainer<TileIndex::TileHashKey>> _pboContainer;
|
|
std::set<TileIndex::TileHashKey> _enqueuedTileRequests;
|
|
|
|
ResetMode _resetMode;
|
|
bool _shouldBeDeleted;
|
|
};
|
|
|
|
} // namespace openspace::globebrowsing
|
|
|
|
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___ASYNC_TILE_DATAPROVIDER___H__
|