diff --git a/modules/globebrowsing/CMakeLists.txt b/modules/globebrowsing/CMakeLists.txt index 311078c45b..a196f0276a 100644 --- a/modules/globebrowsing/CMakeLists.txt +++ b/modules/globebrowsing/CMakeLists.txt @@ -38,6 +38,8 @@ set(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/rendering/clipmapglobe.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/chunklodglobe.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/frustrumculler.h + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/texturetile.h + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/texturetileset.h ${CMAKE_CURRENT_SOURCE_DIR}/datastructures/chunknode.h ${CMAKE_CURRENT_SOURCE_DIR}/datastructures/latlon.h @@ -45,19 +47,21 @@ set(HEADER_FILES ) set(SOURCE_FILES - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableglobe.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/distanceswitch.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/geometry.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/gridgeometry.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/clipmapgeometry.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/globemesh.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/patchrenderer.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/clipmapglobe.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/chunklodglobe.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/frustrumculler.cpp - - ${CMAKE_CURRENT_SOURCE_DIR}/datastructures/chunknode.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/datastructures/latlon.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableglobe.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/distanceswitch.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/geometry.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/gridgeometry.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/clipmapgeometry.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/globemesh.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/patchrenderer.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/clipmapglobe.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/chunklodglobe.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/frustrumculler.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/texturetile.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/texturetileset.cpp + + ${CMAKE_CURRENT_SOURCE_DIR}/datastructures/chunknode.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/datastructures/latlon.cpp ) source_group("Source Files" FILES ${SOURCE_FILES}) diff --git a/modules/globebrowsing/datastructures/latlon.cpp b/modules/globebrowsing/datastructures/latlon.cpp index 1e66cc37c6..0ff7e23b6b 100644 --- a/modules/globebrowsing/datastructures/latlon.cpp +++ b/modules/globebrowsing/datastructures/latlon.cpp @@ -36,6 +36,11 @@ namespace openspace { // LATITUDE LONGITUDE // ////////////////////////////////////////////////////////////////////////////////////////// + LatLon::LatLon() + : lat(0) + , lon(0) + {} + LatLon::LatLon(Scalar latitude, Scalar longitude) : lat(latitude) , lon(longitude) @@ -62,8 +67,8 @@ namespace openspace { glm::sin(lat)); } - Vec2 LatLon::asVec2() const { - return Vec2(lat, lon); + Vec2 LatLon::toLonLatVec2() const { + return Vec2(lon, lat); } bool LatLon::operator==(const LatLon& other) { diff --git a/modules/globebrowsing/datastructures/latlon.h b/modules/globebrowsing/datastructures/latlon.h index 2d4c034112..fe4bfe363c 100644 --- a/modules/globebrowsing/datastructures/latlon.h +++ b/modules/globebrowsing/datastructures/latlon.h @@ -39,12 +39,13 @@ typedef glm::dvec3 Vec3; namespace openspace { struct LatLon { + LatLon(); LatLon(Scalar latitude, Scalar longitude); LatLon(const LatLon& src); static LatLon fromCartesian(const Vec3& v); Vec3 asUnitCartesian() const; - Vec2 asVec2() const; + Vec2 toLonLatVec2() const; inline bool operator==(const LatLon& other); inline bool operator!=(const LatLon& other) { return !(*this == (other)); } diff --git a/modules/globebrowsing/rendering/frustrumculler.h b/modules/globebrowsing/rendering/frustrumculler.h index 74ac892202..66d5a0fd18 100644 --- a/modules/globebrowsing/rendering/frustrumculler.h +++ b/modules/globebrowsing/rendering/frustrumculler.h @@ -75,6 +75,7 @@ namespace openspace { const glm::vec2& pointScreenSpace, const glm::vec2& marginScreenSpace) const; + glm::vec2 transformToScreenSpace(const vec3& point, const mat4x4& modelViewProjection) const; }; diff --git a/modules/globebrowsing/rendering/patchrenderer.cpp b/modules/globebrowsing/rendering/patchrenderer.cpp index be5658be6d..ae8ae8133e 100644 --- a/modules/globebrowsing/rendering/patchrenderer.cpp +++ b/modules/globebrowsing/rendering/patchrenderer.cpp @@ -102,10 +102,17 @@ namespace openspace { * viewTransform * modelTransform; + // Get the textures that should be used for rendering + glm::ivec3 tileIndex = tileSet.getTileIndex(patch); + LatLonPatch tilePatch = tileSet.getTilePositionAndScale(tileIndex); + TextureTile tile00 = tileSet.getTile(tileIndex); + + // Upload the tile to the GPU (a lot of caching things should be done) + LatLon swCorner = patch.southWestCorner(); _programObject->setUniform("modelViewProjectionTransform", modelViewProjectionTransform); - _programObject->setUniform("minLatLon", vec2(swCorner.lat, swCorner.lon)); - _programObject->setUniform("latLonScalingFactor", 2.0f * vec2(patch.halfSize().asVec2())); + _programObject->setUniform("minLatLon", vec2(swCorner.toLonLatVec2())); + _programObject->setUniform("lonLatScalingFactor", 2.0f * vec2(patch.halfSize().toLonLatVec2())); _programObject->setUniform("globeRadius", float(radius)); glEnable(GL_DEPTH_TEST); @@ -170,8 +177,8 @@ namespace openspace { //LDEBUG("contraction = [ " << contraction.x << " , " << contraction.y << " ]"); _programObject->setUniform("modelViewProjectionTransform", data.camera.projectionMatrix() * viewTransform * modelTransform); - _programObject->setUniform("minLatLon", vec2(swCorner.lat, swCorner.lon)); - _programObject->setUniform("latLonScalingFactor", 2.0f * vec2(halfSize.lat, halfSize.lon)); + _programObject->setUniform("minLatLon", vec2(swCorner.toLonLatVec2())); + _programObject->setUniform("lonLatScalingFactor", 2.0f * vec2(halfSize.toLonLatVec2())); _programObject->setUniform("globeRadius", float(radius)); _programObject->setUniform("contraction", contraction); diff --git a/modules/globebrowsing/rendering/patchrenderer.h b/modules/globebrowsing/rendering/patchrenderer.h index a00ea36ecf..3e48f925b3 100644 --- a/modules/globebrowsing/rendering/patchrenderer.h +++ b/modules/globebrowsing/rendering/patchrenderer.h @@ -34,6 +34,7 @@ #include #include #include +#include namespace ghoul { namespace opengl { @@ -66,6 +67,7 @@ namespace openspace { unique_ptr _programObject; shared_ptr _geometry; + TextureTileSet tileSet; }; diff --git a/modules/globebrowsing/rendering/texturetile.cpp b/modules/globebrowsing/rendering/texturetile.cpp new file mode 100644 index 0000000000..81d8478b7d --- /dev/null +++ b/modules/globebrowsing/rendering/texturetile.cpp @@ -0,0 +1,36 @@ +/***************************************************************************************** +* * +* 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 + +namespace openspace { + TextureTile::TextureTile() + { + } + + TextureTile::~TextureTile() + { + } + +} // namespace openspace diff --git a/modules/globebrowsing/rendering/texturetile.h b/modules/globebrowsing/rendering/texturetile.h new file mode 100644 index 0000000000..ab39afb409 --- /dev/null +++ b/modules/globebrowsing/rendering/texturetile.h @@ -0,0 +1,46 @@ +/***************************************************************************************** +* * +* 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 __TEXTURETILE_H__ +#define __TEXTURETILE_H__ + +#include + +#include + +namespace openspace { + + class TextureTile + { + public: + TextureTile(); + ~TextureTile(); + + private: + glm::ivec2 positionIndex; + int level; + }; +} // namespace openspace + +#endif // __TEXTURETILE_H__ \ No newline at end of file diff --git a/modules/globebrowsing/rendering/texturetileset.cpp b/modules/globebrowsing/rendering/texturetileset.cpp new file mode 100644 index 0000000000..bcea6369cd --- /dev/null +++ b/modules/globebrowsing/rendering/texturetileset.cpp @@ -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. * +****************************************************************************************/ + +#include + +#include + +namespace openspace { + TextureTileSet::TextureTileSet() + { + } + + TextureTileSet::~TextureTileSet() + { + } + + glm::ivec3 TextureTileSet::getTileIndex(LatLonPatch patch) + { + int level = log2(static_cast(glm::max( + sizeLevel0.lat / patch.halfSize().lat * 2, + sizeLevel0.lon / patch.halfSize().lon * 2))); + Vec2 TileSize = sizeLevel0.toLonLatVec2() / pow(2, level); + glm::ivec2 tileIndex = -(patch.northWestCorner().toLonLatVec2() + offsetLevel0.toLonLatVec2()) / TileSize; + return glm::ivec3(tileIndex, level); + } + + TextureTile TextureTileSet::getTile(LatLonPatch patch) + { + return getTile(getTileIndex(patch)); + } + + TextureTile TextureTileSet::getTile(glm::ivec3 tileIndex) + { + return TextureTile(); + } + + LatLonPatch TextureTileSet::getTilePositionAndScale(glm::ivec3 tileIndex) + { + LatLon tileSize = LatLon( + sizeLevel0.lat / pow(2, tileIndex.z), + sizeLevel0.lon / pow(2, tileIndex.z)); + LatLon northWest = LatLon( + offsetLevel0.lat + tileIndex.y * tileSize.lat, + offsetLevel0.lon + tileIndex.x * tileSize.lon); + + return LatLonPatch( + LatLon(northWest.lat + tileSize.lat / 2, northWest.lon + tileSize.lon / 2), + LatLon(tileSize.lat / 2, tileSize.lon / 2)); + } + +} // namespace openspace diff --git a/modules/globebrowsing/rendering/texturetileset.h b/modules/globebrowsing/rendering/texturetileset.h new file mode 100644 index 0000000000..2549a6fcf4 --- /dev/null +++ b/modules/globebrowsing/rendering/texturetileset.h @@ -0,0 +1,56 @@ +/***************************************************************************************** +* * +* 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 __TEXTURETILESET_H__ +#define __TEXTURETILESET_H__ + +#include + +#include +#include + +namespace openspace { + + class TextureTileSet + { + public: + TextureTileSet(); + ~TextureTileSet(); + + /// Returns the index of the tile at an appropriate level. + /// Appropriate meaning that the tile should be at as high level as possible + /// Without the tile being smaller than the patch in lat-lon space. + /// The tile needs to be at least as big as the patch. + glm::ivec3 getTileIndex(LatLonPatch patch); + TextureTile getTile(LatLonPatch patch); + TextureTile getTile(glm::ivec3 tileIndex); + LatLonPatch getTilePositionAndScale(glm::ivec3 tileIndex); + private: + LatLon sizeLevel0; + LatLon offsetLevel0; + }; + +} // namespace openspace + +#endif // __TEXTURETILESET_H__ \ No newline at end of file diff --git a/modules/globebrowsing/shaders/clipmappatch_spheremapping_vs.glsl b/modules/globebrowsing/shaders/clipmappatch_spheremapping_vs.glsl index 73d94191c3..bd3de45487 100644 --- a/modules/globebrowsing/shaders/clipmappatch_spheremapping_vs.glsl +++ b/modules/globebrowsing/shaders/clipmappatch_spheremapping_vs.glsl @@ -28,7 +28,7 @@ uniform mat4 modelViewProjectionTransform; uniform float globeRadius; uniform vec2 minLatLon; -uniform vec2 latLonScalingFactor; +uniform vec2 lonLatScalingFactor; uniform ivec2 contraction; // [-1, 1] layout(location = 1) in vec2 in_uv; @@ -46,10 +46,10 @@ vec3 latLonToCartesian(float latitude, float longitude, float radius) { } vec3 globalInterpolation(vec2 uv) { - vec2 latLonInput; - latLonInput.x = minLatLon.x + latLonScalingFactor.x * uv.y; // Lat - latLonInput.y = minLatLon.y + latLonScalingFactor.y * uv.x; // Lon - vec3 positionModelSpace = latLonToCartesian(latLonInput.x, latLonInput.y, globeRadius); + vec2 lonLatInput; + lonLatInput.y = minLatLon.y + lonLatScalingFactor.y * uv.y; // Lat + lonLatInput.x = minLatLon.x + lonLatScalingFactor.x * uv.x; // Lon + vec3 positionModelSpace = latLonToCartesian(lonLatInput.y, lonLatInput.x, globeRadius); return positionModelSpace; } diff --git a/modules/globebrowsing/shaders/latlonpatch_spheremapping_vs.glsl b/modules/globebrowsing/shaders/latlonpatch_spheremapping_vs.glsl index 19fa3dc6b3..a9052005ba 100644 --- a/modules/globebrowsing/shaders/latlonpatch_spheremapping_vs.glsl +++ b/modules/globebrowsing/shaders/latlonpatch_spheremapping_vs.glsl @@ -28,7 +28,7 @@ uniform mat4 modelViewProjectionTransform; uniform float globeRadius; uniform vec2 minLatLon; -uniform vec2 latLonScalingFactor; +uniform vec2 lonLatScalingFactor; layout(location = 1) in vec2 in_UV; @@ -45,10 +45,10 @@ vec3 latLonToCartesian(float latitude, float longitude, float radius) { } vec3 globalInterpolation() { - vec2 latLonInput; - latLonInput.x = minLatLon.x + latLonScalingFactor.x * in_UV.y; // Lat - latLonInput.y = minLatLon.y + latLonScalingFactor.y * in_UV.x; // Lon - vec3 positionModelSpace = latLonToCartesian(latLonInput.x, latLonInput.y, globeRadius); + vec2 lonLatInput; + lonLatInput.y = minLatLon.y + lonLatScalingFactor.y * in_UV.y; // Lat + lonLatInput.x = minLatLon.x + lonLatScalingFactor.x * in_UV.x; // Lon + vec3 positionModelSpace = latLonToCartesian(lonLatInput.y, lonLatInput.x, globeRadius); return positionModelSpace; }