From 1615b921623e3972d1b96fdd4f6348ec997e09f4 Mon Sep 17 00:00:00 2001 From: Erik Broberg Date: Wed, 18 May 2016 10:53:56 -0400 Subject: [PATCH] Changed gdaldataconverter to TextureDataProvider. Clean up public interface and added skeleton interface for async data fetching --- modules/globebrowsing/CMakeLists.txt | 4 +- ...ldataconverter.h => texturedataprovider.h} | 76 ++++++++++++++----- ...aconverter.inl => texturedataprovider.inl} | 63 +++++++++++---- .../globebrowsing/other/texturetileset.cpp | 4 +- modules/globebrowsing/other/tileprovider.cpp | 24 +++--- modules/globebrowsing/other/tileprovider.h | 38 ++++++---- .../shaders/globalchunkedlodpatch_fs.glsl | 4 +- .../shaders/localchunkedlodpatch_fs.glsl | 2 +- 8 files changed, 148 insertions(+), 67 deletions(-) rename modules/globebrowsing/other/{gdaldataconverter.h => texturedataprovider.h} (64%) rename modules/globebrowsing/other/{gdaldataconverter.inl => texturedataprovider.inl} (88%) diff --git a/modules/globebrowsing/CMakeLists.txt b/modules/globebrowsing/CMakeLists.txt index 3c93f41d47..d2e9626990 100644 --- a/modules/globebrowsing/CMakeLists.txt +++ b/modules/globebrowsing/CMakeLists.txt @@ -52,7 +52,7 @@ set(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/other/texturetileset.h ${CMAKE_CURRENT_SOURCE_DIR}/other/patchcoverageprovider.h ${CMAKE_CURRENT_SOURCE_DIR}/other/tileprovider.h - ${CMAKE_CURRENT_SOURCE_DIR}/other/gdaldataconverter.h + ${CMAKE_CURRENT_SOURCE_DIR}/other/texturedataprovider.h ${CMAKE_CURRENT_SOURCE_DIR}/other/lrucache.h ${CMAKE_CURRENT_SOURCE_DIR}/other/concurrentjobmanager.h ${CMAKE_CURRENT_SOURCE_DIR}/other/threadpool.h @@ -89,7 +89,7 @@ set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/other/texturetileset.cpp ${CMAKE_CURRENT_SOURCE_DIR}/other/patchcoverageprovider.cpp ${CMAKE_CURRENT_SOURCE_DIR}/other/tileprovider.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/other/gdaldataconverter.inl + ${CMAKE_CURRENT_SOURCE_DIR}/other/texturedataprovider.inl ${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/gdaldataconverter.h b/modules/globebrowsing/other/texturedataprovider.h similarity index 64% rename from modules/globebrowsing/other/gdaldataconverter.h rename to modules/globebrowsing/other/texturedataprovider.h index 93a86dafc3..d41c5367c4 100644 --- a/modules/globebrowsing/other/gdaldataconverter.h +++ b/modules/globebrowsing/other/texturedataprovider.h @@ -31,6 +31,7 @@ #include #include +#include #include "gdal_priv.h" @@ -40,7 +41,7 @@ namespace openspace { using namespace ghoul::opengl; - struct UninitializedTextureTile { + struct TextureData { struct TextureFormat { @@ -48,12 +49,8 @@ namespace openspace { GLuint glFormat; }; - UninitializedTextureTile( - void* data, - glm::uvec3 dims, - TextureFormat format, - GLuint glType, - const ChunkIndex& chunkIndex) + TextureData(void* data, glm::uvec3 dims, TextureFormat format, + GLuint glType, const ChunkIndex& chunkIndex) : imageData(data) , dimensions(dims) , texFormat(format) @@ -70,32 +67,71 @@ namespace openspace { const ChunkIndex chunkIndex; }; + template - class GdalDataConverter + class TextureDataProvider { public: - GdalDataConverter(); - ~GdalDataConverter(); + TextureDataProvider(); + ~TextureDataProvider(); - std::shared_ptr getUninitializedTextureTile( - GDALDataset * dataSet, - ChunkIndex chunkIndex, - int tileLevelDifference); - UninitializedTextureTile::TextureFormat getTextureFormat( - int rasterCount, - GDALDataType gdalType); - GLuint getGlDataTypeFromGdalDataType(GDALDataType gdalType); + std::shared_ptr getTextureData( + GDALDataset * dataSet, ChunkIndex chunkIndex, int tileLevelDifference); + + + + struct async { + public: + void request(GDALDataset * dataSet, ChunkIndex chunkIndex, int tileLevelDifference); + void updateRequests(); + bool hasTextureTileData() const; + std::shared_ptr nextTextureTile(); + + private: + std::queue> loadedTextureTiles; + std::set asyncReaders; + }; + + + + private: + + ////////////////////////////////////////////////////////////////////////////////// + // HELPER STRUCTS // + ////////////////////////////////////////////////////////////////////////////////// + + + struct GdalRequestParams { + glm::uvec2 pixelStart; + glm::uvec2 numPixels; + GDALDataType dataType; + int pixelSpacing; + int lineSpacing; + }; + + + ////////////////////////////////////////////////////////////////////////////////// + // HELPER FUNCTIONS // + ////////////////////////////////////////////////////////////////////////////////// + glm::uvec2 geodeticToPixel(GDALDataset* dataSet, const Geodetic2& geo); - }; + GLuint getGlDataTypeFromGdalDataType(GDALDataType gdalType); + + TextureData::TextureFormat getTextureFormat( + int rasterCount, + GDALDataType gdalType); + + + }; } // namespace openspace +#include -#include #endif // __GDALDATACONVERTER_H__ \ No newline at end of file diff --git a/modules/globebrowsing/other/gdaldataconverter.inl b/modules/globebrowsing/other/texturedataprovider.inl similarity index 88% rename from modules/globebrowsing/other/gdaldataconverter.inl rename to modules/globebrowsing/other/texturedataprovider.inl index 7e01541e35..8f2538283c 100644 --- a/modules/globebrowsing/other/gdaldataconverter.inl +++ b/modules/globebrowsing/other/texturedataprovider.inl @@ -23,7 +23,7 @@ ****************************************************************************************/ -#include +#include #include #include @@ -31,20 +31,22 @@ namespace openspace { template - GdalDataConverter::GdalDataConverter() + TextureDataProvider::TextureDataProvider() { } template - GdalDataConverter::~GdalDataConverter() + TextureDataProvider::~TextureDataProvider() { } + + template - std::shared_ptr GdalDataConverter::getUninitializedTextureTile( + std::shared_ptr TextureDataProvider::getTextureData( GDALDataset* dataSet, ChunkIndex chunkIndex, int tileLevelDifference) @@ -94,6 +96,9 @@ namespace openspace { // GDAL reads image data top to bottom T* imageData = new T[numPixels.x * numPixels.y * nRasters]; + int pixelSpacing = sizeof(T) * nRasters; + int lineSpacing = pixelSpacing * numPixels.x; + // Read the data (each rasterband is a separate channel) for (size_t i = 0; i < nRasters; i++) { GDALRasterBand* rasterBand = dataSet->GetRasterBand(i + 1)->GetOverview(ov); @@ -101,6 +106,7 @@ namespace openspace { int xSize = rasterBand->GetXSize(); int ySize = rasterBand->GetYSize(); + CPLErr err = rasterBand->RasterIO( GF_Read, pixelStart.x, // Begin read x @@ -111,8 +117,8 @@ namespace openspace { numPixels.x, // width to write x in destination numPixels.y, // width to write y in destination gdalType, // Type - sizeof(T) * nRasters, // Pixel spacing - 0); // Line spacing + pixelSpacing, // Pixel spacing + lineSpacing); // Line spacing if (err != CE_None) { ;//LERROR("There was a IO error (" << err << ") for: " << dataSet->GetDescription()); @@ -130,22 +136,22 @@ namespace openspace { delete[] imageData; glm::uvec3 dims(numPixels.x, numPixels.y, 1); - UninitializedTextureTile::TextureFormat textureFormat = + TextureData::TextureFormat textureFormat = getTextureFormat(nRasters, gdalType); GLuint glType = getGlDataTypeFromGdalDataType(gdalType); - UninitializedTextureTile* uninitedTexPtr = new UninitializedTextureTile( + TextureData* uninitedTexPtr = new TextureData( imageDataYflipped, dims, textureFormat, glType, chunkIndex); - std::shared_ptr uninitedTex = - std::shared_ptr(uninitedTexPtr); + std::shared_ptr uninitedTex = + std::shared_ptr(uninitedTexPtr); return uninitedTex; } template - glm::uvec2 GdalDataConverter::geodeticToPixel(GDALDataset* dataSet, const Geodetic2& geo) { + glm::uvec2 TextureDataProvider::geodeticToPixel(GDALDataset* dataSet, const Geodetic2& geo) { double padfTransform[6]; CPLErr err = dataSet->GetGeoTransform(padfTransform); @@ -183,11 +189,11 @@ namespace openspace { } template - UninitializedTextureTile::TextureFormat GdalDataConverter::getTextureFormat( + TextureData::TextureFormat TextureDataProvider::getTextureFormat( int rasterCount, GDALDataType gdalType) { - UninitializedTextureTile::TextureFormat format; + TextureData::TextureFormat format; switch (rasterCount) { @@ -323,7 +329,7 @@ namespace openspace { } template - GLuint GdalDataConverter::getGlDataTypeFromGdalDataType(GDALDataType gdalType) + GLuint TextureDataProvider::getGlDataTypeFromGdalDataType(GDALDataType gdalType) { switch (gdalType) { @@ -354,4 +360,33 @@ namespace openspace { } } + + template + void TextureDataProvider::async::request(GDALDataset * dataSet, ChunkIndex chunkIndex, int tileLevelDifference) { + + } + + template + void TextureDataProvider::async::updateRequests() { + + } + + template + bool TextureDataProvider::async::hasTextureTileData() const { + + } + + template + std::shared_ptr TextureDataProvider::async::nextTextureTile() { + return nullptr; + } + + + /* + void asyncRequest(GDALDataset * dataSet, ChunkIndex chunkIndex, int tileLevelDifference); + void updateAsyncRequests(); + std::shared_ptr nextTextureTile(); + + */ + } // namespace openspace diff --git a/modules/globebrowsing/other/texturetileset.cpp b/modules/globebrowsing/other/texturetileset.cpp index 7c456f33d6..0ae0475f19 100644 --- a/modules/globebrowsing/other/texturetileset.cpp +++ b/modules/globebrowsing/other/texturetileset.cpp @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include @@ -67,7 +67,7 @@ namespace openspace { poDataset = (GDALDataset *)GDALOpen(testFile.c_str(), GA_ReadOnly); assert(poDataset != nullptr, "Unable to read dataset" << testFile); - GdalDataConverter conv; + TextureDataProvider conv; GeodeticTileIndex ti(0, 0, 0); diff --git a/modules/globebrowsing/other/tileprovider.cpp b/modules/globebrowsing/other/tileprovider.cpp index 601c9ee660..c55fd12631 100644 --- a/modules/globebrowsing/other/tileprovider.cpp +++ b/modules/globebrowsing/other/tileprovider.cpp @@ -101,6 +101,9 @@ namespace openspace { _depthTransform.depthOffset = firstBand->GetOffset(); _depthTransform.depthScale = firstBand->GetScale() * maximumValue; + + + } TileProvider::~TileProvider(){ @@ -120,7 +123,7 @@ namespace openspace { void TileProvider::initTexturesFromLoadedData() { while (_tileLoadManager.numFinishedJobs() > 0) { auto finishedJob = _tileLoadManager.popFinishedJob(); - std::shared_ptr uninitedTex = + std::shared_ptr uninitedTex = finishedJob->product(); HashKey key = uninitedTex->chunkIndex.hashKey(); std::shared_ptr texture = initializeTexture(uninitedTex); @@ -228,7 +231,7 @@ namespace openspace { } - std::shared_ptr TileProvider::getUninitializedTextureTile( + std::shared_ptr TileProvider::getTextureData( const ChunkIndex& chunkIndex) { // We assume here that all rasterbands have the same data type @@ -237,44 +240,44 @@ namespace openspace { switch (gdalType) { case GDT_Byte: - return _uByteConverter.getUninitializedTextureTile( + return _uByteTextureTileDataProvider.getTextureData( _gdalDataSet, chunkIndex, _tileLevelDifference); break; case GDT_UInt16: - return _uShortConverter.getUninitializedTextureTile( + return _uShortTextureDataProvider.getTextureData( _gdalDataSet, chunkIndex, _tileLevelDifference); break; case GDT_Int16: - return _shortConverter.getUninitializedTextureTile( + return _shortTextureDataProvider.getTextureData( _gdalDataSet, chunkIndex, _tileLevelDifference); break; case GDT_UInt32: - return _uIntConverter.getUninitializedTextureTile( + return _uIntTextureDataProvider.getTextureData( _gdalDataSet, chunkIndex, _tileLevelDifference); break; case GDT_Int32: - return _intConverter.getUninitializedTextureTile( + return _intTextureDataProvider.getTextureData( _gdalDataSet, chunkIndex, _tileLevelDifference); break; case GDT_Float32: - return _floatConverter.getUninitializedTextureTile( + return _floatTextureDataProvider.getTextureData( _gdalDataSet, chunkIndex, _tileLevelDifference); break; case GDT_Float64: - return _doubleConverter.getUninitializedTextureTile( + return _doubleTextureDataProvider.getTextureData( _gdalDataSet, chunkIndex, _tileLevelDifference); @@ -287,7 +290,7 @@ namespace openspace { } std::shared_ptr TileProvider::initializeTexture( - std::shared_ptr uninitedTexture) { + std::shared_ptr uninitedTexture) { Texture* tex = new Texture( uninitedTexture->imageData, uninitedTexture->dimensions, @@ -299,7 +302,6 @@ namespace openspace { // The texture should take ownership of the data std::shared_ptr texture = std::shared_ptr(tex); - texture->uploadTexture(); return texture; } diff --git a/modules/globebrowsing/other/tileprovider.h b/modules/globebrowsing/other/tileprovider.h index fda5226f3b..3001e62129 100644 --- a/modules/globebrowsing/other/tileprovider.h +++ b/modules/globebrowsing/other/tileprovider.h @@ -38,7 +38,7 @@ #include #include #include -#include +#include ////////////////////////////////////////////////////////////////////////////////////////// // TILE PROVIDER // @@ -99,14 +99,14 @@ namespace openspace { /** Fetches all the needeed texture data from the GDAL dataset. */ - std::shared_ptr getUninitializedTextureTile( + std::shared_ptr getTextureData( const ChunkIndex& chunkIndex); /** Creates an OpenGL texture and pushes the data to the GPU. */ std::shared_ptr initializeTexture( - std::shared_ptr uninitedTexture); + std::shared_ptr uninitedTexture); bool enqueueTileRequest(const ChunkIndex& ci); @@ -133,15 +133,15 @@ namespace openspace { GDALDataset* _gdalDataSet; // Converters are needed for all different data types since they are templated. - GdalDataConverter _uByteConverter; - GdalDataConverter _uShortConverter; - GdalDataConverter _shortConverter; - GdalDataConverter _uIntConverter; - GdalDataConverter _intConverter; - GdalDataConverter _floatConverter; - GdalDataConverter _doubleConverter; + TextureDataProvider _uByteTextureTileDataProvider; + TextureDataProvider _uShortTextureDataProvider; + TextureDataProvider _shortTextureDataProvider; + TextureDataProvider _uIntTextureDataProvider; + TextureDataProvider _intTextureDataProvider; + TextureDataProvider _floatTextureDataProvider; + TextureDataProvider _doubleTextureDataProvider; - ConcurrentJobManager _tileLoadManager; + ConcurrentJobManager _tileLoadManager; std::shared_ptr _defaultTexture; int _tileLevelDifference; @@ -150,11 +150,19 @@ namespace openspace { } // namespace openspace + + + + + + + + namespace openspace { using namespace ghoul::opengl; - struct TextureTileLoadJob : public Job { + struct TextureTileLoadJob : public Job { TextureTileLoadJob(TileProvider * tileProvider, const ChunkIndex& chunkIndex) : _tileProvider(tileProvider) , _chunkIndex(chunkIndex) { @@ -164,11 +172,11 @@ namespace openspace { virtual ~TextureTileLoadJob() { } virtual void execute() { - _uninitedTexture = _tileProvider->getUninitializedTextureTile(_chunkIndex); + _uninitedTexture = _tileProvider->getTextureData(_chunkIndex); } - virtual std::shared_ptr product() { + virtual std::shared_ptr product() { return _uninitedTexture; } @@ -176,7 +184,7 @@ namespace openspace { private: ChunkIndex _chunkIndex; TileProvider * _tileProvider; - std::shared_ptr _uninitedTexture; + std::shared_ptr _uninitedTexture; }; } diff --git a/modules/globebrowsing/shaders/globalchunkedlodpatch_fs.glsl b/modules/globebrowsing/shaders/globalchunkedlodpatch_fs.glsl index 1665862311..b6e30e9b4d 100644 --- a/modules/globebrowsing/shaders/globalchunkedlodpatch_fs.glsl +++ b/modules/globebrowsing/shaders/globalchunkedlodpatch_fs.glsl @@ -44,7 +44,7 @@ Fragment getFragment() { colorTiles[#{i}].uvTransform.uvScale * fs_uv + colorTiles[#{i}].uvTransform.uvOffset; vec4 colorSample = texture(colorTiles[#{i}].textureSampler, samplePos); - frag.color = blendOver(frag.color, colorSample); + frag.color = blendAdd(frag.color, colorSample); } #endfor @@ -54,7 +54,7 @@ Fragment getFragment() { //frag.color = frag.color * 0.9 + 0.2*vec4(samplePos, 0, 1); // Border overlay - //frag.color = frag.color + patchBorderOverlay(fs_uv, vec3(0.5, 0.5, 0.5), 0.02); + frag.color = frag.color + patchBorderOverlay(fs_uv, vec3(0.5, 0.5, 0.5), 0.02); frag.depth = fs_position.w; diff --git a/modules/globebrowsing/shaders/localchunkedlodpatch_fs.glsl b/modules/globebrowsing/shaders/localchunkedlodpatch_fs.glsl index f0cb8f2ed0..4cfa122486 100644 --- a/modules/globebrowsing/shaders/localchunkedlodpatch_fs.glsl +++ b/modules/globebrowsing/shaders/localchunkedlodpatch_fs.glsl @@ -59,7 +59,7 @@ Fragment getFragment() { //frag.color = frag.color * 0.9 + 0.2*vec4(samplePos, 0, 1); // Border overlay - //frag.color = frag.color + patchBorderOverlay(fs_uv, vec3(0.5, 0.5, 0.5), 0.02); + frag.color = frag.color + patchBorderOverlay(fs_uv, vec3(0.5, 0.5, 0.5), 0.02); frag.depth = fs_position.w;