diff --git a/modules/globebrowsing/CMakeLists.txt b/modules/globebrowsing/CMakeLists.txt index b58a4de58f..036e5abccf 100644 --- a/modules/globebrowsing/CMakeLists.txt +++ b/modules/globebrowsing/CMakeLists.txt @@ -54,7 +54,7 @@ set(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/tile/tilepile.h ${CMAKE_CURRENT_SOURCE_DIR}/tile/tile.h - ${CMAKE_CURRENT_SOURCE_DIR}/tile/tileandtransform.h + ${CMAKE_CURRENT_SOURCE_DIR}/tile/chunktile.h ${CMAKE_CURRENT_SOURCE_DIR}/tile/tileindex.h ${CMAKE_CURRENT_SOURCE_DIR}/tile/tileselector.h ${CMAKE_CURRENT_SOURCE_DIR}/tile/tilediskcache.h @@ -110,7 +110,7 @@ set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/tile/tilepile.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tile/tile.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/tile/tileandtransform.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/tile/chunktile.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tile/tileindex.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tile/tileselector.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tile/tilediskcache.cpp diff --git a/modules/globebrowsing/chunk/chunk.cpp b/modules/globebrowsing/chunk/chunk.cpp index 8c928b586a..8384792463 100644 --- a/modules/globebrowsing/chunk/chunk.cpp +++ b/modules/globebrowsing/chunk/chunk.cpp @@ -109,7 +109,7 @@ namespace globebrowsing { size_t HEIGHT_CHANNEL = 0; const TileProviderGroup& heightmaps = tileProviderManager->getTileProviderGroup(LayeredTextures::HeightMaps); - std::vector tiles = TileSelector::getTilesSortedByHighestResolution(heightmaps, _tileIndex); + std::vector tiles = TileSelector::getTilesSortedByHighestResolution(heightmaps, _tileIndex); bool lastHadMissingData = true; for (auto tile : tiles) { bool goodTile = tile.tile.status == Tile::Status::OK; diff --git a/modules/globebrowsing/chunk/chunkrenderer.cpp b/modules/globebrowsing/chunk/chunkrenderer.cpp index 1cff4052d9..48633858f5 100644 --- a/modules/globebrowsing/chunk/chunkrenderer.cpp +++ b/modules/globebrowsing/chunk/chunkrenderer.cpp @@ -126,12 +126,12 @@ namespace globebrowsing { LayeredTextures::BlendLayerSuffixes blendLayerSuffix, size_t layerIndex, ghoul::opengl::TextureUnit& texUnit, - const TileAndTransform& tileAndTransform) + const ChunkTile& chunkTile) { // Blend tile with two parents // The texture needs a unit to sample from texUnit.activate(); - tileAndTransform.tile.texture->bind(); + chunkTile.tile.texture->bind(); uniformIdHandler->programObject().setUniform( uniformIdHandler->getId( @@ -146,14 +146,14 @@ namespace globebrowsing { blendLayerSuffix, layerIndex, LayeredTextures::GlslTileDataId::uvTransform_uvScale), - tileAndTransform.uvTransform.uvScale); + chunkTile.uvTransform.uvScale); uniformIdHandler->programObject().setUniform( uniformIdHandler->getId( textureCategory, blendLayerSuffix, layerIndex, LayeredTextures::GlslTileDataId::uvTransform_uvOffset), - tileAndTransform.uvTransform.uvOffset); + chunkTile.uvTransform.uvOffset); } void ChunkRenderer::setLayerSettingsUniforms( @@ -257,11 +257,11 @@ namespace globebrowsing { auto tileProvider = it->get(); // Get the texture that should be used for rendering - TileAndTransform tileAndTransform = TileSelector::getHighestResolutionTile(tileProvider, tileIndex); - if (tileAndTransform.tile.status == Tile::Status::Unavailable) { - tileAndTransform.tile = tileProvider->getDefaultTile(); - tileAndTransform.uvTransform.uvOffset = { 0, 0 }; - tileAndTransform.uvTransform.uvScale = { 1, 1 }; + ChunkTile chunkTile = TileSelector::getHighestResolutionTile(tileProvider, tileIndex); + if (chunkTile.tile.status == Tile::Status::Unavailable) { + chunkTile.tile = tileProvider->getDefaultTile(); + chunkTile.uvTransform.uvOffset = { 0, 0 }; + chunkTile.uvTransform.uvScale = { 1, 1 }; } activateTileAndSetTileUniforms( @@ -270,13 +270,13 @@ namespace globebrowsing { LayeredTextures::BlendLayerSuffixes::none, i, texUnits[category][i].blendTexture0, - tileAndTransform); + chunkTile); // If blending is enabled, two more textures are needed if (layeredTexturePreprocessingData.layeredTextureInfo[category].layerBlendingEnabled) { - TileAndTransform tileAndTransformParent1 = TileSelector::getHighestResolutionTile(tileProvider, tileIndex, 1); - if (tileAndTransformParent1.tile.status == Tile::Status::Unavailable) { - tileAndTransformParent1 = tileAndTransform; + ChunkTile chunkTileParent1 = TileSelector::getHighestResolutionTile(tileProvider, tileIndex, 1); + if (chunkTileParent1.tile.status == Tile::Status::Unavailable) { + chunkTileParent1 = chunkTile; } activateTileAndSetTileUniforms( programUniformHandler, @@ -284,11 +284,11 @@ namespace globebrowsing { LayeredTextures::BlendLayerSuffixes::Parent1, i, texUnits[category][i].blendTexture1, - tileAndTransformParent1); + chunkTileParent1); - TileAndTransform tileAndTransformParent2 = TileSelector::getHighestResolutionTile(tileProvider, tileIndex, 2); - if (tileAndTransformParent2.tile.status == Tile::Status::Unavailable) { - tileAndTransformParent2 = tileAndTransformParent1; + ChunkTile chunkTileParent2 = TileSelector::getHighestResolutionTile(tileProvider, tileIndex, 2); + if (chunkTileParent2.tile.status == Tile::Status::Unavailable) { + chunkTileParent2 = chunkTileParent1; } activateTileAndSetTileUniforms( programUniformHandler, @@ -296,7 +296,7 @@ namespace globebrowsing { LayeredTextures::BlendLayerSuffixes::Parent2, i, texUnits[category][i].blendTexture2, - tileAndTransformParent2); + chunkTileParent2); } setLayerSettingsUniforms( @@ -306,8 +306,8 @@ namespace globebrowsing { _tileProviderManager->getTileProviderGroup(category).getActiveNamedTileProviders()[i].settings); /* - if (category == LayeredTextures::HeightMaps && tileAndTransform.tile.preprocessData) { - //auto preprocessingData = tileAndTransform.tile.preprocessData; + if (category == LayeredTextures::HeightMaps && chunkTile.tile.preprocessData) { + //auto preprocessingData = chunkTile.tile.preprocessData; //float noDataValue = preprocessingData->noDataValues[0]; programObject->setUniform( "minimumValidHeight[" + std::to_string(i) + "]", diff --git a/modules/globebrowsing/chunk/chunkrenderer.h b/modules/globebrowsing/chunk/chunkrenderer.h index ab8f6ccac2..52f79847fb 100644 --- a/modules/globebrowsing/chunk/chunkrenderer.h +++ b/modules/globebrowsing/chunk/chunkrenderer.h @@ -102,7 +102,7 @@ namespace globebrowsing { LayeredTextures::BlendLayerSuffixes blendLayerSuffix, size_t layerIndex, ghoul::opengl::TextureUnit& texUnit, - const TileAndTransform& tileAndTransform); + const ChunkTile& chunkTile); void setLayerSettingsUniforms( std::shared_ptr uniformIdHandler, diff --git a/modules/globebrowsing/globes/renderableglobe.cpp b/modules/globebrowsing/globes/renderableglobe.cpp index bc88e02d8d..e950ac7705 100644 --- a/modules/globebrowsing/globes/renderableglobe.cpp +++ b/modules/globebrowsing/globes/renderableglobe.cpp @@ -297,10 +297,10 @@ namespace globebrowsing { geoDiffPoint.lon / geoDiffPatch.lon, geoDiffPoint.lat / geoDiffPatch.lat); // Transform the uv coordinates to the current tile texture - TileAndTransform tileAndTransform = TileSelector::getHighestResolutionTile( + ChunkTile chunkTile = TileSelector::getHighestResolutionTile( tileProvider.get(), chunkIdx); - const auto& tile = tileAndTransform.tile; - const auto& uvTransform = tileAndTransform.uvTransform; + const auto& tile = chunkTile.tile; + const auto& uvTransform = chunkTile.uvTransform; const auto& depthTransform = tileProvider->depthTransform(); if (tile.status != Tile::Status::OK) { return 0; diff --git a/modules/globebrowsing/layer/layer.cpp b/modules/globebrowsing/layer/layer.cpp new file mode 100644 index 0000000000..eababa61fe --- /dev/null +++ b/modules/globebrowsing/layer/layer.cpp @@ -0,0 +1,155 @@ +/***************************************************************************************** +* * +* 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 +#include + +#include +#include +#include +#include +#include + +#include +#include + +namespace { + const std::string _loggerCat = "Layer"; + + const std::string KEY_NAME = "Name"; + const std::string KEY_ENABLED = "Enabled"; + +} + +namespace openspace { +namespace globebrowsing { + + Layer::Layer(const ghoul::Dictionary& dict){ + dict.getValue(KEY_NAME, _name); + dict.getValue(KEY_ENABLED, _enabled); + _tileProvider = std::unique_ptr(TileProvider::createFromDictionary(dict)); + + + } + + void Layer::bind(ProgramObject* programObject, const TileIndex& tileIndex){ + /* + ChunkTile tat = TileSelector::getHighestResolutionTile(_tileProvider.get(), tileIndex); + if (tat.tile.status == Tile::Status::Unavailable) { + tat.tile = _tileProvider->getDefaultTile(); + tat.uvTransform.uvOffset = { 0, 0 }; + tat.uvTransform.uvScale = { 1, 1 }; + } + + activateTileAndSetTileUniforms( + programUniformHandler, + LayeredTextures::TextureCategory(category), + LayeredTextures::BlendLayerSuffixes::none, + i, + texUnits[category][i].blendTexture0, + tat); + + // If blending is enabled, two more textures are needed + if (layeredTexturePreprocessingData.layeredTextureInfo[category].layerBlendingEnabled) { + tat tatParent1 = TileSelector::getHighestResolutionTile(_tileProvider.get(), tileIndex, 1); + if (tatParent1.tile.status == Tile::Status::Unavailable) { + tatParent1 = tat; + } + activateTileAndSetTileUniforms( + programUniformHandler, + LayeredTextures::TextureCategory(category), + LayeredTextures::BlendLayerSuffixes::Parent1, + i, + texUnits[category][i].blendTexture1, + tatParent1); + + ChunkTile tatParent2 = TileSelector::getHighestResolutionTile(_tileProvider.get(), tileIndex, 2); + if (tatParent2.tile.status == Tile::Status::Unavailable) { + tatParent2 = tatParent1; + } + activateTileAndSetTileUniforms( + programUniformHandler, + LayeredTextures::TextureCategory(category), + LayeredTextures::BlendLayerSuffixes::Parent2, + i, + texUnits[category][i].blendTexture2, + tatParent2); + } + */ + + } + /* + void Layer::ensureIdsAreUpdated(LayeredTextureShaderProvider* shaderProvider){ + if (shaderProvider->updatedOnLastCall()) + { + _shaderProvider = shaderProvider; + // Ignore errors since this loops through even uniforms that does not exist. + _shaderProvider->_programObject->setIgnoreUniformLocationError( + ProgramObject::IgnoreError::Yes); + for (size_t i = 0; i < LayeredTextures::NUM_TEXTURE_CATEGORIES; i++) + { + for (size_t j = 0; j < LayeredTextures::NUM_BLEND_TEXTURES; j++) + { + for (size_t k = 0; k < LayeredTextures::MAX_NUM_TEXTURES_PER_CATEGORY; + k++) + { + for (size_t l = 0; l < LayeredTextures::NUM_TILE_DATA_VARIABLES; l++) + { + _tileUniformIds[i][j][k][l] = + _shaderProvider->_programObject->uniformLocation( + LayeredTextures::TEXTURE_CATEGORY_NAMES[i] + + LayeredTextures::blendLayerSuffixes[j] + + "[" + std::to_string(k) + "]." + + LayeredTextures::glslTileDataNames[l]); + } + } + } + } + for (size_t i = 0; i < LayeredTextures::NUM_TEXTURE_CATEGORIES; i++) + { + for (size_t k = 0; k < LayeredTextures::MAX_NUM_TEXTURES_PER_CATEGORY; + k++) + { + for (size_t l = 0; l < LayeredTextures::NUM_LAYER_SETTINGS_VARIABLES; l++) + { + _layerSettingsUniformIds[i][k][l] = + _shaderProvider->_programObject->uniformLocation( + LayeredTextures::TEXTURE_CATEGORY_NAMES[i] + + "Settings" + + "[" + std::to_string(k) + "]." + + LayeredTextures::layerSettingsIds[l]); + } + } + } + // Reset ignore errors + _shaderProvider->_programObject->setIgnoreUniformLocationError( + ProgramObject::IgnoreError::No); + } + } + */ + +} // namespace globebrowsing +} // namespace openspace diff --git a/modules/globebrowsing/layer/layer.h b/modules/globebrowsing/layer/layer.h new file mode 100644 index 0000000000..2c95a2ded8 --- /dev/null +++ b/modules/globebrowsing/layer/layer.h @@ -0,0 +1,72 @@ +/***************************************************************************************** +* * +* 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 LAYER_H +#define LAYER_H + +#include +#include + +#include + +#include +#include + +#include +#include + +namespace openspace { +namespace globebrowsing { + +class TileProvider; + +class Layer : public properties::PropertyOwner { +public: + Layer(const ghoul::Dictionary& dict); + + void bind(ProgramObject* program, const TileIndex& tileIndex); + + + static const size_t NUM_LAYER_SETTINGS_VARIABLES = 3; + static const size_t NUM_TILE_DATA_VARIABLES = 3; + static const size_t NUM_BLEND_TEXTURES = 3; + +private: + + //void ensureIdsAreUpdated(LayeredTextureShaderProvider* shaderProvider); + + + std::string _name; + std::unique_ptr _tileProvider; + + std::array,NUM_BLEND_TEXTURES> _tileUniformIds; + std::array _layerSettingsUniformIds; + + bool _enabled; + +}; + +} // namespace globebrowsing +} // namespace openspace +#endif // LAYER_H diff --git a/modules/globebrowsing/tile/tileandtransform.cpp b/modules/globebrowsing/tile/chunktile.cpp similarity index 95% rename from modules/globebrowsing/tile/tileandtransform.cpp rename to modules/globebrowsing/tile/chunktile.cpp index 051c6ab54f..801934a0ff 100644 --- a/modules/globebrowsing/tile/tileandtransform.cpp +++ b/modules/globebrowsing/tile/chunktile.cpp @@ -22,12 +22,12 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include +#include #include namespace { - const std::string _loggerCat = "TileAndTransform"; + const std::string _loggerCat = "ChunkTile"; } namespace openspace { diff --git a/modules/globebrowsing/tile/tileandtransform.h b/modules/globebrowsing/tile/chunktile.h similarity index 98% rename from modules/globebrowsing/tile/tileandtransform.h rename to modules/globebrowsing/tile/chunktile.h index 8a98fc1015..83bf06b0c7 100644 --- a/modules/globebrowsing/tile/tileandtransform.h +++ b/modules/globebrowsing/tile/chunktile.h @@ -39,7 +39,7 @@ namespace globebrowsing { glm::vec2 uvScale; }; - struct TileAndTransform { + struct ChunkTile { Tile tile; TileUvTransform uvTransform; }; diff --git a/modules/globebrowsing/tile/tilepile.h b/modules/globebrowsing/tile/tilepile.h index 7a5ec405c0..7f6e8f18d3 100644 --- a/modules/globebrowsing/tile/tilepile.h +++ b/modules/globebrowsing/tile/tilepile.h @@ -29,7 +29,7 @@ #include // Texture #include -#include +#include #include #include @@ -48,7 +48,7 @@ namespace globebrowsing { void bind(ProgramObject* programObject); private: - std::vector pile; + std::vector pile; }; diff --git a/modules/globebrowsing/tile/tileselector.cpp b/modules/globebrowsing/tile/tileselector.cpp index 8dbe493c99..ad02e15a23 100644 --- a/modules/globebrowsing/tile/tileselector.cpp +++ b/modules/globebrowsing/tile/tileselector.cpp @@ -42,7 +42,7 @@ namespace globebrowsing { const TileSelector::CompareResolution TileSelector::HIGHEST_RES = TileSelector::CompareResolution(); - TileAndTransform TileSelector::getHighestResolutionTile(TileProvider* tileProvider, TileIndex tileIndex, int parents) { + ChunkTile TileSelector::getHighestResolutionTile(TileProvider* tileProvider, TileIndex tileIndex, int parents) { TileUvTransform uvTransform; uvTransform.uvOffset = glm::vec2(0, 0); uvTransform.uvScale = glm::vec2(1, 1); @@ -72,33 +72,33 @@ namespace globebrowsing { return{ Tile::TileUnavailable, uvTransform }; } - TileAndTransform TileSelector::getHighestResolutionTile(const TileProviderGroup& tileProviderGroup, TileIndex tileIndex) { - TileAndTransform mostHighResolution; + ChunkTile TileSelector::getHighestResolutionTile(const TileProviderGroup& tileProviderGroup, TileIndex tileIndex) { + ChunkTile mostHighResolution; mostHighResolution.tile = Tile::TileUnavailable; mostHighResolution.uvTransform.uvScale.x = 0; auto activeProviders = tileProviderGroup.getActiveTileProviders(); for (size_t i = 0; i < activeProviders.size(); i++) { - TileAndTransform tileAndTransform = getHighestResolutionTile(activeProviders[i].get(), tileIndex); - bool tileIsOk = tileAndTransform.tile.status == Tile::Status::OK; - bool tileHasPreprocessData = tileAndTransform.tile.preprocessData != nullptr; - bool tileIsHigherResolution = tileAndTransform.uvTransform.uvScale.x > mostHighResolution.uvTransform.uvScale.x; + ChunkTile chunkTile = getHighestResolutionTile(activeProviders[i].get(), tileIndex); + bool tileIsOk = chunkTile.tile.status == Tile::Status::OK; + bool tileHasPreprocessData = chunkTile.tile.preprocessData != nullptr; + bool tileIsHigherResolution = chunkTile.uvTransform.uvScale.x > mostHighResolution.uvTransform.uvScale.x; if (tileIsOk && tileHasPreprocessData && tileIsHigherResolution) { - mostHighResolution = tileAndTransform; + mostHighResolution = chunkTile; } } return mostHighResolution; } - bool TileSelector::CompareResolution::operator()(const TileAndTransform& a, const TileAndTransform& b) { + bool TileSelector::CompareResolution::operator()(const ChunkTile& a, const ChunkTile& b) { // large uv scale means smaller resolution return a.uvTransform.uvScale.x > b.uvTransform.uvScale.x; } - std::vector TileSelector::getTilesSortedByHighestResolution(const TileProviderGroup& tileProviderGroup, const TileIndex& tileIndex) { + std::vector TileSelector::getTilesSortedByHighestResolution(const TileProviderGroup& tileProviderGroup, const TileIndex& tileIndex) { auto activeProviders = tileProviderGroup.getActiveTileProviders(); - std::vector tiles; + std::vector tiles; for (auto provider : activeProviders){ tiles.push_back(getHighestResolutionTile(provider.get(), tileIndex)); } diff --git a/modules/globebrowsing/tile/tileselector.h b/modules/globebrowsing/tile/tileselector.h index 7a1a990121..d6041a8e69 100644 --- a/modules/globebrowsing/tile/tileselector.h +++ b/modules/globebrowsing/tile/tileselector.h @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include namespace openspace { @@ -37,12 +37,12 @@ namespace globebrowsing { class TileSelector { public: - static TileAndTransform getHighestResolutionTile(TileProvider* tileProvider, TileIndex tileIndex, int parents = 0); - static TileAndTransform getHighestResolutionTile(const TileProviderGroup& tileProviderGroup, TileIndex tileIndex); - static std::vector getTilesSortedByHighestResolution(const TileProviderGroup&, const TileIndex& tileIndex); + static ChunkTile getHighestResolutionTile(TileProvider* tileProvider, TileIndex tileIndex, int parents = 0); + static ChunkTile getHighestResolutionTile(const TileProviderGroup& tileProviderGroup, TileIndex tileIndex); + static std::vector getTilesSortedByHighestResolution(const TileProviderGroup&, const TileIndex& tileIndex); struct CompareResolution { - bool operator() (const TileAndTransform& a, const TileAndTransform& b); + bool operator() (const ChunkTile& a, const ChunkTile& b); }; static const CompareResolution HIGHEST_RES;