From 3d960c8136541f1f6d71409e23b8f56eee9dd1d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Tue, 6 Sep 2016 14:38:49 +0200 Subject: [PATCH] [core] change bool round to LinePatternCap --- src/mbgl/geometry/line_atlas.cpp | 14 ++++++++------ src/mbgl/geometry/line_atlas.hpp | 9 +++++++-- src/mbgl/renderer/painter_line.cpp | 6 ++++-- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/mbgl/geometry/line_atlas.cpp b/src/mbgl/geometry/line_atlas.cpp index f08ea1e5f..bc81c38f5 100644 --- a/src/mbgl/geometry/line_atlas.cpp +++ b/src/mbgl/geometry/line_atlas.cpp @@ -21,8 +21,10 @@ LineAtlas::LineAtlas(GLsizei w, GLsizei h) LineAtlas::~LineAtlas() = default; -LinePatternPos LineAtlas::getDashPosition(const std::vector& dasharray, bool round) { - size_t key = round ? std::numeric_limits::min() : std::numeric_limits::max(); +LinePatternPos LineAtlas::getDashPosition(const std::vector& dasharray, + LinePatternCap patternCap) { + size_t key = patternCap == LinePatternCap::Round ? std::numeric_limits::min() + : std::numeric_limits::max(); for (const float part : dasharray) { boost::hash_combine(key, part); } @@ -30,7 +32,7 @@ LinePatternPos LineAtlas::getDashPosition(const std::vector& dasharray, b // Note: We're not handling hash collisions here. const auto it = positions.find(key); if (it == positions.end()) { - auto inserted = positions.emplace(key, addDash(dasharray, round)); + auto inserted = positions.emplace(key, addDash(dasharray, patternCap)); assert(inserted.second); return inserted.first->second; } else { @@ -38,8 +40,8 @@ LinePatternPos LineAtlas::getDashPosition(const std::vector& dasharray, b } } -LinePatternPos LineAtlas::addDash(const std::vector& dasharray, bool round) { - int n = round ? 7 : 0; +LinePatternPos LineAtlas::addDash(const std::vector& dasharray, LinePatternCap patternCap) { + int n = patternCap == LinePatternCap::Round ? 7 : 0; int dashheight = 2 * n + 1; const uint8_t offset = 128; @@ -90,7 +92,7 @@ LinePatternPos LineAtlas::addDash(const std::vector& dasharray, bool roun bool inside = (partIndex % 2) == 1; int signedDistance; - if (round) { + if (patternCap == LinePatternCap::Round) { float distMiddle = n ? (float)y / n * (halfWidth + 1) : 0; if (inside) { float distEdge = halfWidth - fabs(distMiddle); diff --git a/src/mbgl/geometry/line_atlas.hpp b/src/mbgl/geometry/line_atlas.hpp index 1e6c0ac84..a2bda7186 100644 --- a/src/mbgl/geometry/line_atlas.hpp +++ b/src/mbgl/geometry/line_atlas.hpp @@ -19,6 +19,11 @@ typedef struct { float y; } LinePatternPos; +enum class LinePatternCap : bool { + Square = false, + Round = true, +}; + class LineAtlas { public: LineAtlas(GLsizei width, GLsizei height); @@ -31,8 +36,8 @@ public: // the texture is only bound when the data is out of date (=dirty). void upload(gl::ObjectStore&, gl::Config&, uint32_t unit); - LinePatternPos getDashPosition(const std::vector&, bool); - LinePatternPos addDash(const std::vector& dasharray, bool round); + LinePatternPos getDashPosition(const std::vector&, LinePatternCap); + LinePatternPos addDash(const std::vector& dasharray, LinePatternCap); const GLsizei width; const GLsizei height; diff --git a/src/mbgl/renderer/painter_line.cpp b/src/mbgl/renderer/painter_line.cpp index 2702440d2..f6afaa7ec 100644 --- a/src/mbgl/renderer/painter_line.cpp +++ b/src/mbgl/renderer/painter_line.cpp @@ -72,8 +72,10 @@ void Painter::renderLine(PaintParameters& parameters, linesdfShader.u_color = color; linesdfShader.u_opacity = opacity; - LinePatternPos posA = lineAtlas->getDashPosition(properties.lineDasharray.value.from, layout.lineCap == LineCapType::Round); - LinePatternPos posB = lineAtlas->getDashPosition(properties.lineDasharray.value.to, layout.lineCap == LineCapType::Round); + const LinePatternCap cap = + layout.lineCap == LineCapType::Round ? LinePatternCap::Round : LinePatternCap::Square; + LinePatternPos posA = lineAtlas->getDashPosition(properties.lineDasharray.value.from, cap); + LinePatternPos posB = lineAtlas->getDashPosition(properties.lineDasharray.value.to, cap); const float widthA = posA.width * properties.lineDasharray.value.fromScale * layer.impl->dashLineWidth; const float widthB = posB.width * properties.lineDasharray.value.toScale * layer.impl->dashLineWidth;