diff options
author | zmiao <miao.zhao@mapbox.com> | 2019-08-26 21:54:59 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-26 21:54:59 +0300 |
commit | c770c2326261ee22b22216538a2eaaed3648bc0d (patch) | |
tree | 03725479de83005554f1d3df3d0c0df25c128a2f /src/mbgl/renderer/layers | |
parent | dbda6cc9e889278f391e45d952f57c95234b3f55 (diff) | |
download | qtlocation-mapboxgl-c770c2326261ee22b22216538a2eaaed3648bc0d.tar.gz |
[core] fix mixed sdf + non-sdf icon rendering in one layer (#15456)
* [core] fix icon symbol rendring when sdf and non-sdf icon in the same symbol layer
* fix build error
* fix typo
* revert renderableSegment change
* simplify codes
* fix build error
* refine sdf icon flag
* [core] fix mixed sdf + non-sdf icon rendering in one layer
* remove iconstatus getter in stymbol bucket
* fix review findings
* provide bitwise operator for SymbolContent enum
* use MBGL_MBGL_CONSTEXPR
* add one missing update for sdfIcon
* make renderer symbol type as enum
Diffstat (limited to 'src/mbgl/renderer/layers')
-rw-r--r-- | src/mbgl/renderer/layers/render_symbol_layer.cpp | 43 | ||||
-rw-r--r-- | src/mbgl/renderer/layers/render_symbol_layer.hpp | 6 |
2 files changed, 32 insertions, 17 deletions
diff --git a/src/mbgl/renderer/layers/render_symbol_layer.cpp b/src/mbgl/renderer/layers/render_symbol_layer.cpp index ffb32b9746..d0c038222a 100644 --- a/src/mbgl/renderer/layers/render_symbol_layer.cpp +++ b/src/mbgl/renderer/layers/render_symbol_layer.cpp @@ -67,20 +67,20 @@ struct RenderableSegment { const LayerRenderData& renderData_, const SymbolBucket::PaintProperties& bucketPaintProperties_, float sortKey_, - bool isText_) : + const SymbolType type_) : segment(std::move(segment_)), tile(tile_), renderData(renderData_), bucketPaintProperties(bucketPaintProperties_), sortKey(sortKey_), - isText(isText_) {} + type(type_) {} SegmentWrapper segment; const RenderTile& tile; const LayerRenderData& renderData; const SymbolBucket::PaintProperties& bucketPaintProperties; float sortKey; - bool isText; + SymbolType type; friend bool operator < (const RenderableSegment& lhs, const RenderableSegment& rhs) { // Sort renderable segments by a sort key. @@ -91,11 +91,11 @@ struct RenderableSegment { // 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) { + if (lhs.type != SymbolType::Text && rhs.type == SymbolType::Text) { return true; } - if (lhs.isText == rhs.isText) { + if (lhs.type == rhs.type) { return lhs.tile.id < rhs.tile.id; } } @@ -110,7 +110,8 @@ void drawIcon(const DrawFn& draw, const LayerRenderData& renderData, SegmentsWrapper iconSegments, const SymbolBucket::PaintProperties& bucketPaintProperties, - const PaintParameters& parameters) { + const PaintParameters& parameters, + const bool sdfIcons) { auto& bucket = static_cast<SymbolBucket&>(*renderData.bucket); const auto& evaluated = getEvaluated<SymbolLayerProperties>(renderData.layerProperties); const auto& layout = *bucket.layout; @@ -124,7 +125,7 @@ void drawIcon(const DrawFn& draw, const bool iconTransformed = values.rotationAlignment == AlignmentType::Map || parameters.state.getPitch() != 0; const gfx::TextureBinding textureBinding{ tile.getIconAtlasTexture().getResource(), - bucket.sdfIcons || + sdfIcons || parameters.state.isChanging() || iconScaled || iconTransformed ? gfx::TextureFilterType::Linear @@ -133,11 +134,11 @@ void drawIcon(const DrawFn& draw, const Size& iconSize = tile.getIconAtlasTexture().size; const bool variablePlacedIcon = bucket.hasVariablePlacement && layout.get<IconTextFit>() != IconTextFitType::None; - if (bucket.sdfIcons) { + if (sdfIcons) { if (values.hasHalo) { draw(parameters.programs.getSymbolLayerPrograms().symbolIconSDF, SymbolSDFIconProgram::layoutUniformValues(false, variablePlacedIcon, values, iconSize, parameters.pixelsToGLUnits, parameters.pixelRatio, alongLine, tile, parameters.state, parameters.symbolFadeChange, SymbolSDFPart::Halo), - bucket.icon, + bucket.sdfIcon, iconSegments, bucket.iconSizeBinder, bucketPaintProperties.iconBinders, @@ -151,7 +152,7 @@ void drawIcon(const DrawFn& draw, if (values.hasFill) { draw(parameters.programs.getSymbolLayerPrograms().symbolIconSDF, SymbolSDFIconProgram::layoutUniformValues(false, variablePlacedIcon, values, iconSize, parameters.pixelsToGLUnits, parameters.pixelRatio, alongLine, tile, parameters.state, parameters.symbolFadeChange, SymbolSDFPart::Fill), - bucket.icon, + bucket.sdfIcon, iconSegments, bucket.iconSizeBinder, bucketPaintProperties.iconBinders, @@ -361,23 +362,31 @@ void RenderSymbolLayer::render(PaintParameters& parameters) { 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, bool isText) mutable { + auto addRenderables = [&renderableSegments, &tile, renderData, &bucketPaintProperties, it = renderableSegments.begin()] (auto& segments, const SymbolType type) mutable { for (auto& segment : segments) { - it = renderableSegments.emplace_hint(it, SegmentWrapper{std::ref(segment)}, tile, *renderData, bucketPaintProperties, segment.sortKey, isText); + it = renderableSegments.emplace_hint(it, SegmentWrapper{std::ref(segment)}, tile, *renderData, bucketPaintProperties, segment.sortKey, type); } }; if (bucket.hasIconData()) { if (sortFeaturesByKey) { - addRenderables(bucket.icon.segments, false /*isText*/); + addRenderables(bucket.icon.segments, SymbolType::IconRGBA); + } else { + drawIcon(draw, tile, *renderData, std::ref(bucket.icon.segments), bucketPaintProperties, parameters, false /*sdfIcon*/); + } + } + + if (bucket.hasSdfIconData()) { + if (sortFeaturesByKey) { + addRenderables(bucket.sdfIcon.segments, SymbolType::IconSDF); } else { - drawIcon(draw, tile, *renderData, std::ref(bucket.icon.segments), bucketPaintProperties, parameters); + drawIcon(draw, tile, *renderData, std::ref(bucket.sdfIcon.segments), bucketPaintProperties, parameters, true /*sdfIcon*/); } } if (bucket.hasTextData()) { if (sortFeaturesByKey) { - addRenderables(bucket.text.segments, true /*isText*/); + addRenderables(bucket.text.segments, SymbolType::Text); } else { drawText(draw, tile, *renderData, std::ref(bucket.text.segments), bucketPaintProperties, parameters); } @@ -460,10 +469,10 @@ void RenderSymbolLayer::render(PaintParameters& parameters) { if (sortFeaturesByKey) { for (auto& renderable : renderableSegments) { - if (renderable.isText) { + if (renderable.type == SymbolType::Text) { drawText(draw, renderable.tile, renderable.renderData, renderable.segment, renderable.bucketPaintProperties, parameters); } else { - drawIcon(draw, renderable.tile, renderable.renderData, renderable.segment, renderable.bucketPaintProperties, parameters); + drawIcon(draw, renderable.tile, renderable.renderData, renderable.segment, renderable.bucketPaintProperties, parameters, renderable.type == SymbolType::IconSDF); } } } diff --git a/src/mbgl/renderer/layers/render_symbol_layer.hpp b/src/mbgl/renderer/layers/render_symbol_layer.hpp index d9ce8c688d..5fcb9e2c8c 100644 --- a/src/mbgl/renderer/layers/render_symbol_layer.hpp +++ b/src/mbgl/renderer/layers/render_symbol_layer.hpp @@ -50,6 +50,12 @@ public: bool hasFill; }; +enum class SymbolType : uint8_t { + Text, + IconRGBA, + IconSDF +}; + } // namespace style class RenderSymbolLayer final: public RenderLayer { |