Restructured and commented.

This commit is contained in:
Kalle Bladin
2016-04-19 15:20:18 -04:00
parent aaa099d542
commit 9146fc48c8
16 changed files with 77 additions and 151 deletions

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -108,7 +108,7 @@ namespace openspace {
return ready;
}
PatchRenderer& ChunkLodGlobe::getPatchRenderer() {
LatLonPatchRenderer& ChunkLodGlobe::getPatchRenderer() {
return *_patchRenderer;
}

View File

@@ -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> _frustrumCuller;
// the patch used for actual rendering
std::unique_ptr<PatchRenderer> _patchRenderer;
std::unique_ptr<LatLonPatchRenderer> _patchRenderer;
static const LatLonPatch LEFT_HEMISPHERE;

View File

@@ -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(

View File

@@ -58,7 +58,7 @@ namespace openspace {
void update(const UpdateData& data) override;
private:
std::unique_ptr<PatchRenderer> _patchRenderer;
std::unique_ptr<ClipMapPatchRenderer> _patchRenderer;
std::vector<LatLonPatch> _patches;
properties::IntProperty _rotation;

View File

@@ -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:

View File

@@ -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();

View File

@@ -57,10 +57,7 @@ namespace openspace {
PatchRenderer(shared_ptr<Geometry>);
~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> _programObject;
@@ -78,16 +75,16 @@ namespace openspace {
public:
LatLonPatchRenderer(shared_ptr<Geometry>);
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

View File

@@ -37,11 +37,6 @@
// ghoul includes
#include <ghoul/misc/assert.h>
#define _USE_MATH_DEFINES
#include <math.h>
namespace {
const std::string _loggerCat = "RenderableGlobe";
@@ -71,8 +66,8 @@ namespace openspace {
// Mainly for debugging purposes @AA
addProperty(_rotation);
//addSwitchValue(std::shared_ptr<ClipMapGlobe>(new ClipMapGlobe(dictionary)), 1e9);
addSwitchValue(std::shared_ptr<ChunkLodGlobe>(new ChunkLodGlobe(dictionary)), 1e9);
addSwitchValue(std::shared_ptr<ClipMapGlobe>(new ClipMapGlobe(dictionary)), 1e9);
//addSwitchValue(std::shared_ptr<ChunkLodGlobe>(new ChunkLodGlobe(dictionary)), 1e9);
addSwitchValue(std::shared_ptr<GlobeMesh>(new GlobeMesh(dictionary)), 1e10);

View File

@@ -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 <modules/globebrowsing/rendering/texturetile.h>
namespace openspace {
TextureTile::TextureTile()
{
}
TextureTile::~TextureTile()
{
}
} // namespace openspace

View File

@@ -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 <ghoul/logging/logmanager.h>
#include <ghoul/opengl/ghoul_gl.h>
#include <glm/glm.hpp>
#include <memory>
namespace openspace {
class TextureTile
{
public:
TextureTile();
~TextureTile();
private:
};
} // namespace openspace
#endif // __TEXTURETILE_H__

View File

@@ -33,10 +33,6 @@
#include <glm/glm.hpp>
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<int>(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 });

View File

@@ -31,7 +31,6 @@
#include <modules/globebrowsing/datastructures/latlon.h>
#include <modules/globebrowsing/rendering/twmstileprovider.h>
#include <modules/globebrowsing/rendering/texturetile.h>
@@ -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<Texture> 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<Texture> 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;

View File

@@ -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;