summaryrefslogtreecommitdiff
path: root/src/mbgl
diff options
context:
space:
mode:
authorAlexander Shalamov <alexander.shalamov@mapbox.com>2019-11-14 15:23:15 +0200
committerAlexander Shalamov <alexander.shalamov@mapbox.com>2019-12-02 17:11:49 +0200
commit2c49c4374cb9e3654c1d347b1071542918ce5fd2 (patch)
tree9791f6f960939e92a5c891160d86065cc0cf0184 /src/mbgl
parent2bb2a40b6d13d4fe44e8879003a3e53416033a34 (diff)
downloadqtlocation-mapboxgl-2c49c4374cb9e3654c1d347b1071542918ce5fd2.tar.gz
[core] Store 'sdf' flag in vertex attribute
Diffstat (limited to 'src/mbgl')
-rw-r--r--src/mbgl/layout/symbol_instance.cpp6
-rw-r--r--src/mbgl/layout/symbol_instance.hpp10
-rw-r--r--src/mbgl/layout/symbol_layout.cpp13
-rw-r--r--src/mbgl/programs/symbol_program.hpp36
-rw-r--r--src/mbgl/text/quads.cpp17
-rw-r--r--src/mbgl/text/quads.hpp7
6 files changed, 48 insertions, 41 deletions
diff --git a/src/mbgl/layout/symbol_instance.cpp b/src/mbgl/layout/symbol_instance.cpp
index d48a3af388..094f859830 100644
--- a/src/mbgl/layout/symbol_instance.cpp
+++ b/src/mbgl/layout/symbol_instance.cpp
@@ -26,13 +26,15 @@ SymbolInstanceSharedData::SymbolInstanceSharedData(GeometryCoordinates line_,
const style::SymbolPlacementType textPlacement,
const std::array<float, 2>& textOffset,
const ImageMap& imageMap,
+ SymbolContent iconType,
bool allowVerticalPlacement)
: line(std::move(line_)) {
// Create the quads used for rendering the icon and glyphs.
if (shapedIcon) {
- iconQuad = getIconQuad(*shapedIcon, getAnyShaping(shapedTextOrientations).writingMode);
+ iconQuad = getIconQuad(*shapedIcon, getAnyShaping(shapedTextOrientations).writingMode, iconType);
if (verticallyShapedIcon) {
- verticalIconQuad = getIconQuad(*verticallyShapedIcon, shapedTextOrientations.vertical.writingMode);
+ verticalIconQuad =
+ getIconQuad(*verticallyShapedIcon, shapedTextOrientations.vertical.writingMode, iconType);
}
}
diff --git a/src/mbgl/layout/symbol_instance.hpp b/src/mbgl/layout/symbol_instance.hpp
index bc2ff48d33..e20c05a0ab 100644
--- a/src/mbgl/layout/symbol_instance.hpp
+++ b/src/mbgl/layout/symbol_instance.hpp
@@ -21,6 +21,8 @@ struct ShapedTextOrientations {
bool singleLine = false;
};
+enum class SymbolContent : uint8_t { None = 0, Text = 1 << 0, IconRGBA = 1 << 1, IconSDF = 1 << 2 };
+
struct SymbolInstanceSharedData {
SymbolInstanceSharedData(GeometryCoordinates line,
const ShapedTextOrientations& shapedTextOrientations,
@@ -30,6 +32,7 @@ struct SymbolInstanceSharedData {
const style::SymbolPlacementType textPlacement,
const std::array<float, 2>& textOffset,
const ImageMap& imageMap,
+ SymbolContent iconType,
bool allowVerticalPlacement);
bool empty() const;
GeometryCoordinates line;
@@ -42,13 +45,6 @@ struct SymbolInstanceSharedData {
optional<SymbolQuad> verticalIconQuad;
};
-enum class SymbolContent : uint8_t {
- None = 0,
- Text = 1 << 0,
- IconRGBA = 1 << 1,
- IconSDF = 1 << 2
-};
-
class SymbolInstance {
public:
SymbolInstance(Anchor& anchor_,
diff --git a/src/mbgl/layout/symbol_layout.cpp b/src/mbgl/layout/symbol_layout.cpp
index 1207c1c668..c03ad8835f 100644
--- a/src/mbgl/layout/symbol_layout.cpp
+++ b/src/mbgl/layout/symbol_layout.cpp
@@ -597,6 +597,7 @@ void SymbolLayout::addFeature(const std::size_t layoutFeatureIndex,
textPlacement,
textOffset,
imageMap,
+ iconType,
allowVerticalPlacement);
};
@@ -864,10 +865,14 @@ size_t SymbolLayout::addSymbol(SymbolBucket::Buffer& buffer,
uint16_t index = segment.vertexLength;
// coordinates (2 triangles)
- buffer.vertices.emplace_back(SymbolSDFIconProgram::layoutVertex(labelAnchor.point, tl, symbol.glyphOffset.y, tex.x, tex.y, sizeData));
- buffer.vertices.emplace_back(SymbolSDFIconProgram::layoutVertex(labelAnchor.point, tr, symbol.glyphOffset.y, tex.x + tex.w, tex.y, sizeData));
- buffer.vertices.emplace_back(SymbolSDFIconProgram::layoutVertex(labelAnchor.point, bl, symbol.glyphOffset.y, tex.x, tex.y + tex.h, sizeData));
- buffer.vertices.emplace_back(SymbolSDFIconProgram::layoutVertex(labelAnchor.point, br, symbol.glyphOffset.y, tex.x + tex.w, tex.y + tex.h, sizeData));
+ buffer.vertices.emplace_back(SymbolSDFIconProgram::layoutVertex(
+ labelAnchor.point, tl, symbol.glyphOffset.y, tex.x, tex.y, sizeData, symbol.isSDF));
+ buffer.vertices.emplace_back(SymbolSDFIconProgram::layoutVertex(
+ labelAnchor.point, tr, symbol.glyphOffset.y, tex.x + tex.w, tex.y, sizeData, symbol.isSDF));
+ buffer.vertices.emplace_back(SymbolSDFIconProgram::layoutVertex(
+ labelAnchor.point, bl, symbol.glyphOffset.y, tex.x, tex.y + tex.h, sizeData, symbol.isSDF));
+ buffer.vertices.emplace_back(SymbolSDFIconProgram::layoutVertex(
+ labelAnchor.point, br, symbol.glyphOffset.y, tex.x + tex.w, tex.y + tex.h, sizeData, symbol.isSDF));
// Dynamic/Opacity vertices are initialized so that the vertex count always agrees with
// the layout vertex buffer, but they will always be updated before rendering happens
diff --git a/src/mbgl/programs/symbol_program.hpp b/src/mbgl/programs/symbol_program.hpp
index 80e6245a03..f614181a1e 100644
--- a/src/mbgl/programs/symbol_program.hpp
+++ b/src/mbgl/programs/symbol_program.hpp
@@ -14,12 +14,15 @@
#include <mbgl/style/layers/symbol_layer_impl.hpp>
#include <mbgl/renderer/layers/render_symbol_layer.hpp>
-
#include <cmath>
#include <array>
namespace mbgl {
+const uint16_t MAX_GLYPH_ICON_SIZE = 255;
+const uint16_t SIZE_PACK_FACTOR = 128;
+const uint16_t MAX_PACKED_SIZE = MAX_GLYPH_ICON_SIZE * SIZE_PACK_FACTOR;
+
namespace style {
class SymbolPropertyValues;
} // namespace style
@@ -197,26 +200,21 @@ public:
class SymbolProgramBase {
public:
static gfx::Vertex<SymbolLayoutAttributes> layoutVertex(Point<float> labelAnchor,
- Point<float> o,
- float glyphOffsetY,
- uint16_t tx,
- uint16_t ty,
- const Range<float>& sizeData) {
+ Point<float> o,
+ float glyphOffsetY,
+ uint16_t tx,
+ uint16_t ty,
+ const Range<float>& sizeData,
+ bool isSDF) {
+ const uint16_t aSizeMin = (std::min(MAX_PACKED_SIZE, static_cast<uint16_t>(sizeData.min * SIZE_PACK_FACTOR)) << 1) + uint16_t(isSDF);
+ const uint16_t aSizeMax = std::min(MAX_PACKED_SIZE, static_cast<uint16_t>(sizeData.max * SIZE_PACK_FACTOR));
return {
// combining pos and offset to reduce number of vertex attributes passed to shader (8 max for some devices)
- {{
- static_cast<int16_t>(labelAnchor.x),
- static_cast<int16_t>(labelAnchor.y),
- static_cast<int16_t>(::round(o.x * 32)), // use 1/32 pixels for placement
- static_cast<int16_t>(::round((o.y + glyphOffsetY) * 32))
- }},
- {{
- tx,
- ty,
- static_cast<uint16_t>(sizeData.min * 256),
- static_cast<uint16_t>(sizeData.max * 256)
- }}
- };
+ {{static_cast<int16_t>(labelAnchor.x),
+ static_cast<int16_t>(labelAnchor.y),
+ static_cast<int16_t>(::round(o.x * 32)), // use 1/32 pixels for placement
+ static_cast<int16_t>(::round((o.y + glyphOffsetY) * 32))}},
+ {{tx, ty, aSizeMin, aSizeMax}}};
}
static gfx::Vertex<SymbolDynamicLayoutAttributes> dynamicLayoutVertex(Point<float> anchorPoint, float labelAngle) {
diff --git a/src/mbgl/text/quads.cpp b/src/mbgl/text/quads.cpp
index ee17510c35..480bcd79a9 100644
--- a/src/mbgl/text/quads.cpp
+++ b/src/mbgl/text/quads.cpp
@@ -1,10 +1,11 @@
+#include <mbgl/geometry/anchor.hpp>
+#include <mbgl/layout/symbol_instance.hpp>
+#include <mbgl/style/layers/symbol_layer_properties.hpp>
#include <mbgl/text/quads.hpp>
#include <mbgl/text/shaping.hpp>
#include <mbgl/tile/geometry_tile_data.hpp>
-#include <mbgl/geometry/anchor.hpp>
-#include <mbgl/style/layers/symbol_layer_properties.hpp>
-#include <mbgl/util/math.hpp>
#include <mbgl/util/constants.hpp>
+#include <mbgl/util/math.hpp>
#include <mbgl/util/optional.hpp>
#include <cassert>
@@ -13,8 +14,7 @@ namespace mbgl {
using namespace style;
-SymbolQuad getIconQuad(const PositionedIcon& shapedIcon,
- WritingModeType writingMode) {
+SymbolQuad getIconQuad(const PositionedIcon& shapedIcon, WritingModeType writingMode, SymbolContent iconType) {
const ImagePosition& image = shapedIcon.image();
// If you have a 10px icon that isn't perfectly aligned to the pixel grid it will cover 11 actual
@@ -70,7 +70,7 @@ SymbolQuad getIconQuad(const PositionedIcon& shapedIcon,
static_cast<uint16_t>(image.textureRect.h + border * 2)
};
- return SymbolQuad { tl, tr, bl, br, textureRect, writingMode, { 0.0f, 0.0f } };
+ return SymbolQuad{tl, tr, bl, br, textureRect, writingMode, {0.0f, 0.0f}, iconType == SymbolContent::IconSDF};
}
SymbolQuads getGlyphQuads(const Shaping& shapedText,
@@ -96,6 +96,7 @@ SymbolQuads getGlyphQuads(const Shaping& shapedText,
const bool rotateVerticalGlyph = (alongLine || allowVerticalPlacement) && positionedGlyph.vertical;
const float halfAdvance = positionedGlyph.metrics.advance * positionedGlyph.scale / 2.0;
const Rect<uint16_t>& rect = positionedGlyph.rect;
+ bool isSDF = true;
// Align images and scaled glyphs in the middle of a vertical line.
if (allowVerticalPlacement && shapedText.verticalizable) {
@@ -111,6 +112,7 @@ SymbolQuads getGlyphQuads(const Shaping& shapedText,
}
pixelRatio = image->second->pixelRatio;
rectBuffer = ImagePosition::padding / pixelRatio;
+ isSDF = image->second->sdf;
}
const Point<float> glyphOffset =
@@ -179,7 +181,8 @@ SymbolQuads getGlyphQuads(const Shaping& shapedText,
br = util::matrixMultiply(matrix, br);
}
- quads.emplace_back(tl, tr, bl, br, rect, shapedText.writingMode, glyphOffset, positionedGlyph.sectionIndex);
+ quads.emplace_back(
+ tl, tr, bl, br, rect, shapedText.writingMode, glyphOffset, isSDF, positionedGlyph.sectionIndex);
}
}
diff --git a/src/mbgl/text/quads.hpp b/src/mbgl/text/quads.hpp
index f67266b1ec..29f798ba0d 100644
--- a/src/mbgl/text/quads.hpp
+++ b/src/mbgl/text/quads.hpp
@@ -12,6 +12,7 @@ namespace mbgl {
class Anchor;
class PositionedIcon;
+enum class SymbolContent : uint8_t;
class SymbolQuad {
public:
@@ -22,6 +23,7 @@ public:
Rect<uint16_t> tex_,
WritingModeType writingMode_,
Point<float> glyphOffset_,
+ bool isSDF_,
size_t sectionIndex_ = 0)
: tl(tl_),
tr(tr_),
@@ -30,6 +32,7 @@ public:
tex(tex_),
writingMode(writingMode_),
glyphOffset(glyphOffset_),
+ isSDF(isSDF_),
sectionIndex(sectionIndex_) {}
Point<float> tl;
@@ -39,13 +42,13 @@ public:
Rect<uint16_t> tex;
WritingModeType writingMode;
Point<float> glyphOffset;
+ bool isSDF;
size_t sectionIndex;
};
using SymbolQuads = std::vector<SymbolQuad>;
-SymbolQuad getIconQuad(const PositionedIcon& shapedIcon,
- WritingModeType writingMode);
+SymbolQuad getIconQuad(const PositionedIcon& shapedIcon, WritingModeType writingMode, SymbolContent iconType);
SymbolQuads getGlyphQuads(const Shaping& shapedText,
const std::array<float, 2> textOffset,