From 9146fc48c8551df69331d5fe84e7d9f11782fa74 Mon Sep 17 00:00:00 2001 From: Kalle Bladin Date: Tue, 19 Apr 2016 15:20:18 -0400 Subject: [PATCH] Restructured and commented. --- modules/globebrowsing/CMakeLists.txt | 2 - .../datastructures/chunknode.cpp | 2 +- modules/globebrowsing/datastructures/latlon.h | 6 +-- .../globebrowsing/rendering/chunklodglobe.cpp | 2 +- .../globebrowsing/rendering/chunklodglobe.h | 4 +- .../globebrowsing/rendering/clipmapglobe.cpp | 2 +- .../globebrowsing/rendering/clipmapglobe.h | 2 +- modules/globebrowsing/rendering/geometry.h | 14 +++--- .../globebrowsing/rendering/patchrenderer.cpp | 9 +++- .../globebrowsing/rendering/patchrenderer.h | 24 +++------- .../rendering/renderableglobe.cpp | 9 +--- .../globebrowsing/rendering/texturetile.cpp | 36 --------------- modules/globebrowsing/rendering/texturetile.h | 46 ------------------- .../rendering/texturetileset.cpp | 42 ++++++++--------- .../globebrowsing/rendering/texturetileset.h | 26 +++++++++-- modules/globebrowsing/shaders/simple_fs.glsl | 2 +- 16 files changed, 77 insertions(+), 151 deletions(-) delete mode 100644 modules/globebrowsing/rendering/texturetile.cpp delete mode 100644 modules/globebrowsing/rendering/texturetile.h diff --git a/modules/globebrowsing/CMakeLists.txt b/modules/globebrowsing/CMakeLists.txt index ed1be8d47f..e75ebe7fff 100644 --- a/modules/globebrowsing/CMakeLists.txt +++ b/modules/globebrowsing/CMakeLists.txt @@ -38,7 +38,6 @@ 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}/rendering/twmstileprovider.h @@ -59,7 +58,6 @@ set(SOURCE_FILES ${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}/rendering/twmstileprovider.cpp diff --git a/modules/globebrowsing/datastructures/chunknode.cpp b/modules/globebrowsing/datastructures/chunknode.cpp index 91464fb788..dfdeff9ff7 100644 --- a/modules/globebrowsing/datastructures/chunknode.cpp +++ b/modules/globebrowsing/datastructures/chunknode.cpp @@ -116,7 +116,7 @@ bool ChunkNode::internalUpdateChunkTree(const RenderData& data, ChunkIndex& trav void ChunkNode::internalRender(const RenderData& data, ChunkIndex& traverseData) { if (isLeaf()) { - PatchRenderer& patchRenderer = _owner.getPatchRenderer(); + LatLonPatchRenderer& patchRenderer = _owner.getPatchRenderer(); patchRenderer.renderPatch(_patch, data, _owner.globeRadius); } diff --git a/modules/globebrowsing/datastructures/latlon.h b/modules/globebrowsing/datastructures/latlon.h index 83c7aaa7a6..0e4c3c6bb1 100644 --- a/modules/globebrowsing/datastructures/latlon.h +++ b/modules/globebrowsing/datastructures/latlon.h @@ -68,11 +68,11 @@ public: void setHalfSize(const LatLon&); - // Returns the minimal bounding radius that together with the LatLonPatch's - // center point represents a sphere in which the patch is completely contained + /// Returns the minimal bounding radius that together with the LatLonPatch's + /// center point represents a sphere in which the patch is completely contained Scalar minimalBoundingRadius() const; - // Returns the area of the patch with unit radius + /// Returns the area of the patch with unit radius Scalar unitArea() const; diff --git a/modules/globebrowsing/rendering/chunklodglobe.cpp b/modules/globebrowsing/rendering/chunklodglobe.cpp index 7c2cbd17b4..afd0018dcf 100644 --- a/modules/globebrowsing/rendering/chunklodglobe.cpp +++ b/modules/globebrowsing/rendering/chunklodglobe.cpp @@ -108,7 +108,7 @@ namespace openspace { return ready; } - PatchRenderer& ChunkLodGlobe::getPatchRenderer() { + LatLonPatchRenderer& ChunkLodGlobe::getPatchRenderer() { return *_patchRenderer; } diff --git a/modules/globebrowsing/rendering/chunklodglobe.h b/modules/globebrowsing/rendering/chunklodglobe.h index bab0d747c0..650ae3ef83 100644 --- a/modules/globebrowsing/rendering/chunklodglobe.h +++ b/modules/globebrowsing/rendering/chunklodglobe.h @@ -56,7 +56,7 @@ namespace openspace { ChunkLodGlobe(const ghoul::Dictionary& dictionary); ~ChunkLodGlobe(); - PatchRenderer& getPatchRenderer(); + LatLonPatchRenderer& getPatchRenderer(); FrustrumCuller& getFrustrumCuller(); bool initialize() override; @@ -86,7 +86,7 @@ namespace openspace { std::shared_ptr _frustrumCuller; // the patch used for actual rendering - std::unique_ptr _patchRenderer; + std::unique_ptr _patchRenderer; static const LatLonPatch LEFT_HEMISPHERE; diff --git a/modules/globebrowsing/rendering/clipmapglobe.cpp b/modules/globebrowsing/rendering/clipmapglobe.cpp index c97e0598b6..7601137ed7 100644 --- a/modules/globebrowsing/rendering/clipmapglobe.cpp +++ b/modules/globebrowsing/rendering/clipmapglobe.cpp @@ -65,7 +65,7 @@ namespace openspace { if (_target != "") setBody(_target); - size_t numPatches = 5; + size_t numPatches = 10; for (size_t i = 0; i < numPatches; i++) { _patches.push_back(LatLonPatch( diff --git a/modules/globebrowsing/rendering/clipmapglobe.h b/modules/globebrowsing/rendering/clipmapglobe.h index 4e82d085e4..e1ef78c87e 100644 --- a/modules/globebrowsing/rendering/clipmapglobe.h +++ b/modules/globebrowsing/rendering/clipmapglobe.h @@ -58,7 +58,7 @@ namespace openspace { void update(const UpdateData& data) override; private: - std::unique_ptr _patchRenderer; + std::unique_ptr _patchRenderer; std::vector _patches; properties::IntProperty _rotation; diff --git a/modules/globebrowsing/rendering/geometry.h b/modules/globebrowsing/rendering/geometry.h index 5064e88f0b..a89669168e 100644 --- a/modules/globebrowsing/rendering/geometry.h +++ b/modules/globebrowsing/rendering/geometry.h @@ -34,12 +34,14 @@ namespace openspace { -/** - Class to hold vertex data and handling OpenGL interfacing and rendering. A Geometry - has all data needed such as position buffer and normal buffer but all data is not - necessarily needed for all purpouses so the Geometry can disable use of normals for - example. -*/ +/// Class to hold vertex data and handling OpenGL interfacing and rendering. A Geometry +/// has all data needed such as position buffer and normal buffer but all data is not +/// necessarily needed for all purpouses so the Geometry can disable use of normals for +/// example. + + // TODO : Possibly render triangle strips in this class instead of triangles since + // that is faster + class Geometry { public: diff --git a/modules/globebrowsing/rendering/patchrenderer.cpp b/modules/globebrowsing/rendering/patchrenderer.cpp index d1a8d3f521..c92dca1b62 100644 --- a/modules/globebrowsing/rendering/patchrenderer.cpp +++ b/modules/globebrowsing/rendering/patchrenderer.cpp @@ -99,7 +99,10 @@ namespace openspace { } void LatLonPatchRenderer::renderPatch( - const LatLonPatch& patch, const RenderData& data, double radius, const TileIndex& tileIndex) + const LatLonPatch& patch, + const RenderData& data, + double radius, + const TileIndex& tileIndex) { using namespace glm; @@ -165,7 +168,9 @@ namespace openspace { } void ClipMapPatchRenderer::renderPatch( - const LatLonPatch& patch, const RenderData& data, double radius) + const LatLonPatch& patch, + const RenderData& data, + double radius) { // activate shader _programObject->activate(); diff --git a/modules/globebrowsing/rendering/patchrenderer.h b/modules/globebrowsing/rendering/patchrenderer.h index 850a5535ba..6c49ca4677 100644 --- a/modules/globebrowsing/rendering/patchrenderer.h +++ b/modules/globebrowsing/rendering/patchrenderer.h @@ -57,10 +57,7 @@ namespace openspace { PatchRenderer(shared_ptr); ~PatchRenderer(); - - virtual void renderPatch(const LatLonPatch& patch, const RenderData& data, double radius) = 0; - virtual void renderPatch(const LatLonPatch& patch, const RenderData& data, double radius, const TileIndex& ti) = 0; - + protected: unique_ptr _programObject; @@ -78,16 +75,16 @@ namespace openspace { public: LatLonPatchRenderer(shared_ptr); - virtual void renderPatch( + void renderPatch( const LatLonPatch& patch, const RenderData& data, - double radius) override; + double radius); - virtual void renderPatch( + void renderPatch( const LatLonPatch& patch, const RenderData& data, double radius, - const TileIndex& ti) override; + const TileIndex& ti); }; @@ -96,17 +93,10 @@ namespace openspace { public: ClipMapPatchRenderer(); - virtual void renderPatch( + void renderPatch( const LatLonPatch& patch, const RenderData& data, - double radius) override; - - virtual void renderPatch( - const LatLonPatch& patch, - const RenderData& data, - double radius, - const TileIndex& ti) { /* empty */}; - + double radius); }; } // namespace openspace diff --git a/modules/globebrowsing/rendering/renderableglobe.cpp b/modules/globebrowsing/rendering/renderableglobe.cpp index d295117c20..f1594d9b96 100644 --- a/modules/globebrowsing/rendering/renderableglobe.cpp +++ b/modules/globebrowsing/rendering/renderableglobe.cpp @@ -37,11 +37,6 @@ // ghoul includes #include - - -#define _USE_MATH_DEFINES -#include - namespace { const std::string _loggerCat = "RenderableGlobe"; @@ -71,8 +66,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/texturetile.cpp b/modules/globebrowsing/rendering/texturetile.cpp deleted file mode 100644 index 81d8478b7d..0000000000 --- a/modules/globebrowsing/rendering/texturetile.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/***************************************************************************************** -* * -* 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 deleted file mode 100644 index 05fa81a2fc..0000000000 --- a/modules/globebrowsing/rendering/texturetile.h +++ /dev/null @@ -1,46 +0,0 @@ -/***************************************************************************************** -* * -* 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 - -#include -#include - -namespace openspace { - - class TextureTile - { - public: - TextureTile(); - ~TextureTile(); - - private: - }; -} // 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 index 13445423dc..29ee7b8bfb 100644 --- a/modules/globebrowsing/rendering/texturetileset.cpp +++ b/modules/globebrowsing/rendering/texturetileset.cpp @@ -33,10 +33,6 @@ #include - - - - namespace { const std::string _loggerCat = "TextureTileSet"; } @@ -60,17 +56,6 @@ namespace openspace { //_testTexture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap); _testTexture->setFilter(ghoul::opengl::Texture::FilterMode::Linear); } - /* - int dataSize = _testTexture->width() * _testTexture->height() * _testTexture->bytesPerPixel(); - GLubyte* data = new GLubyte[dataSize]; - for (size_t i = 0; i < dataSize; i++) - { - data[i] = unsigned char(i / float(dataSize) * 255); - } - _testTexture->setPixelData(data); - _testTexture->uploadTexture(); - */ - } TextureTileSet::~TextureTileSet(){ @@ -78,10 +63,17 @@ namespace openspace { } TileIndex TextureTileSet::getTileIndex(LatLonPatch patch) { + // Calculate the level of the index depanding on the size of the incoming patch. + // The level is as big as possible (as far down as possible) but it can't be + // too big since at maximum four tiles should be used to cover a patch int level = log2(static_cast(glm::max( _sizeLevel0.lat / (patch.size().lat), _sizeLevel0.lon / (patch.size().lon)))); + + // If the depth is not big enough, the level must be clamped. level = glm::min(level, _depth); + + // Calculate the index in x y where the tile should be positioned Vec2 tileSize = _sizeLevel0.toLonLatVec2() / pow(2, level); Vec2 nw = patch.northWestCorner().toLonLatVec2(); Vec2 offset = _offsetLevel0.toLonLatVec2(); @@ -90,6 +82,7 @@ namespace openspace { // Flip y since indices increase from top to bottom tileIndexXY.y *= -1; + // Create the tileindex TileIndex tileIndex = { tileIndexXY.x, tileIndexXY.y, level }; return tileIndex; } @@ -120,22 +113,29 @@ namespace openspace { const TileIndex& tileIndex) { LatLonPatch tile = getTilePositionAndScale(tileIndex); + return getUvTransformationPatchToTile(patch, tile); + } + + glm::mat3 TextureTileSet::getUvTransformationPatchToTile( + LatLonPatch patch, + LatLonPatch tile) + { Vec2 posDiff = - patch.southWestCorner().toLonLatVec2() - + patch.southWestCorner().toLonLatVec2() - tile.southWestCorner().toLonLatVec2(); - + glm::mat3 invTileScale = glm::mat3( - {1 / (tile.halfSize().lon * 2), 0, 0, + { 1 / (tile.halfSize().lon * 2), 0, 0, 0, 1 / (tile.halfSize().lat * 2), 0, - 0, 0, 1}); + 0, 0, 1 }); glm::mat3 globalTranslation = glm::mat3( { 1, 0, 0, 0, 1, 0, posDiff.x, posDiff.y, 1 }); - + glm::mat3 patchScale = glm::mat3( - { (patch.halfSize().lon * 2), 0, 0, + { (patch.halfSize().lon * 2), 0, 0, 0, (patch.halfSize().lat * 2), 0, 0, 0, 1 }); diff --git a/modules/globebrowsing/rendering/texturetileset.h b/modules/globebrowsing/rendering/texturetileset.h index 7ae17b52ec..189df7e8b0 100644 --- a/modules/globebrowsing/rendering/texturetileset.h +++ b/modules/globebrowsing/rendering/texturetileset.h @@ -31,7 +31,6 @@ #include #include -#include @@ -40,8 +39,8 @@ // TEXTURE TILE SET // ////////////////////////////////////////////////////////////////////////////////////////// - namespace openspace { + using namespace ghoul::opengl; class TextureTileSet @@ -55,11 +54,30 @@ namespace openspace { /// Without the tile being smaller than the patch in lat-lon space. /// The tile is at least as big as the patch. TileIndex getTileIndex(LatLonPatch patch); + + /// Returns a texture that can be used for the specified patch std::shared_ptr getTile(LatLonPatch patch); - + + /// Returns the texture for the given tile index. The indices reaches from left + /// to right and top to bottom while the texture coordinates and the latlon + /// coordinates reaches from left to right and bottom to top. std::shared_ptr getTile(const TileIndex& tileIndex); + + /// A tile can be defined with a tile index or a LatLonPatch which defines + /// the position and the size of the tile. LatLonPatch getTilePositionAndScale(const TileIndex& tileIndex); - glm::mat3 getUvTransformationPatchToTile(LatLonPatch patch, const TileIndex& tileIndex); + + /// A transformation (translation and scaling) from the texture space of a patch + /// to the texture space of a tile. + glm::mat3 getUvTransformationPatchToTile( + LatLonPatch patch, + const TileIndex& tileIndex); + + /// Overloaded function + glm::mat3 getUvTransformationPatchToTile( + LatLonPatch patch, + LatLonPatch tile); + private: LatLon _sizeLevel0; LatLon _offsetLevel0; diff --git a/modules/globebrowsing/shaders/simple_fs.glsl b/modules/globebrowsing/shaders/simple_fs.glsl index 697502db24..7405389c2b 100644 --- a/modules/globebrowsing/shaders/simple_fs.glsl +++ b/modules/globebrowsing/shaders/simple_fs.glsl @@ -49,7 +49,7 @@ Fragment getFragment() { Fragment frag; frag.color = texture(textureSampler, vec2(uvTransformPatchToTile * vec3(vs_uv.s, vs_uv.t, 1))); - frag.color = frag.color * 1.0 + vec4(fract(vs_uv * 1), 0.4,1) * 0.2; + frag.color = frag.color * 1.0 + vec4(fract(vs_uv * 32), 0.4,1) * 0.2; frag.depth = pscDepth(vs_position); return frag;