From f901e776b3e63aaaa6bc0cc4476624bf84127fe6 Mon Sep 17 00:00:00 2001 From: Anand Thakker Date: Tue, 28 Feb 2017 19:54:24 -0800 Subject: [core] Implement data-driven styling for {text,icon}-{color,opacity,halo-color,halo-blur,halo-width} (#7939) * Add symbol dds attributes and adapt style code generation * Update to mapbox-gl-js/master * Refactor SymbolFeature as a subclass of GeometryTileFeature Prepares for enabling DDS on symbol paint properties by allowing the SymbolFeatures, which we keep around after constructing SymbolLayout, to be used in evaluating data-driven paint properties later in the layout process. * Draft approach for splitting icon/text paint properties The `Program` types are set up to bind GL attributes to each of the data-driven paint properties specified in the `PaintProperties` type provided. Since `SymbolPaintProperties` specifies both `Text*` and `Icon*` properties, the symbolIcon, symbolIconSDF, and symbolGlyph programs each attempt to bind roughly double the number of attributes that they actually need. This change addresses this by: - Adding the more specific `IconPaintProperties` and `TextPaintProperties` types, which are subsets of the full `SymbolPaintProperties`. - The symbol layer continues to use its `SymbolPaintProperties paint` member to track layer property state, but it provides helpers that construct objects of each the specific `{Icon,Text}PaintProperties::Evaluated` type, for use by the painter. - The three symbol programs instantiate `Program<>` using the appropriate `{Icon,Text}PaintProperties` type. * check in generated style code * Populate paint buffers for symbol DDS properties * Address first round of review comments * Refactor VectorTile{Layer,Feature} to explicitly share data * Update submodule --- src/mbgl/style/layers/symbol_layer_impl.cpp | 56 +++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 15 deletions(-) (limited to 'src/mbgl/style/layers/symbol_layer_impl.cpp') diff --git a/src/mbgl/style/layers/symbol_layer_impl.cpp b/src/mbgl/style/layers/symbol_layer_impl.cpp index 32547e465a..ff59b14d65 100644 --- a/src/mbgl/style/layers/symbol_layer_impl.cpp +++ b/src/mbgl/style/layers/symbol_layer_impl.cpp @@ -16,9 +16,14 @@ bool SymbolLayer::Impl::evaluate(const PropertyEvaluationParameters& parameters) // text-size and icon-size are layout properties but they also need to be evaluated as paint properties: iconSize = layout.evaluate(parameters); textSize = layout.evaluate(parameters); - - passes = ((paint.evaluated.get() > 0 && (paint.evaluated.get().a > 0 || paint.evaluated.get().a > 0) && iconSize > 0) - || (paint.evaluated.get() > 0 && (paint.evaluated.get().a > 0 || paint.evaluated.get().a > 0) && textSize > 0)) + + auto hasIconOpacity = paint.evaluated.get().constantOr(Color::black()).a > 0 || + paint.evaluated.get().constantOr(Color::black()).a > 0; + auto hasTextOpacity = paint.evaluated.get().constantOr(Color::black()).a > 0 || + paint.evaluated.get().constantOr(Color::black()).a > 0; + + passes = ((paint.evaluated.get().constantOr(1) > 0 && hasIconOpacity && iconSize > 0) + || (paint.evaluated.get().constantOr(1) > 0 && hasTextOpacity && textSize > 0)) ? RenderPass::Translucent : RenderPass::None; return paint.hasTransition(); @@ -38,20 +43,43 @@ std::unique_ptr SymbolLayer::Impl::createLayout(const BucketParame *spriteAtlas); } -SymbolPropertyValues SymbolLayer::Impl::iconPropertyValues(const SymbolLayoutProperties::Evaluated& layout_) const { - return SymbolPropertyValues { - layout_.get(), // icon-pitch-alignment is not yet implemented; inherit the rotation alignment - layout_.get(), - layout_.get(), +IconPaintProperties::Evaluated SymbolLayer::Impl::iconPaintProperties() const { + return IconPaintProperties::Evaluated { paint.evaluated.get(), paint.evaluated.get(), paint.evaluated.get(), paint.evaluated.get(), paint.evaluated.get(), paint.evaluated.get(), + paint.evaluated.get() + }; +} + +TextPaintProperties::Evaluated SymbolLayer::Impl::textPaintProperties() const { + return TextPaintProperties::Evaluated { + paint.evaluated.get(), + paint.evaluated.get(), + paint.evaluated.get(), + paint.evaluated.get(), + paint.evaluated.get(), + paint.evaluated.get(), + paint.evaluated.get() + }; +} + + +SymbolPropertyValues SymbolLayer::Impl::iconPropertyValues(const SymbolLayoutProperties::Evaluated& layout_) const { + return SymbolPropertyValues { + layout_.get(), // icon-pitch-alignment is not yet implemented; inherit the rotation alignment + layout_.get(), + layout_.get(), + paint.evaluated.get(), paint.evaluated.get(), iconSize, - 1.0f + 1.0f, + paint.evaluated.get().constantOr(Color::black()).a > 0 && + paint.evaluated.get().constantOr(1), + paint.evaluated.get().constantOr(Color::black()).a > 0 }; } @@ -60,15 +88,13 @@ SymbolPropertyValues SymbolLayer::Impl::textPropertyValues(const SymbolLayoutPro layout_.get(), layout_.get(), layout_.get(), - paint.evaluated.get(), - paint.evaluated.get(), - paint.evaluated.get(), - paint.evaluated.get(), - paint.evaluated.get(), paint.evaluated.get(), paint.evaluated.get(), textSize, - 24.0f + 24.0f, + paint.evaluated.get().constantOr(Color::black()).a > 0 && + paint.evaluated.get().constantOr(1), + paint.evaluated.get().constantOr(Color::black()).a > 0 }; } -- cgit v1.2.1