From 9a31b116399c2184da94a4d216744bf5dfd38428 Mon Sep 17 00:00:00 2001 From: Kalle Bladin Date: Thu, 14 Apr 2016 19:29:58 -0400 Subject: [PATCH 1/4] Added classes TextureTile and TextureTileSet. --- modules/globebrowsing/CMakeLists.txt | 30 +++++----- .../globebrowsing/datastructures/latlon.cpp | 5 ++ modules/globebrowsing/datastructures/latlon.h | 1 + .../globebrowsing/rendering/patchrenderer.cpp | 8 ++- .../globebrowsing/rendering/patchrenderer.h | 2 + .../globebrowsing/rendering/texturetile.cpp | 36 ++++++++++++ modules/globebrowsing/rendering/texturetile.h | 46 +++++++++++++++ .../rendering/texturetileset.cpp | 58 +++++++++++++++++++ .../globebrowsing/rendering/texturetileset.h | 55 ++++++++++++++++++ .../shaders/latlonpatch_spheremapping_vs.glsl | 4 +- 10 files changed, 228 insertions(+), 17 deletions(-) create mode 100644 modules/globebrowsing/rendering/texturetile.cpp create mode 100644 modules/globebrowsing/rendering/texturetile.h create mode 100644 modules/globebrowsing/rendering/texturetileset.cpp create mode 100644 modules/globebrowsing/rendering/texturetileset.h 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 4d9f37545d..d140df65cd 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) diff --git a/modules/globebrowsing/datastructures/latlon.h b/modules/globebrowsing/datastructures/latlon.h index 1999f8a0d0..df082e8d9d 100644 --- a/modules/globebrowsing/datastructures/latlon.h +++ b/modules/globebrowsing/datastructures/latlon.h @@ -39,6 +39,7 @@ typedef glm::dvec3 Vec3; namespace openspace { struct LatLon { + LatLon(); LatLon(Scalar latitude, Scalar longitude); LatLon(const LatLon& src); diff --git a/modules/globebrowsing/rendering/patchrenderer.cpp b/modules/globebrowsing/rendering/patchrenderer.cpp index ca3d61219e..325fcfaec6 100644 --- a/modules/globebrowsing/rendering/patchrenderer.cpp +++ b/modules/globebrowsing/rendering/patchrenderer.cpp @@ -119,9 +119,13 @@ namespace openspace { } } + // 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)); diff --git a/modules/globebrowsing/rendering/patchrenderer.h b/modules/globebrowsing/rendering/patchrenderer.h index a1b04e1600..68f2fa360d 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 { @@ -67,6 +68,7 @@ namespace openspace { shared_ptr _geometry; shared_ptr _frustrumCuller; + 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..bc444b6be0 --- /dev/null +++ b/modules/globebrowsing/rendering/texturetileset.cpp @@ -0,0 +1,58 @@ +/***************************************************************************************** +* * +* 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.asVec2() / pow(2, level); + glm::ivec2 tileIndex = -(patch.northWestCorner().asVec2() + offsetLevel0.asVec2()) / TileSize; + return glm::ivec3(tileIndex, level); + } + + TextureTile TextureTileSet::getTile(glm::ivec3 tileIndex) + { + return TextureTile(); + } + + LatLonPatch TextureTileSet::getTilePositionAndScale(glm::ivec3 tileIndex) + { + return LatLonPatch(LatLon(), LatLon()); + } + +} // namespace openspace diff --git a/modules/globebrowsing/rendering/texturetileset.h b/modules/globebrowsing/rendering/texturetileset.h new file mode 100644 index 0000000000..a59683273e --- /dev/null +++ b/modules/globebrowsing/rendering/texturetileset.h @@ -0,0 +1,55 @@ +/***************************************************************************************** +* * +* 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(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/latlonpatch_spheremapping_vs.glsl b/modules/globebrowsing/shaders/latlonpatch_spheremapping_vs.glsl index 19fa3dc6b3..a97a361e15 100644 --- a/modules/globebrowsing/shaders/latlonpatch_spheremapping_vs.glsl +++ b/modules/globebrowsing/shaders/latlonpatch_spheremapping_vs.glsl @@ -46,8 +46,8 @@ 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 + latLonInput.x = minLatLon.x + latLonScalingFactor.x * in_UV.x; // Lat + latLonInput.y = minLatLon.y + latLonScalingFactor.y * in_UV.y; // Lon vec3 positionModelSpace = latLonToCartesian(latLonInput.x, latLonInput.y, globeRadius); return positionModelSpace; } From acf4297491e18a4a3f7d9690df202d866755b795 Mon Sep 17 00:00:00 2001 From: Kalle Bladin Date: Thu, 14 Apr 2016 19:35:24 -0400 Subject: [PATCH 2/4] Changed definition of ordering in LatLon --- modules/globebrowsing/datastructures/latlon.cpp | 2 +- modules/globebrowsing/rendering/patchrenderer.cpp | 4 ++-- .../shaders/clipmappatch_spheremapping_vs.glsl | 6 +++--- .../globebrowsing/shaders/latlonpatch_spheremapping_vs.glsl | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/globebrowsing/datastructures/latlon.cpp b/modules/globebrowsing/datastructures/latlon.cpp index d140df65cd..1e4d73e385 100644 --- a/modules/globebrowsing/datastructures/latlon.cpp +++ b/modules/globebrowsing/datastructures/latlon.cpp @@ -68,7 +68,7 @@ namespace openspace { } Vec2 LatLon::asVec2() const { - return Vec2(lat, lon); + return Vec2(lon, lat); } bool LatLon::operator==(const LatLon& other) { diff --git a/modules/globebrowsing/rendering/patchrenderer.cpp b/modules/globebrowsing/rendering/patchrenderer.cpp index 325fcfaec6..3fd3639825 100644 --- a/modules/globebrowsing/rendering/patchrenderer.cpp +++ b/modules/globebrowsing/rendering/patchrenderer.cpp @@ -128,7 +128,7 @@ namespace openspace { LatLon swCorner = patch.southWestCorner(); _programObject->setUniform("modelViewProjectionTransform", modelViewProjectionTransform); - _programObject->setUniform("minLatLon", vec2(swCorner.lat, swCorner.lon)); + _programObject->setUniform("minLatLon", vec2(swCorner.asVec2())); _programObject->setUniform("latLonScalingFactor", 2.0f * vec2(patch.halfSize.asVec2())); _programObject->setUniform("globeRadius", float(radius)); @@ -200,7 +200,7 @@ 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("minLatLon", vec2(swCorner.asVec2())); _programObject->setUniform("latLonScalingFactor", 2.0f * vec2(patch.halfSize.lat, patch.halfSize.lon)); _programObject->setUniform("globeRadius", float(radius)); _programObject->setUniform("contraction", contraction); diff --git a/modules/globebrowsing/shaders/clipmappatch_spheremapping_vs.glsl b/modules/globebrowsing/shaders/clipmappatch_spheremapping_vs.glsl index 73d94191c3..02158ca187 100644 --- a/modules/globebrowsing/shaders/clipmappatch_spheremapping_vs.glsl +++ b/modules/globebrowsing/shaders/clipmappatch_spheremapping_vs.glsl @@ -47,9 +47,9 @@ 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); + latLonInput.y = minLatLon.y + latLonScalingFactor.y * uv.y; // Lat + latLonInput.x = minLatLon.x + latLonScalingFactor.x * uv.x; // Lon + vec3 positionModelSpace = latLonToCartesian(latLonInput.y, latLonInput.x, globeRadius); return positionModelSpace; } diff --git a/modules/globebrowsing/shaders/latlonpatch_spheremapping_vs.glsl b/modules/globebrowsing/shaders/latlonpatch_spheremapping_vs.glsl index a97a361e15..a96f786ea4 100644 --- a/modules/globebrowsing/shaders/latlonpatch_spheremapping_vs.glsl +++ b/modules/globebrowsing/shaders/latlonpatch_spheremapping_vs.glsl @@ -46,9 +46,9 @@ vec3 latLonToCartesian(float latitude, float longitude, float radius) { vec3 globalInterpolation() { vec2 latLonInput; - latLonInput.x = minLatLon.x + latLonScalingFactor.x * in_UV.x; // Lat - latLonInput.y = minLatLon.y + latLonScalingFactor.y * in_UV.y; // Lon - vec3 positionModelSpace = latLonToCartesian(latLonInput.x, latLonInput.y, globeRadius); + latLonInput.y = minLatLon.y + latLonScalingFactor.y * in_UV.y; // Lat + latLonInput.x = minLatLon.x + latLonScalingFactor.x * in_UV.x; // Lon + vec3 positionModelSpace = latLonToCartesian(latLonInput.y, latLonInput.x, globeRadius); return positionModelSpace; } From 4fd0b0643c502b2be673efee1d8519bbf659db46 Mon Sep 17 00:00:00 2001 From: Kalle Bladin Date: Thu, 14 Apr 2016 20:27:43 -0400 Subject: [PATCH 3/4] Clearified latlon interface. --- modules/globebrowsing/datastructures/latlon.cpp | 2 +- modules/globebrowsing/datastructures/latlon.h | 2 +- modules/globebrowsing/rendering/patchrenderer.cpp | 8 ++++---- modules/globebrowsing/rendering/texturetileset.cpp | 4 ++-- .../shaders/clipmappatch_spheremapping_vs.glsl | 10 +++++----- .../shaders/latlonpatch_spheremapping_vs.glsl | 10 +++++----- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/modules/globebrowsing/datastructures/latlon.cpp b/modules/globebrowsing/datastructures/latlon.cpp index 1e4d73e385..07c4552074 100644 --- a/modules/globebrowsing/datastructures/latlon.cpp +++ b/modules/globebrowsing/datastructures/latlon.cpp @@ -67,7 +67,7 @@ namespace openspace { glm::sin(lat)); } - Vec2 LatLon::asVec2() const { + Vec2 LatLon::toLonLatVec2() const { return Vec2(lon, lat); } diff --git a/modules/globebrowsing/datastructures/latlon.h b/modules/globebrowsing/datastructures/latlon.h index df082e8d9d..6a7c80c181 100644 --- a/modules/globebrowsing/datastructures/latlon.h +++ b/modules/globebrowsing/datastructures/latlon.h @@ -45,7 +45,7 @@ struct LatLon { static LatLon fromCartesian(const Vec3& v); Vec3 asUnitCartesian(); - 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/patchrenderer.cpp b/modules/globebrowsing/rendering/patchrenderer.cpp index 3fd3639825..a9c4757f5b 100644 --- a/modules/globebrowsing/rendering/patchrenderer.cpp +++ b/modules/globebrowsing/rendering/patchrenderer.cpp @@ -128,8 +128,8 @@ namespace openspace { LatLon swCorner = patch.southWestCorner(); _programObject->setUniform("modelViewProjectionTransform", modelViewProjectionTransform); - _programObject->setUniform("minLatLon", vec2(swCorner.asVec2())); - _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); @@ -200,8 +200,8 @@ namespace openspace { //LDEBUG("contraction = [ " << contraction.x << " , " << contraction.y << " ]"); _programObject->setUniform("modelViewProjectionTransform", data.camera.projectionMatrix() * viewTransform * modelTransform); - _programObject->setUniform("minLatLon", vec2(swCorner.asVec2())); - _programObject->setUniform("latLonScalingFactor", 2.0f * vec2(patch.halfSize.lat, patch.halfSize.lon)); + _programObject->setUniform("minLatLon", vec2(swCorner.toLonLatVec2())); + _programObject->setUniform("lonLatScalingFactor", 2.0f * vec2(patch.halfSize.toLonLatVec2())); _programObject->setUniform("globeRadius", float(radius)); _programObject->setUniform("contraction", contraction); diff --git a/modules/globebrowsing/rendering/texturetileset.cpp b/modules/globebrowsing/rendering/texturetileset.cpp index bc444b6be0..5b7ef25526 100644 --- a/modules/globebrowsing/rendering/texturetileset.cpp +++ b/modules/globebrowsing/rendering/texturetileset.cpp @@ -40,8 +40,8 @@ namespace openspace { int level = log2(static_cast(glm::max( sizeLevel0.lat / patch.halfSize.lat * 2, sizeLevel0.lon / patch.halfSize.lon * 2))); - Vec2 TileSize = sizeLevel0.asVec2() / pow(2, level); - glm::ivec2 tileIndex = -(patch.northWestCorner().asVec2() + offsetLevel0.asVec2()) / TileSize; + Vec2 TileSize = sizeLevel0.toLonLatVec2() / pow(2, level); + glm::ivec2 tileIndex = -(patch.northWestCorner().toLonLatVec2() + offsetLevel0.toLonLatVec2()) / TileSize; return glm::ivec3(tileIndex, level); } diff --git a/modules/globebrowsing/shaders/clipmappatch_spheremapping_vs.glsl b/modules/globebrowsing/shaders/clipmappatch_spheremapping_vs.glsl index 02158ca187..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.y = minLatLon.y + latLonScalingFactor.y * uv.y; // Lat - latLonInput.x = minLatLon.x + latLonScalingFactor.x * uv.x; // Lon - vec3 positionModelSpace = latLonToCartesian(latLonInput.y, latLonInput.x, 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 a96f786ea4..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.y = minLatLon.y + latLonScalingFactor.y * in_UV.y; // Lat - latLonInput.x = minLatLon.x + latLonScalingFactor.x * in_UV.x; // Lon - vec3 positionModelSpace = latLonToCartesian(latLonInput.y, latLonInput.x, 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; } From 0f88b922f798c148f768f06b8ea7f880cf7dc8ac Mon Sep 17 00:00:00 2001 From: Kalle Bladin Date: Fri, 15 Apr 2016 10:38:40 -0400 Subject: [PATCH 4/4] Define interface for TextureTileSet. --- .../globebrowsing/rendering/patchrenderer.cpp | 2 +- .../globebrowsing/rendering/renderableglobe.cpp | 4 ++-- .../globebrowsing/rendering/texturetileset.cpp | 16 +++++++++++++++- modules/globebrowsing/rendering/texturetileset.h | 1 + 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/modules/globebrowsing/rendering/patchrenderer.cpp b/modules/globebrowsing/rendering/patchrenderer.cpp index b3da920666..3f7aba2706 100644 --- a/modules/globebrowsing/rendering/patchrenderer.cpp +++ b/modules/globebrowsing/rendering/patchrenderer.cpp @@ -161,7 +161,7 @@ namespace openspace { _programObject->activate(); using namespace glm; - const mat4& viewTransform = data.camera.combinedViewMatrix(); + mat4 viewTransform = data.camera.combinedViewMatrix(); // TODO : Model transform should be fetched as a matrix directly. mat4 modelTransform = translate(mat4(1), data.position.vec3()); diff --git a/modules/globebrowsing/rendering/renderableglobe.cpp b/modules/globebrowsing/rendering/renderableglobe.cpp index 2a7ab9a3f1..c22f8d8490 100644 --- a/modules/globebrowsing/rendering/renderableglobe.cpp +++ b/modules/globebrowsing/rendering/renderableglobe.cpp @@ -71,8 +71,8 @@ namespace openspace { // Mainly for debugging purposes @AA addProperty(_rotation); - //addSwitchValue(std::shared_ptr(new ClipMapGlobe(dictionary)), 1e9); - addSwitchValue(std::shared_ptr(new ChunkLodGlobe(dictionary)), 1e9); + addSwitchValue(std::shared_ptr(new ClipMapGlobe(dictionary)), 1e9); + //addSwitchValue(std::shared_ptr(new ChunkLodGlobe(dictionary)), 1e9); addSwitchValue(std::shared_ptr(new GlobeMesh(dictionary)), 1e10); } diff --git a/modules/globebrowsing/rendering/texturetileset.cpp b/modules/globebrowsing/rendering/texturetileset.cpp index 5b7ef25526..a3119c8570 100644 --- a/modules/globebrowsing/rendering/texturetileset.cpp +++ b/modules/globebrowsing/rendering/texturetileset.cpp @@ -45,6 +45,11 @@ namespace openspace { return glm::ivec3(tileIndex, level); } + TextureTile TextureTileSet::getTile(LatLonPatch patch) + { + return getTile(getTileIndex(patch)); + } + TextureTile TextureTileSet::getTile(glm::ivec3 tileIndex) { return TextureTile(); @@ -52,7 +57,16 @@ namespace openspace { LatLonPatch TextureTileSet::getTilePositionAndScale(glm::ivec3 tileIndex) { - return LatLonPatch(LatLon(), LatLon()); + 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 index a59683273e..2549a6fcf4 100644 --- a/modules/globebrowsing/rendering/texturetileset.h +++ b/modules/globebrowsing/rendering/texturetileset.h @@ -43,6 +43,7 @@ namespace openspace { /// 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: