diff --git a/include/llmr/renderer/painter.hpp b/include/llmr/renderer/painter.hpp index 323d5016d..73281a906 100644 --- a/include/llmr/renderer/painter.hpp +++ b/include/llmr/renderer/painter.hpp @@ -89,7 +89,7 @@ public: bool needsAnimation() const; private: void setupShaders(); - mat4 translatedMatrix(const std::array &translation, const Tile::ID &id, TranslateAnchor anchor = TranslateAnchor::Map); + const mat4 &translatedMatrix(const std::array &translation, const Tile::ID &id, TranslateAnchor anchor = TranslateAnchor::Map); void prepareTile(const Tile& tile); void useProgram(uint32_t program); @@ -98,6 +98,7 @@ private: public: mat4 matrix; + mat4 vtxMatrix; mat4 projMatrix; mat4 nativeMatrix; mat4 extrudeMatrix; diff --git a/src/renderer/painter.cpp b/src/renderer/painter.cpp index f214e4a59..833f7b6a4 100644 --- a/src/renderer/painter.cpp +++ b/src/renderer/painter.cpp @@ -171,28 +171,28 @@ void Painter::renderTileLayer(const Tile& tile, const LayerDescription &layer_de } } -mat4 Painter::translatedMatrix(const std::array &translation, const Tile::ID &id, TranslateAnchor anchor) { +const mat4 &Painter::translatedMatrix(const std::array &translation, const Tile::ID &id, TranslateAnchor anchor) { if (translation[0] == 0 && translation[1] == 0) { return matrix; } else { // TODO: Get rid of the 8 (scaling from 4096 to tile size) const double factor = ((double)(1 << id.z)) / map.getState().getScale() * (4096.0 / util::tileSize); - mat4 result; if (anchor == TranslateAnchor::Viewport) { const double sin_a = std::sin(-map.getState().getAngle()); const double cos_a = std::cos(-map.getState().getAngle()); - matrix::translate(result, matrix, + matrix::translate(vtxMatrix, matrix, factor * (translation[0] * cos_a - translation[1] * sin_a), factor * (translation[0] * sin_a + translation[1] * cos_a), 0); } else { - matrix::translate(result, matrix, + matrix::translate(vtxMatrix, matrix, factor * translation[0], factor * translation[1], 0); } - return result; + + return vtxMatrix; } } diff --git a/src/renderer/painter_fill.cpp b/src/renderer/painter_fill.cpp index 543df440d..6193e3068 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; } - const mat4 vtxMatrix = translatedMatrix(properties.translate, id, properties.translateAnchor); + const mat4 &vtxMatrix = translatedMatrix(properties.translate, id, properties.translateAnchor); // Because we're drawing top-to-bottom, and we update the stencil mask // below, we have to draw the outline first (!) diff --git a/src/renderer/painter_line.cpp b/src/renderer/painter_line.cpp index 8d60f4c81..8dc486201 100644 --- a/src/renderer/painter_line.cpp +++ b/src/renderer/painter_line.cpp @@ -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]; - const mat4 vtxMatrix = translatedMatrix(properties.translate, id, properties.translateAnchor); + const mat4 &vtxMatrix = translatedMatrix(properties.translate, id, properties.translateAnchor); glDepthRange(strata, 1.0f); diff --git a/src/renderer/painter_point.cpp b/src/renderer/painter_point.cpp index 64e2ae77f..84861367d 100644 --- a/src/renderer/painter_point.cpp +++ b/src/renderer/painter_point.cpp @@ -35,7 +35,7 @@ void Painter::renderPoint(PointBucket& bucket, const std::string& layer_name, co imagePos = sprite->getPosition(sized_image, false); } - const mat4 vtxMatrix = translatedMatrix(properties.translate, id, properties.translateAnchor); + const mat4 &vtxMatrix = translatedMatrix(properties.translate, id, properties.translateAnchor); if (!imagePos.size) { useProgram(dotShader->program); diff --git a/src/renderer/painter_text.cpp b/src/renderer/painter_text.cpp index d1abbb526..c083da964 100644 --- a/src/renderer/painter_text.cpp +++ b/src/renderer/painter_text.cpp @@ -31,7 +31,7 @@ void Painter::renderText(TextBucket& bucket, const std::string& layer_name, cons float fontSize = std::fmin(properties.size, bucket.geom_desc.font_size); matrix::scale(exMatrix, exMatrix, fontSize / 24.0f, fontSize / 24.0f, 1.0f); - const mat4 vtxMatrix = translatedMatrix(properties.translate, id, properties.translateAnchor); + const mat4 &vtxMatrix = translatedMatrix(properties.translate, id, properties.translateAnchor); useProgram(textShader->program); textShader->setMatrix(vtxMatrix);