summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnsis Brammanis <brammanis@gmail.com>2017-06-29 12:10:46 -0400
committerAnsis Brammanis <brammanis@gmail.com>2017-06-29 12:10:46 -0400
commit62790098084a0176b79a667d9cb1c9329fc89fd9 (patch)
tree850bb082890f1a668c3e1b9be9ac33accfee89e1
parent95c4c692ec6fed1ed1f0ccf3090b72af17e57a6b (diff)
downloadqtlocation-mapboxgl-62790098084a0176b79a667d9cb1c9329fc89fd9.tar.gz
fix clipping and lineoffset
-rw-r--r--src/mbgl/layout/symbol_instance.cpp6
-rw-r--r--src/mbgl/layout/symbol_instance.hpp4
-rw-r--r--src/mbgl/layout/symbol_layout.cpp18
-rw-r--r--src/mbgl/layout/symbol_projection.cpp7
-rw-r--r--src/mbgl/programs/symbol_program.hpp3
-rw-r--r--src/mbgl/renderer/buckets/symbol_bucket.hpp7
-rw-r--r--src/mbgl/text/shaping.cpp14
7 files changed, 32 insertions, 27 deletions
diff --git a/src/mbgl/layout/symbol_instance.cpp b/src/mbgl/layout/symbol_instance.cpp
index 0dc6802883..02fb800df6 100644
--- a/src/mbgl/layout/symbol_instance.cpp
+++ b/src/mbgl/layout/symbol_instance.cpp
@@ -16,9 +16,11 @@ SymbolInstance::SymbolInstance(Anchor& anchor_,
const float textBoxScale,
const float textPadding,
const SymbolPlacementType textPlacement,
+ const std::array<float, 2> textOffset_,
const float iconBoxScale,
const float iconPadding,
const SymbolPlacementType iconPlacement,
+ const std::array<float, 2> iconOffset_,
const GlyphPositionMap& positions,
const IndexedSubfeature& indexedFeature,
const std::size_t featureIndex_) :
@@ -31,7 +33,9 @@ SymbolInstance::SymbolInstance(Anchor& anchor_,
// Create the collision features that will be used to check whether this symbol instance can be placed
textCollisionFeature(line_, anchor, shapedTextOrientations.second ?: shapedTextOrientations.first, textBoxScale, textPadding, textPlacement, indexedFeature),
iconCollisionFeature(line_, anchor, shapedIcon, iconBoxScale, iconPadding, iconPlacement, indexedFeature),
- featureIndex(featureIndex_) {
+ featureIndex(featureIndex_),
+ textOffset(textOffset_),
+ iconOffset(iconOffset_) {
// Create the quads used for rendering the icon and glyphs.
if (addToBuffers) {
diff --git a/src/mbgl/layout/symbol_instance.hpp b/src/mbgl/layout/symbol_instance.hpp
index 0eca512271..f1df416cd1 100644
--- a/src/mbgl/layout/symbol_instance.hpp
+++ b/src/mbgl/layout/symbol_instance.hpp
@@ -23,9 +23,11 @@ public:
const float textBoxScale,
const float textPadding,
style::SymbolPlacementType textPlacement,
+ const std::array<float, 2> textOffset,
const float iconBoxScale,
const float iconPadding,
style::SymbolPlacementType iconPlacement,
+ const std::array<float, 2> iconOffset,
const GlyphPositionMap&,
const IndexedSubfeature&,
const std::size_t featureIndex);
@@ -41,6 +43,8 @@ public:
CollisionFeature iconCollisionFeature;
WritingModeType writingModes;
std::size_t featureIndex;
+ std::array<float, 2> textOffset;
+ std::array<float, 2> iconOffset;
};
} // namespace mbgl
diff --git a/src/mbgl/layout/symbol_layout.cpp b/src/mbgl/layout/symbol_layout.cpp
index 51a030de57..593c102f98 100644
--- a/src/mbgl/layout/symbol_layout.cpp
+++ b/src/mbgl/layout/symbol_layout.cpp
@@ -305,6 +305,8 @@ void SymbolLayout::addFeature(const std::size_t index,
const float layoutTextSize = layout.evaluate<TextSize>(zoom + 1, feature);
const float layoutIconSize = layout.evaluate<IconSize>(zoom + 1, feature);
+ const std::array<float, 2> textOffset = layout.evaluate<TextOffset>(zoom, feature);
+ const std::array<float, 2> iconOffset = layout.evaluate<IconOffset>(zoom, feature);
// To reduce the number of labels that jump around when zooming we need
// to use a text-size value that is the same for all zoom levels.
@@ -354,8 +356,8 @@ void SymbolLayout::addFeature(const std::size_t index,
symbolInstances.emplace_back(anchor, line, shapedTextOrientations, shapedIcon,
layout.evaluate(zoom, feature), layoutTextSize,
addToBuffers, symbolInstances.size(),
- textBoxScale, textPadding, textPlacement,
- iconBoxScale, iconPadding, iconPlacement,
+ textBoxScale, textPadding, textPlacement, textOffset,
+ iconBoxScale, iconPadding, iconPlacement, iconOffset,
glyphPositionMap, indexedFeature, index);
};
@@ -502,7 +504,7 @@ std::unique_ptr<SymbolBucket> SymbolLayout::place(CollisionTile& collisionTile)
if (glyphScale < collisionTile.maxScale) {
const Range<float> sizeData = bucket->textSizeBinder->getVertexSizeData(feature);
PlacedSymbol placedSymbol(symbolInstance.anchor.point, symbolInstance.anchor.segment, sizeData.min, sizeData.max,
- 0, 0, placementZoom, false, symbolInstance.line);
+ symbolInstance.textOffset, placementZoom, false, symbolInstance.line);
for (const auto& symbol : symbolInstance.glyphQuads) {
addSymbol(
bucket->text, sizeData, symbol, placementZoom,
@@ -518,7 +520,7 @@ std::unique_ptr<SymbolBucket> SymbolLayout::place(CollisionTile& collisionTile)
if (iconScale < collisionTile.maxScale && symbolInstance.iconQuad) {
const Range<float> sizeData = bucket->iconSizeBinder->getVertexSizeData(feature);
PlacedSymbol placedSymbol(symbolInstance.anchor.point, symbolInstance.anchor.segment, sizeData.min, sizeData.max,
- 0, 0, placementZoom, false, symbolInstance.line);
+ symbolInstance.iconOffset, placementZoom, false, symbolInstance.line);
addSymbol(
bucket->icon, sizeData, *symbolInstance.iconQuad, placementZoom,
keepUpright, iconPlacement, collisionTile.config.angle, symbolInstance.writingModes, symbolInstance.anchor, placedSymbol);
@@ -580,10 +582,10 @@ void SymbolLayout::addSymbol(Buffer& buffer,
uint16_t index = segment.vertexLength;
// coordinates (2 triangles)
- buffer.vertices.emplace_back(SymbolLayoutAttributes::vertex(labelAnchor.point, tl, tex.x, tex.y, sizeData));
- buffer.vertices.emplace_back(SymbolLayoutAttributes::vertex(labelAnchor.point, tr, tex.x + tex.w, tex.y, sizeData));
- buffer.vertices.emplace_back(SymbolLayoutAttributes::vertex(labelAnchor.point, bl, tex.x, tex.y + tex.h, sizeData));
- buffer.vertices.emplace_back(SymbolLayoutAttributes::vertex(labelAnchor.point, br, tex.x + tex.w, tex.y + tex.h, sizeData));
+ buffer.vertices.emplace_back(SymbolLayoutAttributes::vertex(labelAnchor.point, tl, symbol.glyphOffset.y, tex.x, tex.y, sizeData));
+ buffer.vertices.emplace_back(SymbolLayoutAttributes::vertex(labelAnchor.point, tr, symbol.glyphOffset.y, tex.x + tex.w, tex.y, sizeData));
+ buffer.vertices.emplace_back(SymbolLayoutAttributes::vertex(labelAnchor.point, bl, symbol.glyphOffset.y, tex.x, tex.y + tex.h, sizeData));
+ buffer.vertices.emplace_back(SymbolLayoutAttributes::vertex(labelAnchor.point, br, symbol.glyphOffset.y, tex.x + tex.w, tex.y + tex.h, sizeData));
auto dynamicVertex = SymbolDynamicLayoutAttributes::vertex(labelAnchor.point, 0, placementZoom);
buffer.dynamicVertices.emplace_back(dynamicVertex);
diff --git a/src/mbgl/layout/symbol_projection.cpp b/src/mbgl/layout/symbol_projection.cpp
index 2e3828fff9..5b1dce29f8 100644
--- a/src/mbgl/layout/symbol_projection.cpp
+++ b/src/mbgl/layout/symbol_projection.cpp
@@ -62,7 +62,6 @@ namespace mbgl {
}
bool isVisible(const vec4& anchorPos, const float placementZoom, const std::array<double, 2>& clippingBuffer, const FrameHistory& frameHistory) {
- if (true) return true;
const float x = anchorPos[0] / anchorPos[3];
const float y = anchorPos[1] / anchorPos[3];
const bool inPaddedViewport = (
@@ -151,8 +150,8 @@ namespace mbgl {
void placeGlyphsAlongLine(const PlacedSymbol& symbol, const float fontSize, const bool flip, const mat4& labelPlaneMatrix,
gl::VertexVector<SymbolDynamicLayoutAttributes::Vertex>& dynamicVertexArray) {
const float fontScale = fontSize / 24.0;
- const float lineOffsetX = symbol.lineOffsetX * fontSize;
- const float lineOffsetY = symbol.lineOffsetY * fontSize;
+ const float lineOffsetX = symbol.lineOffset[0] * fontSize;
+ const float lineOffsetY = symbol.lineOffset[1] * fontSize;
const Point<float> anchorPoint = project(symbol.anchorPoint, labelPlaneMatrix);
@@ -177,7 +176,7 @@ namespace mbgl {
const ZoomEvaluatedSize partiallyEvaluatedSize = sizeBinder.evaluateForZoom(state.getZoom());
- const std::array<double, 2> clippingBuffer = {{ 256.0 / state.getSize().width * 2.0 + 1.0, 256.0 / state.getSize().height }};
+ const std::array<double, 2> clippingBuffer = {{ 256.0 / state.getSize().width * 2.0 + 1.0, 256.0 / state.getSize().height * 2.0 + 1.0 }};
const mat4 labelPlaneMatrix = getLabelPlaneMatrix(posMatrix, values.pitchAlignment == style::AlignmentType::Map,
values.rotationAlignment == style::AlignmentType::Map, state, tile.id.pixelsToTileUnits(1, state.getZoom()));
diff --git a/src/mbgl/programs/symbol_program.hpp b/src/mbgl/programs/symbol_program.hpp
index 95727d2c84..2248c81ffe 100644
--- a/src/mbgl/programs/symbol_program.hpp
+++ b/src/mbgl/programs/symbol_program.hpp
@@ -50,6 +50,7 @@ struct SymbolLayoutAttributes : gl::Attributes<
{
static Vertex vertex(Point<float> labelAnchor,
Point<float> o,
+ float glyphOffsetY,
uint16_t tx,
uint16_t ty,
const Range<float>& sizeData) {
@@ -59,7 +60,7 @@ struct SymbolLayoutAttributes : gl::Attributes<
static_cast<int16_t>(labelAnchor.x),
static_cast<int16_t>(labelAnchor.y),
static_cast<int16_t>(::round(o.x * 64)), // use 1/64 pixels for placement
- static_cast<int16_t>(::round(o.y * 64))
+ static_cast<int16_t>(::round((o.y + glyphOffsetY) * 64))
}},
{{
tx,
diff --git a/src/mbgl/renderer/buckets/symbol_bucket.hpp b/src/mbgl/renderer/buckets/symbol_bucket.hpp
index 5f109bbddf..769841b3a1 100644
--- a/src/mbgl/renderer/buckets/symbol_bucket.hpp
+++ b/src/mbgl/renderer/buckets/symbol_bucket.hpp
@@ -18,15 +18,14 @@ namespace mbgl {
class PlacedSymbol {
public:
PlacedSymbol(Point<float> anchorPoint_, uint16_t segment_, float lowerSize_, float upperSize_,
- float lineOffsetX_, float lineOffsetY_, float placementZoom_, bool vertical_, GeometryCoordinates line_) :
+ std::array<float, 2> lineOffset_, float placementZoom_, bool vertical_, GeometryCoordinates line_) :
anchorPoint(anchorPoint_), segment(segment_), lowerSize(lowerSize_), upperSize(upperSize_),
- lineOffsetX(lineOffsetX_), lineOffsetY(lineOffsetY_), placementZoom(placementZoom_), vertical(vertical_), line(line_) {}
+ lineOffset(lineOffset_), placementZoom(placementZoom_), vertical(vertical_), line(line_) {}
Point<float> anchorPoint;
uint16_t segment;
float lowerSize;
float upperSize;
- float lineOffsetX;
- float lineOffsetY;
+ std::array<float, 2> lineOffset;
float placementZoom;
bool vertical;
GeometryCoordinates line;
diff --git a/src/mbgl/text/shaping.cpp b/src/mbgl/text/shaping.cpp
index 338abe2e43..c81f25d4eb 100644
--- a/src/mbgl/text/shaping.cpp
+++ b/src/mbgl/text/shaping.cpp
@@ -27,12 +27,9 @@ void align(Shaping& shaping,
const float verticalAlign,
const float maxLineLength,
const float lineHeight,
- const std::size_t lineCount,
- const Point<float>& translate) {
- const float shiftX =
- (justify - horizontalAlign) * maxLineLength + ::round(translate.x);
- const float shiftY =
- (-verticalAlign * lineCount + 0.5) * lineHeight + ::round(translate.y);
+ const std::size_t lineCount) {
+ const float shiftX = (justify - horizontalAlign) * maxLineLength;
+ const float shiftY = (-verticalAlign * lineCount + 0.5) * lineHeight;
for (auto& glyph : shaping.positionedGlyphs) {
glyph.x += shiftX;
@@ -205,7 +202,6 @@ void shapeLines(Shaping& shaping,
const float horizontalAlign,
const float verticalAlign,
const float justify,
- const Point<float>& translate,
const float verticalHeight,
const WritingModeType writingMode,
const Glyphs& glyphs) {
@@ -259,7 +255,7 @@ void shapeLines(Shaping& shaping,
}
align(shaping, justify, horizontalAlign, verticalAlign, maxLineLength, lineHeight,
- lines.size(), translate);
+ lines.size());
const uint32_t height = lines.size() * lineHeight;
// Calculate the bounding box
@@ -288,7 +284,7 @@ const Shaping getShaping(const std::u16string& logicalInput,
determineLineBreaks(logicalInput, spacing, maxWidth, writingMode, glyphs));
shapeLines(shaping, reorderedLines, spacing, lineHeight, horizontalAlign, verticalAlign,
- justify, translate, verticalHeight, writingMode, glyphs);
+ justify, verticalHeight, writingMode, glyphs);
return shaping;
}