mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-11 06:00:55 -06:00
Resolved merge conflicts
This commit is contained in:
@@ -57,6 +57,7 @@ namespace openspace {
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
PatchRenderer::PatchRenderer(shared_ptr<Geometry> geometry)
|
||||
: _geometry(geometry)
|
||||
, _tileSet(LatLon(M_PI, M_PI * 2), LatLon(M_PI / 2, - M_PI), 0)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -92,7 +93,7 @@ namespace openspace {
|
||||
{
|
||||
|
||||
// Get the textures that should be used for rendering
|
||||
TileIndex ti = tileSet.getTileIndex(patch);
|
||||
TileIndex ti = _tileSet.getTileIndex(patch);
|
||||
|
||||
renderPatch(patch, data, radius, ti);
|
||||
}
|
||||
@@ -103,8 +104,7 @@ namespace openspace {
|
||||
|
||||
using namespace glm;
|
||||
|
||||
LatLonPatch tilePatch = tileSet.getTilePositionAndScale(tileIndex);
|
||||
std::shared_ptr<ghoul::opengl::Texture> tile00 = tileSet.getTile(tileIndex);
|
||||
|
||||
|
||||
// TODO : Model transform should be fetched as a matrix directly.
|
||||
mat4 modelTransform = translate(mat4(1), data.position.vec3());
|
||||
@@ -116,12 +116,19 @@ namespace openspace {
|
||||
// activate shader
|
||||
_programObject->activate();
|
||||
|
||||
// Get the textures that should be used for rendering
|
||||
LatLonPatch tilePatch = _tileSet.getTilePositionAndScale(tileIndex);
|
||||
std::shared_ptr<ghoul::opengl::Texture> tile00 = _tileSet.getTile(tileIndex);
|
||||
glm::mat3 uvTransform = _tileSet.getUvTransformationPatchToTile(patch, tileIndex);
|
||||
|
||||
// Bind and use the texture
|
||||
ghoul::opengl::TextureUnit texUnit;
|
||||
texUnit.activate();
|
||||
tile00->bind();
|
||||
_programObject->setUniform("textureSampler", texUnit);
|
||||
|
||||
_programObject->setUniform("uvTransformPatchToTile", uvTransform);
|
||||
|
||||
LatLon swCorner = patch.southWestCorner();
|
||||
_programObject->setUniform("modelViewProjectionTransform", modelViewProjectionTransform);
|
||||
_programObject->setUniform("minLatLon", vec2(swCorner.toLonLatVec2()));
|
||||
@@ -181,9 +188,10 @@ namespace openspace {
|
||||
ivec2 intSnapCoord = ivec2(
|
||||
patch.center().lat / (M_PI * 2) * segmentsPerPatch * patchesToCoverGlobe.y,
|
||||
patch.center().lon / (M_PI) * segmentsPerPatch * patchesToCoverGlobe.x);
|
||||
LatLon swCorner = LatLon(
|
||||
stepSize.lat * intSnapCoord.x - halfSize.lat,
|
||||
stepSize.lon * intSnapCoord.y - halfSize.lon);
|
||||
LatLon newPatchCenter = LatLon(
|
||||
stepSize.lat * intSnapCoord.x,
|
||||
stepSize.lon * intSnapCoord.y);
|
||||
LatLonPatch newPatch(newPatchCenter, patch.halfSize());
|
||||
|
||||
ivec2 contraction = ivec2(intSnapCoord.y % 2, intSnapCoord.x % 2);
|
||||
|
||||
@@ -193,18 +201,20 @@ namespace openspace {
|
||||
|
||||
|
||||
// Get the textures that should be used for rendering
|
||||
TileIndex tileIndex = tileSet.getTileIndex(patch);
|
||||
LatLonPatch tilePatch = tileSet.getTilePositionAndScale(tileIndex);
|
||||
std::shared_ptr<ghoul::opengl::Texture> tile00 = tileSet.getTile(tileIndex);
|
||||
TileIndex tileIndex = _tileSet.getTileIndex(patch);
|
||||
LatLonPatch tilePatch = _tileSet.getTilePositionAndScale(tileIndex);
|
||||
std::shared_ptr<ghoul::opengl::Texture> tile00 = _tileSet.getTile(tileIndex);
|
||||
glm::mat3 uvTransform = _tileSet.getUvTransformationPatchToTile(newPatch, tileIndex);
|
||||
|
||||
// Bind and use the texture
|
||||
ghoul::opengl::TextureUnit texUnit;
|
||||
texUnit.activate();
|
||||
tile00->bind();
|
||||
_programObject->setUniform("textureSampler", texUnit);
|
||||
_programObject->setUniform("uvTransformPatchToTile", mat3(uvTransform));
|
||||
|
||||
_programObject->setUniform("modelViewProjectionTransform", data.camera.projectionMatrix() * viewTransform * modelTransform);
|
||||
_programObject->setUniform("minLatLon", vec2(swCorner.toLonLatVec2()));
|
||||
_programObject->setUniform("minLatLon", vec2(newPatch.southWestCorner().toLonLatVec2()));
|
||||
_programObject->setUniform("lonLatScalingFactor", 2.0f * vec2(halfSize.toLonLatVec2()));
|
||||
_programObject->setUniform("globeRadius", float(radius));
|
||||
_programObject->setUniform("contraction", contraction);
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace openspace {
|
||||
unique_ptr<ProgramObject> _programObject;
|
||||
shared_ptr<Geometry> _geometry;
|
||||
|
||||
TextureTileSet tileSet;
|
||||
TextureTileSet _tileSet;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
|
||||
#include <modules/globebrowsing/rendering/texturetileset.h>
|
||||
|
||||
#include <openspace/engine/downloadmanager.h>
|
||||
|
||||
#include <ghoul/opengl/texturemanager.h>
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
@@ -35,7 +33,6 @@
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
|
||||
|
||||
@@ -46,8 +43,13 @@ namespace {
|
||||
|
||||
namespace openspace {
|
||||
|
||||
TextureTileSet::TextureTileSet()
|
||||
TextureTileSet::TextureTileSet(LatLon sizeLevel0, LatLon offsetLevel0, int depth)
|
||||
: _sizeLevel0(sizeLevel0)
|
||||
, _offsetLevel0(offsetLevel0)
|
||||
, _depth(depth)
|
||||
{
|
||||
|
||||
// Set e texture to test
|
||||
_testTexture = std::move(ghoul::io::TextureReader::ref().loadTexture(absPath("textures/earth_bluemarble.jpg")));
|
||||
if (_testTexture) {
|
||||
LDEBUG("Loaded texture from '" << "textures/earth_bluemarble.jpg" << "'");
|
||||
@@ -58,6 +60,16 @@ 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();
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
@@ -67,10 +79,16 @@ namespace openspace {
|
||||
|
||||
TileIndex TextureTileSet::getTileIndex(LatLonPatch patch) {
|
||||
int level = log2(static_cast<int>(glm::max(
|
||||
_sizeLevel0.lat / patch.size().lat,
|
||||
_sizeLevel0.lon / patch.size().lon)));
|
||||
Vec2 TileSize = _sizeLevel0.toLonLatVec2() / pow(2, level);
|
||||
glm::ivec2 tileIndexXY = -(patch.northWestCorner().toLonLatVec2() + _offsetLevel0.toLonLatVec2()) / TileSize;
|
||||
_sizeLevel0.lat / (patch.size().lat),
|
||||
_sizeLevel0.lon / (patch.size().lon))));
|
||||
level = glm::min(level, _depth);
|
||||
Vec2 tileSize = _sizeLevel0.toLonLatVec2() / pow(2, level);
|
||||
Vec2 nw = patch.northWestCorner().toLonLatVec2();
|
||||
Vec2 offset = _offsetLevel0.toLonLatVec2();
|
||||
glm::ivec2 tileIndexXY = (nw - offset) / tileSize;
|
||||
|
||||
// Flip y since indices increase from top to bottom
|
||||
tileIndexXY.y *= -1;
|
||||
|
||||
TileIndex tileIndex = { tileIndexXY.x, tileIndexXY.y, level };
|
||||
return tileIndex;
|
||||
@@ -93,8 +111,35 @@ namespace openspace {
|
||||
_offsetLevel0.lon + tileIndex.x * tileSize.lon);
|
||||
|
||||
return LatLonPatch(
|
||||
LatLon(northWest.lat + tileSize.lat / 2, northWest.lon + tileSize.lon / 2),
|
||||
LatLon(northWest.lat - tileSize.lat / 2, northWest.lon + tileSize.lon / 2),
|
||||
LatLon(tileSize.lat / 2, tileSize.lon / 2));
|
||||
}
|
||||
|
||||
glm::mat3 TextureTileSet::getUvTransformationPatchToTile(
|
||||
LatLonPatch patch,
|
||||
const TileIndex& tileIndex)
|
||||
{
|
||||
LatLonPatch tile = getTilePositionAndScale(tileIndex);
|
||||
Vec2 posDiff =
|
||||
patch.southWestCorner().toLonLatVec2() -
|
||||
tile.southWestCorner().toLonLatVec2();
|
||||
|
||||
glm::mat3 invTileScale = glm::mat3(
|
||||
{1 / (tile.halfSize().lon * 2), 0, 0,
|
||||
0, 1 / (tile.halfSize().lat * 2), 0,
|
||||
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,
|
||||
0, (patch.halfSize().lat * 2), 0,
|
||||
0, 0, 1 });
|
||||
|
||||
return invTileScale * globalTranslation * patchScale;
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace openspace {
|
||||
class TextureTileSet
|
||||
{
|
||||
public:
|
||||
TextureTileSet();
|
||||
TextureTileSet(LatLon sizeLevel0, LatLon offsetLevel0, int depth);
|
||||
~TextureTileSet();
|
||||
|
||||
/// Returns the index of the tile at an appropriate level.
|
||||
@@ -56,12 +56,14 @@ namespace openspace {
|
||||
/// The tile is at least as big as the patch.
|
||||
TileIndex getTileIndex(LatLonPatch patch);
|
||||
std::shared_ptr<Texture> getTile(LatLonPatch patch);
|
||||
|
||||
std::shared_ptr<Texture> getTile(const TileIndex& tileIndex);
|
||||
LatLonPatch getTilePositionAndScale(const TileIndex& tileIndex);
|
||||
|
||||
glm::mat3 getUvTransformationPatchToTile(LatLonPatch patch, const TileIndex& tileIndex);
|
||||
private:
|
||||
LatLon _sizeLevel0;
|
||||
LatLon _offsetLevel0;
|
||||
int _depth;
|
||||
|
||||
std::shared_ptr<Texture> _testTexture;
|
||||
|
||||
|
||||
@@ -21,20 +21,16 @@
|
||||
* 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 <modules/globebrowsing/rendering/twmstileprovider.h>
|
||||
|
||||
#include <openspace/engine/downloadmanager.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>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
|
||||
@@ -118,3 +114,4 @@ namespace openspace {
|
||||
|
||||
|
||||
} // namespace openspace
|
||||
*/
|
||||
@@ -28,9 +28,6 @@
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
|
||||
#include <modules/globebrowsing/datastructures/latlon.h>
|
||||
|
||||
#include <modules/globebrowsing/rendering/texturetile.h>
|
||||
|
||||
|
||||
|
||||
@@ -48,29 +45,8 @@ namespace openspace {
|
||||
return x ^ (y << 16) ^ (level << 21);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
bool operator==(const openspace::TileIndex& a, const openspace::TileIndex& b) {
|
||||
return a.x == b.x && a.y == b.y && a.level == b.level;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& o, const openspace::TileIndex& key) {
|
||||
return o << key.x << ", " << key.y << " at level " << key.level;
|
||||
}
|
||||
|
||||
|
||||
// custom specialization of std::hash can be injected in namespace std
|
||||
namespace std {
|
||||
template<> struct hash<openspace::TileIndex> {
|
||||
unsigned long operator()(openspace::TileIndex const& ti) const {
|
||||
return ti.x ^ (ti.y << 16) ^ (ti.level << 21);
|
||||
}
|
||||
};
|
||||
}
|
||||
*/
|
||||
|
||||
#include <modules/globebrowsing/datastructures/lrucache.h>
|
||||
|
||||
@@ -80,7 +56,7 @@ namespace std {
|
||||
// TWMS TILE PROVIDER //
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/*
|
||||
namespace openspace {
|
||||
using namespace ghoul::opengl;
|
||||
|
||||
@@ -100,5 +76,5 @@ namespace openspace {
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
*/
|
||||
#endif // __TWMS_TILE_PROVIDER_H__
|
||||
@@ -36,6 +36,7 @@ uniform sampler2D texture1;
|
||||
uniform sampler2D nightTex;
|
||||
|
||||
uniform sampler2D textureSampler;
|
||||
uniform mat3 uvTransformPatchToTile;
|
||||
|
||||
in vec4 vs_position;
|
||||
in vec2 vs_uv;
|
||||
@@ -47,7 +48,8 @@ in vec2 vs_uv;
|
||||
Fragment getFragment() {
|
||||
Fragment frag;
|
||||
|
||||
frag.color = texture2D(textureSampler, vs_uv);// vec4(fract(vs_uv * 1), 0.4,1);
|
||||
frag.color = texture2D(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.depth = pscDepth(vs_position);
|
||||
|
||||
return frag;
|
||||
|
||||
Reference in New Issue
Block a user