From 05a330f347e16dc310e3dd3fbdb3b27007c18fb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Tue, 13 May 2014 16:48:23 +0200 Subject: [PATCH] make translate property zoom independent if you want a zoom-dependent translation, you can use a function refs #189 --- include/llmr/renderer/painter.hpp | 2 +- src/renderer/painter.cpp | 17 +++++++---------- src/renderer/painter_fill.cpp | 4 ++-- src/renderer/painter_line.cpp | 6 +++--- src/renderer/painter_point.cpp | 6 +++--- src/renderer/painter_text.cpp | 6 +++--- 6 files changed, 19 insertions(+), 22 deletions(-) diff --git a/include/llmr/renderer/painter.hpp b/include/llmr/renderer/painter.hpp index d236ead44..5dbc97143 100644 --- a/include/llmr/renderer/painter.hpp +++ b/include/llmr/renderer/painter.hpp @@ -88,7 +88,7 @@ public: bool needsAnimation() const; private: void setupShaders(); - void translateLayer(std::array translation, bool reverse = false); + void translateLayer(std::array translation, const Tile::ID &id, bool reverse = false); void prepareTile(const Tile& tile); void useProgram(uint32_t program); diff --git a/src/renderer/painter.cpp b/src/renderer/painter.cpp index 6adbc71c4..6d85af4be 100644 --- a/src/renderer/painter.cpp +++ b/src/renderer/painter.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -170,17 +171,13 @@ void Painter::renderTileLayer(const Tile& tile, const LayerDescription &layer_de } } -void Painter::translateLayer(std::array translation, bool reverse) { +void Painter::translateLayer(const std::array translation, const Tile::ID &id, bool reverse) { if (translation[0] || translation[1]) { - if (reverse) { - translation[0] *= -1; - translation[1] *= -1; - } - matrix::translate(matrix, - matrix, - translation[0] / map.getState().getPixelRatio(), - translation[1] / map.getState().getPixelRatio(), - 0); + const int direction = reverse ? -1 : 1; + // TODO: Get rid of the 8 (scaling from 4096 to tile size) + const double factor = direction * ((double)(1 << id.z)) / map.getState().getScale() / + map.getState().getPixelRatio() * (4096.0 / util::tileSize); + matrix::translate(matrix, matrix, translation[0] * factor, translation[1] * factor, 0); } } diff --git a/src/renderer/painter_fill.cpp b/src/renderer/painter_fill.cpp index 921947857..442f627a5 100644 --- a/src/renderer/painter_fill.cpp +++ b/src/renderer/painter_fill.cpp @@ -35,7 +35,7 @@ void Painter::renderFill(FillBucket& bucket, const std::string& layer_name, cons stroke_color = fill_color; } - translateLayer(properties.translate); + translateLayer(properties.translate, id); // Because we're drawing top-to-bottom, and we update the stencil mask // below, we have to draw the outline first (!) @@ -139,5 +139,5 @@ void Painter::renderFill(FillBucket& bucket, const std::string& layer_name, cons bucket.drawVertices(*outlineShader); } - translateLayer(properties.translate, true); + translateLayer(properties.translate, id, true); } diff --git a/src/renderer/painter_line.cpp b/src/renderer/painter_line.cpp index 1998e5584..ccd916c52 100644 --- a/src/renderer/painter_line.cpp +++ b/src/renderer/painter_line.cpp @@ -4,7 +4,7 @@ using namespace llmr; -void Painter::renderLine(LineBucket& bucket, const std::string& layer_name, const Tile::ID& /*id*/) { +void Painter::renderLine(LineBucket& bucket, const std::string& layer_name, const Tile::ID& id) { // Abort early. if (pass == Opaque) return; if (!bucket.hasData()) return; @@ -33,7 +33,7 @@ void Painter::renderLine(LineBucket& bucket, const std::string& layer_name, cons float dash_length = properties.dash_array[0]; float dash_gap = properties.dash_array[1]; - translateLayer(properties.translate); + translateLayer(properties.translate, id); glDepthRange(strata, 1.0f); @@ -88,5 +88,5 @@ void Painter::renderLine(LineBucket& bucket, const std::string& layer_name, cons bucket.drawLines(*lineShader); } - translateLayer(properties.translate, true); + translateLayer(properties.translate, id, true); } diff --git a/src/renderer/painter_point.cpp b/src/renderer/painter_point.cpp index d54c66be9..2bb2da672 100644 --- a/src/renderer/painter_point.cpp +++ b/src/renderer/painter_point.cpp @@ -5,7 +5,7 @@ using namespace llmr; -void Painter::renderPoint(PointBucket& bucket, const std::string& layer_name, const Tile::ID& /*id&*/) { +void Painter::renderPoint(PointBucket& bucket, const std::string& layer_name, const Tile::ID& id) { // Abort early. if (!bucket.hasData()) return; if (pass == Opaque) return; @@ -17,7 +17,7 @@ void Painter::renderPoint(PointBucket& bucket, const std::string& layer_name, co const PointProperties& properties = point_properties_it->second; if (!properties.enabled) return; - translateLayer(properties.translate); + translateLayer(properties.translate, id); Color color = properties.color; color[0] *= properties.opacity; @@ -76,5 +76,5 @@ void Painter::renderPoint(PointBucket& bucket, const std::string& layer_name, co bucket.drawPoints(*pointShader); } - translateLayer(properties.translate, true); + translateLayer(properties.translate, id, true); } diff --git a/src/renderer/painter_text.cpp b/src/renderer/painter_text.cpp index 092b74b09..7d2a2d2ae 100644 --- a/src/renderer/painter_text.cpp +++ b/src/renderer/painter_text.cpp @@ -4,7 +4,7 @@ using namespace llmr; -void Painter::renderText(TextBucket& bucket, const std::string& layer_name, const Tile::ID& /*id*/) { +void Painter::renderText(TextBucket& bucket, const std::string& layer_name, const Tile::ID& id) { // Abort early. if (pass == Opaque) return; if (!bucket.hasData()) return; @@ -16,7 +16,7 @@ void Painter::renderText(TextBucket& bucket, const std::string& layer_name, cons const TextProperties& properties = text_properties_it->second; if (!properties.enabled) return; - translateLayer(properties.translate); + translateLayer(properties.translate, id); mat4 exMatrix; matrix::copy(exMatrix, projMatrix); @@ -110,5 +110,5 @@ void Painter::renderText(TextBucket& bucket, const std::string& layer_name, cons glDepthRange(strata + strata_epsilon, 1.0f); bucket.drawGlyphs(*textShader); - translateLayer(properties.translate, true); + translateLayer(properties.translate, id, true); }