Reading textures that are used for patch rendering.

This commit is contained in:
Kalle Bladin
2016-04-15 17:17:31 -04:00
parent 0f88b922f7
commit 89d7b3ca8b
7 changed files with 62 additions and 29 deletions

View File

@@ -31,9 +31,11 @@
#include <openspace/engine/openspaceengine.h>
#include <openspace/rendering/renderengine.h>
// ghoul includes
#include <ghoul/misc/assert.h>
#include <ghoul/opengl/texture.h>
#include <ghoul/opengl/textureunit.h>
#define _USE_MATH_DEFINES
#include <math.h>
@@ -113,13 +115,17 @@ namespace openspace {
return;
}
}
// 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);
std::shared_ptr<ghoul::opengl::Texture> tile00 = tileSet.getTile(tileIndex);
// Upload the tile to the GPU (a lot of caching things should be done)
// Bind and use the texture
ghoul::opengl::TextureUnit texUnit;
texUnit.activate();
tile00->bind();
_programObject->setUniform("textureSampler", texUnit);
LatLon swCorner = patch.southWestCorner();
_programObject->setUniform("modelViewProjectionTransform", modelViewProjectionTransform);

View File

@@ -71,8 +71,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

@@ -22,8 +22,8 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __PLANET_H__
#define __PLANET_H__
#ifndef __RENDERABLEGLOBE_H__
#define __RENDERABLEGLOBE_H__
#include <ghoul/logging/logmanager.h>
@@ -66,4 +66,4 @@ private:
} // namespace openspace
#endif // __PLANET_H__
#endif // __RENDERABLEGLOBE_H__

View File

@@ -26,8 +26,10 @@
#define __TEXTURETILE_H__
#include <ghoul/logging/logmanager.h>
#include <ghoul/opengl/ghoul_gl.h>
#include <glm/glm.hpp>
#include <memory>
namespace openspace {
@@ -38,8 +40,6 @@ namespace openspace {
~TextureTile();
private:
glm::ivec2 positionIndex;
int level;
};
} // namespace openspace

View File

@@ -23,12 +23,32 @@
****************************************************************************************/
#include <modules/globebrowsing/rendering/texturetileset.h>
#include <ghoul/opengl/texturemanager.h>
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/logging/logmanager.h>
#include <glm/glm.hpp>
namespace {
const std::string _loggerCat = "TextureTileSet";
}
namespace openspace {
TextureTileSet::TextureTileSet()
{
{
_testTexture = std::move(ghoul::io::TextureReader::ref().loadTexture(absPath("textures/earth_bluemarble.jpg")));
if (_testTexture) {
LDEBUG("Loaded texture from '" << "textures/earth_bluemarble.jpg" << "'");
_testTexture->uploadTexture();
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
// TODO: AnisotropicMipMap crashes on ATI cards ---abock
//_testTexture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
_testTexture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
}
}
TextureTileSet::~TextureTileSet()
@@ -38,31 +58,31 @@ namespace openspace {
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.toLonLatVec2() / pow(2, level);
glm::ivec2 tileIndex = -(patch.northWestCorner().toLonLatVec2() + offsetLevel0.toLonLatVec2()) / TileSize;
_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)
std::shared_ptr<Texture> TextureTileSet::getTile(LatLonPatch patch)
{
return getTile(getTileIndex(patch));
}
TextureTile TextureTileSet::getTile(glm::ivec3 tileIndex)
std::shared_ptr<Texture> TextureTileSet::getTile(glm::ivec3 tileIndex)
{
return TextureTile();
return _testTexture;
}
LatLonPatch TextureTileSet::getTilePositionAndScale(glm::ivec3 tileIndex)
{
LatLon tileSize = LatLon(
sizeLevel0.lat / pow(2, tileIndex.z),
sizeLevel0.lon / pow(2, tileIndex.z));
_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);
_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),

View File

@@ -26,12 +26,15 @@
#define __TEXTURETILESET_H__
#include <ghoul/logging/logmanager.h>
#include <ghoul/opengl/texture.h>
#include <modules/globebrowsing/datastructures/latlon.h>
#include <modules/globebrowsing/rendering/texturetile.h>
namespace openspace {
using namespace ghoul::opengl;
class TextureTileSet
{
public:
@@ -41,14 +44,16 @@ namespace openspace {
/// 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.
/// The tile is at least as big as the patch.
glm::ivec3 getTileIndex(LatLonPatch patch);
TextureTile getTile(LatLonPatch patch);
TextureTile getTile(glm::ivec3 tileIndex);
std::shared_ptr<Texture> getTile(LatLonPatch patch);
std::shared_ptr<Texture> getTile(glm::ivec3 tileIndex);
LatLonPatch getTilePositionAndScale(glm::ivec3 tileIndex);
private:
LatLon sizeLevel0;
LatLon offsetLevel0;
LatLon _sizeLevel0;
LatLon _offsetLevel0;
std::shared_ptr<Texture> _testTexture;
};
} // namespace openspace

View File

@@ -35,6 +35,8 @@ uniform float time;
uniform sampler2D texture1;
uniform sampler2D nightTex;
uniform sampler2D textureSampler;
in vec4 vs_position;
in vec2 vs_uv;
@@ -45,7 +47,7 @@ in vec2 vs_uv;
Fragment getFragment() {
Fragment frag;
frag.color = vec4(fract(vs_uv * 1), 0.4,1);
frag.color = texture2D(textureSampler, vs_uv);// vec4(fract(vs_uv * 1), 0.4,1);
frag.depth = pscDepth(vs_position);
return frag;