Added classes TextureTile and TextureTileSet.

This commit is contained in:
Kalle Bladin
2016-04-14 19:29:58 -04:00
parent eeaa4925ba
commit 9a31b11639
10 changed files with 228 additions and 17 deletions
+17 -13
View File
@@ -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})
@@ -36,6 +36,11 @@ namespace openspace {
// LATITUDE LONGITUDE //
//////////////////////////////////////////////////////////////////////////////////////////
LatLon::LatLon()
: lat(0)
, lon(0)
{}
LatLon::LatLon(Scalar latitude, Scalar longitude)
: lat(latitude)
, lon(longitude)
@@ -39,6 +39,7 @@ typedef glm::dvec3 Vec3;
namespace openspace {
struct LatLon {
LatLon();
LatLon(Scalar latitude, Scalar longitude);
LatLon(const LatLon& src);
@@ -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));
@@ -34,6 +34,7 @@
#include <modules/globebrowsing/datastructures/latlon.h>
#include <modules/globebrowsing/rendering/gridgeometry.h>
#include <modules/globebrowsing/rendering/frustrumculler.h>
#include <modules/globebrowsing/rendering/texturetileset.h>
namespace ghoul {
namespace opengl {
@@ -67,6 +68,7 @@ namespace openspace {
shared_ptr<Geometry> _geometry;
shared_ptr<FrustrumCuller> _frustrumCuller;
TextureTileSet tileSet;
};
@@ -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 <modules/globebrowsing/rendering/texturetile.h>
namespace openspace {
TextureTile::TextureTile()
{
}
TextureTile::~TextureTile()
{
}
} // namespace openspace
@@ -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 <ghoul/logging/logmanager.h>
#include <glm/glm.hpp>
namespace openspace {
class TextureTile
{
public:
TextureTile();
~TextureTile();
private:
glm::ivec2 positionIndex;
int level;
};
} // namespace openspace
#endif // __TEXTURETILE_H__
@@ -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 <modules/globebrowsing/rendering/texturetileset.h>
#include <glm/glm.hpp>
namespace openspace {
TextureTileSet::TextureTileSet()
{
}
TextureTileSet::~TextureTileSet()
{
}
glm::ivec3 TextureTileSet::getTileIndex(LatLonPatch patch)
{
int level = log2(static_cast<int>(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
@@ -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 <ghoul/logging/logmanager.h>
#include <modules/globebrowsing/datastructures/latlon.h>
#include <modules/globebrowsing/rendering/texturetile.h>
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__
@@ -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;
}