summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Shalamov <alexander.shalamov@mapbox.com>2019-04-25 12:36:18 +0300
committerAlexander Shalamov <alexander.shalamov@mapbox.com>2019-04-26 15:06:20 +0300
commit684d5ceed3b338c2c1eafa447892f0da3635ddd7 (patch)
tree2d3ab1a0cd93ce4665f63fc349ef8959e9b1fbd1
parent5276a2f78f4faa704371a56d7ec828768283c7e9 (diff)
downloadqtlocation-mapboxgl-upstream/alexshalamov_cp_14517_release-mojito.tar.gz
[core] CP #14517 - Store type of renderable segment when sorting symbols by keyupstream/alexshalamov_cp_14517_release-mojito
-rw-r--r--src/mbgl/renderer/layers/render_symbol_layer.cpp46
1 files changed, 31 insertions, 15 deletions
diff --git a/src/mbgl/renderer/layers/render_symbol_layer.cpp b/src/mbgl/renderer/layers/render_symbol_layer.cpp
index 7e2eb1aa86..696220662d 100644
--- a/src/mbgl/renderer/layers/render_symbol_layer.cpp
+++ b/src/mbgl/renderer/layers/render_symbol_layer.cpp
@@ -74,25 +74,41 @@ struct RenderableSegment {
const RenderTile& tile_,
const LayerRenderData& renderData_,
const SymbolBucket::PaintProperties& bucketPaintProperties_,
- float sortKey_) :
+ float sortKey_,
+ bool isText_) :
segment(std::move(segment_)),
tile(tile_),
renderData(renderData_),
bucketPaintProperties(bucketPaintProperties_),
- sortKey(sortKey_) {}
+ sortKey(sortKey_),
+ isText(isText_) {}
SegmentWrapper segment;
const RenderTile& tile;
const LayerRenderData& renderData;
const SymbolBucket::PaintProperties& bucketPaintProperties;
float sortKey;
-
- bool hasIconData() const {
- return static_cast<const SymbolBucket&>(*renderData.bucket).hasIconData();
- }
+ bool isText;
friend bool operator < (const RenderableSegment& lhs, const RenderableSegment& rhs) {
- return lhs.sortKey < rhs.sortKey;
+ // Sort renderable segments by a sort key.
+ if (lhs.sortKey < rhs.sortKey) {
+ return true;
+ }
+
+ // In cases when sort key is the same, sort by the type of a segment (text over icons),
+ // and for segments of the same type with the same sort key, sort by a tile id.
+ if (lhs.sortKey == rhs.sortKey) {
+ if (!lhs.isText && rhs.isText) {
+ return true;
+ }
+
+ if (lhs.isText == rhs.isText) {
+ return lhs.tile.id < rhs.tile.id;
+ }
+ }
+
+ return false;
}
};
@@ -383,7 +399,7 @@ void RenderSymbolLayer::render(PaintParameters& parameters, RenderSource*) {
}
const bool sortFeaturesByKey = !impl(baseImpl).layout.get<SymbolSortKey>().isUndefined();
- std::set<RenderableSegment> renderableSegments;
+ std::multiset<RenderableSegment> renderableSegments;
const auto draw = [&parameters, this] (auto& programInstance,
const auto& uniformValues,
@@ -464,15 +480,15 @@ void RenderSymbolLayer::render(PaintParameters& parameters, RenderSource*) {
assert(bucket.paintProperties.find(getID()) != bucket.paintProperties.end());
const auto& bucketPaintProperties = bucket.paintProperties.at(getID());
- auto addRenderables = [&renderableSegments, &tile, renderData, &bucketPaintProperties, it = renderableSegments.begin()] (auto& segments) mutable {
+ auto addRenderables = [&renderableSegments, &tile, renderData, &bucketPaintProperties, it = renderableSegments.begin()] (auto& segments, bool isText) mutable {
for (auto& segment : segments) {
- it = renderableSegments.emplace_hint(it, SegmentWrapper{std::ref(segment)}, tile, *renderData, bucketPaintProperties, segment.sortKey);
+ it = renderableSegments.emplace_hint(it, SegmentWrapper{std::ref(segment)}, tile, *renderData, bucketPaintProperties, segment.sortKey, isText);
}
};
if (bucket.hasIconData()) {
if (sortFeaturesByKey) {
- addRenderables(bucket.icon.segments);
+ addRenderables(bucket.icon.segments, false /*isText*/);
} else {
drawIcon(draw, tile, *renderData, std::ref(bucket.icon.segments), bucketPaintProperties, parameters);
}
@@ -480,7 +496,7 @@ void RenderSymbolLayer::render(PaintParameters& parameters, RenderSource*) {
if (bucket.hasTextData()) {
if (sortFeaturesByKey) {
- addRenderables(bucket.text.segments);
+ addRenderables(bucket.text.segments, true /*isText*/);
} else {
drawText(draw, tile, *renderData, std::ref(bucket.text.segments), bucketPaintProperties, parameters);
}
@@ -565,10 +581,10 @@ void RenderSymbolLayer::render(PaintParameters& parameters, RenderSource*) {
if (sortFeaturesByKey) {
for (auto& renderable : renderableSegments) {
- if (renderable.hasIconData()) {
- drawIcon(draw, renderable.tile, renderable.renderData, renderable.segment, renderable.bucketPaintProperties, parameters);
- } else {
+ if (renderable.isText) {
drawText(draw, renderable.tile, renderable.renderData, renderable.segment, renderable.bucketPaintProperties, parameters);
+ } else {
+ drawIcon(draw, renderable.tile, renderable.renderData, renderable.segment, renderable.bucketPaintProperties, parameters);
}
}
}