From c200053951bc3e2b152d38fbf2f2c5e63ed5dddc Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 1 Apr 2015 16:26:33 -0700 Subject: [PATCH] don't add upside-down glyphs to buffers --- src/mbgl/renderer/symbol_bucket.cpp | 14 ++++++++------ src/mbgl/renderer/symbol_bucket.hpp | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/mbgl/renderer/symbol_bucket.cpp b/src/mbgl/renderer/symbol_bucket.cpp index 15cb5b1b7..bfce2475b 100644 --- a/src/mbgl/renderer/symbol_bucket.cpp +++ b/src/mbgl/renderer/symbol_bucket.cpp @@ -302,14 +302,12 @@ void SymbolBucket::placeFeatures() { auto &layout = *styleLayout; - /* const bool textAlongLine = layout.text.rotation_alignment == RotationAlignmentType::Map && layout.placement == PlacementType::Line; const bool iconAlongLine = layout.icon.rotation_alignment == RotationAlignmentType::Map && layout.placement == PlacementType::Line; - */ for (SymbolInstance &symbolInstance : symbolInstances) { @@ -327,7 +325,6 @@ void SymbolBucket::placeFeatures() { float iconScale = hasIcon && !layout.icon.allow_overlap ? collision.placeFeature(symbolInstance.iconCollisionFeature) : collision.minScale; - //if (glyphScale) fprintf(stderr, "glyphScale %f\n", glyphScale); // Combine the scales for icons and text. @@ -347,7 +344,7 @@ void SymbolBucket::placeFeatures() { collision.insertFeature(symbolInstance.textCollisionFeature, glyphScale); } if (glyphScale < collision.maxScale) { - addSymbols(text, symbolInstance.glyphQuads, glyphScale); + addSymbols(text, symbolInstance.glyphQuads, glyphScale, layout.text.keep_upright, textAlongLine); } } @@ -356,7 +353,7 @@ void SymbolBucket::placeFeatures() { collision.insertFeature(symbolInstance.iconCollisionFeature, iconScale); } if (iconScale < collision.maxScale) { - addSymbols(icon, symbolInstance.iconQuads, iconScale); + addSymbols(icon, symbolInstance.iconQuads, iconScale, layout.icon.keep_upright, iconAlongLine); } } } @@ -365,7 +362,7 @@ void SymbolBucket::placeFeatures() { } template -void SymbolBucket::addSymbols(Buffer &buffer, const PlacedGlyphs &symbols, float scale) { +void SymbolBucket::addSymbols(Buffer &buffer, const PlacedGlyphs &symbols, float scale, const bool keepUpright, const bool alongLine) { const float zoom = collision.zoom; const float placementZoom = std::log(scale) / std::log(2) + zoom; @@ -382,6 +379,11 @@ void SymbolBucket::addSymbols(Buffer &buffer, const PlacedGlyphs &symbols, float float maxZoom = util::min(static_cast(zoom + log(symbol.maxScale) / log(2)), 25.0f); const auto &glyphAnchor = symbol.anchor; + // drop upside down versions of glyphs + const float a = std::fmod(symbol.angle + collision.angle + M_PI, M_PI * 2); + if (keepUpright && alongLine && (a <= M_PI / 2 || a > M_PI * 3 / 2)) continue; + + if (maxZoom <= minZoom) continue; diff --git a/src/mbgl/renderer/symbol_bucket.hpp b/src/mbgl/renderer/symbol_bucket.hpp index 1b730ced8..f49afba36 100644 --- a/src/mbgl/renderer/symbol_bucket.hpp +++ b/src/mbgl/renderer/symbol_bucket.hpp @@ -102,7 +102,7 @@ private: // Adds placed items to the buffer. template - void addSymbols(Buffer &buffer, const PlacedGlyphs &symbols, float scale); + void addSymbols(Buffer &buffer, const PlacedGlyphs &symbols, float scale, const bool keepUpright, const bool alongLine); public: const std::unique_ptr styleLayout;