From ae838b397b6e5ca85d30fe1a8b9ccbb74864a7a6 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 8 Jul 2016 16:23:13 -0700 Subject: [core] Move translatedMatrix to RenderTile --- src/mbgl/renderer/painter.cpp | 26 -------------------------- src/mbgl/renderer/painter.hpp | 5 ----- src/mbgl/renderer/painter_circle.cpp | 7 +++---- src/mbgl/renderer/painter_fill.cpp | 5 +++-- src/mbgl/renderer/painter_line.cpp | 5 +++-- src/mbgl/renderer/painter_symbol.cpp | 9 +++++---- src/mbgl/renderer/render_tile.cpp | 29 +++++++++++++++++++++++++++++ src/mbgl/renderer/render_tile.hpp | 8 ++++++++ 8 files changed, 51 insertions(+), 43 deletions(-) (limited to 'src/mbgl') diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index b39cee97e2..c0c2da9c4d 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -274,32 +274,6 @@ void Painter::renderPass(PaintParameters& parameters, } } -mat4 Painter::translatedMatrix(const mat4& matrix, - const std::array& translation, - const UnwrappedTileID& id, - TranslateAnchorType anchor) { - if (translation[0] == 0 && translation[1] == 0) { - return matrix; - } else { - mat4 vtxMatrix; - if (anchor == TranslateAnchorType::Viewport) { - const double sin_a = std::sin(-state.getAngle()); - const double cos_a = std::cos(-state.getAngle()); - matrix::translate(vtxMatrix, matrix, - id.pixelsToTileUnits(translation[0] * cos_a - translation[1] * sin_a, state.getZoom()), - id.pixelsToTileUnits(translation[0] * sin_a + translation[1] * cos_a, state.getZoom()), - 0); - } else { - matrix::translate(vtxMatrix, matrix, - id.pixelsToTileUnits(translation[0], state.getZoom()), - id.pixelsToTileUnits(translation[1], state.getZoom()), - 0); - } - - return vtxMatrix; - } -} - void Painter::setDepthSublayer(int n) { float nearDepth = ((1 + currentLayer) * numSublayers + n) * depthEpsilon; float farDepth = nearDepth + depthRangeSize; diff --git a/src/mbgl/renderer/painter.hpp b/src/mbgl/renderer/painter.hpp index 0133c43072..700ddf2deb 100644 --- a/src/mbgl/renderer/painter.hpp +++ b/src/mbgl/renderer/painter.hpp @@ -105,11 +105,6 @@ public: bool needsAnimation() const; private: - mat4 translatedMatrix(const mat4& matrix, - const std::array& translation, - const UnwrappedTileID& id, - style::TranslateAnchorType anchor); - std::vector determineRenderOrder(const style::Style&); template diff --git a/src/mbgl/renderer/painter_circle.cpp b/src/mbgl/renderer/painter_circle.cpp index 9ef531d206..f91370ff22 100644 --- a/src/mbgl/renderer/painter_circle.cpp +++ b/src/mbgl/renderer/painter_circle.cpp @@ -26,14 +26,13 @@ void Painter::renderCircle(PaintParameters& parameters, setDepthSublayer(0); const CirclePaintProperties& properties = layer.impl->paint; - mat4 vtxMatrix = translatedMatrix(tile.matrix, properties.circleTranslate, tile.id, - properties.circleTranslateAnchor); - auto& circleShader = parameters.shaders.circle; config.program = circleShader.getID(); - circleShader.u_matrix = vtxMatrix; + circleShader.u_matrix = tile.translatedMatrix(properties.circleTranslate, + properties.circleTranslateAnchor, + state); if (properties.circlePitchScale == CirclePitchScaleType::Map) { circleShader.u_extrude_scale = {{ diff --git a/src/mbgl/renderer/painter_fill.cpp b/src/mbgl/renderer/painter_fill.cpp index 99a183b386..3c0eb515a7 100644 --- a/src/mbgl/renderer/painter_fill.cpp +++ b/src/mbgl/renderer/painter_fill.cpp @@ -17,8 +17,9 @@ void Painter::renderFill(PaintParameters& parameters, const FillLayer& layer, const RenderTile& tile) { const FillPaintProperties& properties = layer.impl->paint; - mat4 vertexMatrix = - translatedMatrix(tile.matrix, properties.fillTranslate, tile.id, properties.fillTranslateAnchor); + mat4 vertexMatrix = tile.translatedMatrix(properties.fillTranslate, + properties.fillTranslateAnchor, + state); Color fillColor = properties.fillColor; float opacity = properties.fillOpacity; diff --git a/src/mbgl/renderer/painter_line.cpp b/src/mbgl/renderer/painter_line.cpp index 2137eabc03..ed1975f955 100644 --- a/src/mbgl/renderer/painter_line.cpp +++ b/src/mbgl/renderer/painter_line.cpp @@ -50,8 +50,9 @@ void Painter::renderLine(PaintParameters& parameters, float x = state.getHeight() / 2.0f * std::tan(state.getPitch()); float extra = (topedgelength + x) / topedgelength - 1.0f; - mat4 vtxMatrix = - translatedMatrix(tile.matrix, properties.lineTranslate, tile.id, properties.lineTranslateAnchor); + mat4 vtxMatrix = tile.translatedMatrix(properties.lineTranslate, + properties.lineTranslateAnchor, + state); setDepthSublayer(0); diff --git a/src/mbgl/renderer/painter_symbol.cpp b/src/mbgl/renderer/painter_symbol.cpp index 4c2847401f..8599329842 100644 --- a/src/mbgl/renderer/painter_symbol.cpp +++ b/src/mbgl/renderer/painter_symbol.cpp @@ -15,7 +15,7 @@ namespace mbgl { using namespace style; -void Painter::renderSDF(SymbolBucket &bucket, +void Painter::renderSDF(SymbolBucket& bucket, const RenderTile& tile, float sdfFontSize, std::array texsize, @@ -37,7 +37,7 @@ void Painter::renderSDF(SymbolBucket &bucket, TranslateAnchorType translateAnchor, float paintSize) { - mat4 vtxMatrix = translatedMatrix(tile.matrix, translate, tile.id, translateAnchor); + mat4 vtxMatrix = tile.translatedMatrix(translate, translateAnchor, state); // If layerStyle.size > bucket.info.fontSize then labels may collide float fontSize = paintSize; @@ -185,8 +185,9 @@ void Painter::renderSymbol(PaintParameters& parameters, paint.iconTranslateAnchor, layer.impl->iconSize); } else { - mat4 vtxMatrix = - translatedMatrix(tile.matrix, paint.iconTranslate, tile.id, paint.iconTranslateAnchor); + mat4 vtxMatrix = tile.translatedMatrix(paint.iconTranslate, + paint.iconTranslateAnchor, + state); std::array extrudeScale; diff --git a/src/mbgl/renderer/render_tile.cpp b/src/mbgl/renderer/render_tile.cpp index 513515ddf0..5c7c491be0 100644 --- a/src/mbgl/renderer/render_tile.cpp +++ b/src/mbgl/renderer/render_tile.cpp @@ -1,5 +1,34 @@ #include +#include namespace mbgl { +using namespace style; + +mat4 RenderTile::translatedMatrix(const std::array& translation, + TranslateAnchorType anchor, + const TransformState& state) const { + if (translation[0] == 0 && translation[1] == 0) { + return matrix; + } + + mat4 vtxMatrix; + + if (anchor == TranslateAnchorType::Viewport) { + const double sin_a = std::sin(-state.getAngle()); + const double cos_a = std::cos(-state.getAngle()); + matrix::translate(vtxMatrix, matrix, + id.pixelsToTileUnits(translation[0] * cos_a - translation[1] * sin_a, state.getZoom()), + id.pixelsToTileUnits(translation[0] * sin_a + translation[1] * cos_a, state.getZoom()), + 0); + } else { + matrix::translate(vtxMatrix, matrix, + id.pixelsToTileUnits(translation[0], state.getZoom()), + id.pixelsToTileUnits(translation[1], state.getZoom()), + 0); + } + + return vtxMatrix; +} + } // namespace mbgl diff --git a/src/mbgl/renderer/render_tile.hpp b/src/mbgl/renderer/render_tile.hpp index 55a605280e..82b60a66c7 100644 --- a/src/mbgl/renderer/render_tile.hpp +++ b/src/mbgl/renderer/render_tile.hpp @@ -4,10 +4,14 @@ #include #include #include +#include + +#include namespace mbgl { class Tile; +class TransformState; class RenderTile { public: @@ -21,6 +25,10 @@ public: Tile& tile; ClipID clip; mat4 matrix; + + mat4 translatedMatrix(const std::array& translate, + style::TranslateAnchorType anchor, + const TransformState&) const; }; } // namespace mbgl -- cgit v1.2.1