diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2017-04-21 09:19:47 -0700 |
---|---|---|
committer | Ivo van Dongen <ivovandongen@users.noreply.github.com> | 2017-04-25 17:23:54 -0700 |
commit | 3c175adf30546fe58713b8fed29ac35a85e150be (patch) | |
tree | 5666e9bcf311ed1b86a13444e50dc7a030c10da9 | |
parent | ea8ec38df156c6683c886253dbb1f6bc828686ff (diff) | |
download | qtlocation-mapboxgl-3c175adf30546fe58713b8fed29ac35a85e150be.tar.gz |
[core] split off render layers
104 files changed, 1715 insertions, 1114 deletions
diff --git a/cmake/core-files.cmake b/cmake/core-files.cmake index a0c46c7cd4..602cf90dad 100644 --- a/cmake/core-files.cmake +++ b/cmake/core-files.cmake @@ -154,6 +154,8 @@ set(MBGL_CORE_FILES # renderer src/mbgl/renderer/bucket.hpp + src/mbgl/renderer/bucket_parameters.cpp + src/mbgl/renderer/bucket_parameters.hpp src/mbgl/renderer/circle_bucket.cpp src/mbgl/renderer/circle_bucket.hpp src/mbgl/renderer/debug_bucket.cpp @@ -162,6 +164,8 @@ set(MBGL_CORE_FILES src/mbgl/renderer/fill_bucket.hpp src/mbgl/renderer/frame_history.cpp src/mbgl/renderer/frame_history.hpp + src/mbgl/renderer/group_by_layout.cpp + src/mbgl/renderer/group_by_layout.hpp src/mbgl/renderer/line_bucket.cpp src/mbgl/renderer/line_bucket.hpp src/mbgl/renderer/paint_parameters.hpp @@ -177,8 +181,26 @@ set(MBGL_CORE_FILES src/mbgl/renderer/painter_symbol.cpp src/mbgl/renderer/raster_bucket.cpp src/mbgl/renderer/raster_bucket.hpp + src/mbgl/renderer/render_background_layer.cpp + src/mbgl/renderer/render_background_layer.hpp + src/mbgl/renderer/render_circle_layer.cpp + src/mbgl/renderer/render_circle_layer.hpp + src/mbgl/renderer/render_custom_layer.cpp + src/mbgl/renderer/render_custom_layer.hpp + src/mbgl/renderer/render_fill_extrusion_layer.cpp + src/mbgl/renderer/render_fill_extrusion_layer.hpp + src/mbgl/renderer/render_fill_layer.cpp + src/mbgl/renderer/render_fill_layer.hpp src/mbgl/renderer/render_item.hpp + src/mbgl/renderer/render_layer.cpp + src/mbgl/renderer/render_layer.hpp + src/mbgl/renderer/render_line_layer.cpp + src/mbgl/renderer/render_line_layer.hpp src/mbgl/renderer/render_pass.hpp + src/mbgl/renderer/render_raster_layer.cpp + src/mbgl/renderer/render_raster_layer.hpp + src/mbgl/renderer/render_symbol_layer.cpp + src/mbgl/renderer/render_symbol_layer.hpp src/mbgl/renderer/render_tile.cpp src/mbgl/renderer/render_tile.hpp src/mbgl/renderer/symbol_bucket.cpp @@ -247,22 +269,19 @@ set(MBGL_CORE_FILES include/mbgl/style/filter_evaluator.hpp include/mbgl/style/image.hpp include/mbgl/style/layer.hpp + include/mbgl/style/layer_type.hpp include/mbgl/style/property_value.hpp include/mbgl/style/query.hpp include/mbgl/style/source.hpp include/mbgl/style/transition_options.hpp include/mbgl/style/types.hpp include/mbgl/style/undefined.hpp - src/mbgl/style/bucket_parameters.cpp - src/mbgl/style/bucket_parameters.hpp src/mbgl/style/cascade_parameters.hpp src/mbgl/style/class_dictionary.cpp src/mbgl/style/class_dictionary.hpp src/mbgl/style/cross_faded_property_evaluator.cpp src/mbgl/style/cross_faded_property_evaluator.hpp src/mbgl/style/data_driven_property_evaluator.hpp - src/mbgl/style/group_by_layout.cpp - src/mbgl/style/group_by_layout.hpp src/mbgl/style/image.cpp src/mbgl/style/layer.cpp src/mbgl/style/layer_impl.cpp @@ -285,6 +304,8 @@ set(MBGL_CORE_FILES src/mbgl/style/source_observer.hpp src/mbgl/style/style.cpp src/mbgl/style/style.hpp + src/mbgl/style/style.hpp + src/mbgl/style/style.hpp src/mbgl/style/tile_source_impl.cpp src/mbgl/style/tile_source_impl.hpp src/mbgl/style/types.cpp diff --git a/cmake/test-files.cmake b/cmake/test-files.cmake index 02df6c4d67..9012ae9616 100644 --- a/cmake/test-files.cmake +++ b/cmake/test-files.cmake @@ -41,6 +41,9 @@ set(MBGL_TEST_FILES # programs test/programs/binary_program.test.cpp + # renderer + test/renderer/group_by_layout.test.cpp + # sprite test/sprite/sprite_atlas.test.cpp test/sprite/sprite_parser.test.cpp @@ -90,7 +93,6 @@ set(MBGL_TEST_FILES test/style/function/source_function.test.cpp # style - test/style/group_by_layout.test.cpp test/style/paint_property.test.cpp test/style/source.test.cpp test/style/style.test.cpp diff --git a/include/mbgl/style/layer.hpp b/include/mbgl/style/layer.hpp index fa88b30dbc..f09eb0165a 100644 --- a/include/mbgl/style/layer.hpp +++ b/include/mbgl/style/layer.hpp @@ -2,6 +2,7 @@ #include <mbgl/util/noncopyable.hpp> #include <mbgl/util/any.hpp> +#include <mbgl/style/layer_type.hpp> #include <mbgl/style/types.hpp> #include <memory> @@ -36,23 +37,16 @@ class FillExtrusionLayer; * auto circleLayer = std::make_unique<CircleLayer>("my-circle-layer"); */ class Layer : public mbgl::util::noncopyable { +public: + class Impl; + protected: - enum class Type { - Fill, - Line, - Circle, - Symbol, - Raster, - Background, - Custom, - FillExtrusion, - }; - class Impl; - const Type type; - Layer(Type, std::unique_ptr<Impl>); + const LayerType type; + Layer(LayerType, std::unique_ptr<Impl>); public: + virtual ~Layer(); // Check whether this layer is of the given subtype. @@ -85,21 +79,21 @@ public: template <class V> auto accept(V&& visitor) { switch (type) { - case Type::Fill: + case LayerType::Fill: return visitor(*as<FillLayer>()); - case Type::Line: + case LayerType::Line: return visitor(*as<LineLayer>()); - case Type::Circle: + case LayerType::Circle: return visitor(*as<CircleLayer>()); - case Type::Symbol: + case LayerType::Symbol: return visitor(*as<SymbolLayer>()); - case Type::Raster: + case LayerType::Raster: return visitor(*as<RasterLayer>()); - case Type::Background: + case LayerType::Background: return visitor(*as<BackgroundLayer>()); - case Type::Custom: + case LayerType::Custom: return visitor(*as<CustomLayer>()); - case Type::FillExtrusion: + case LayerType::FillExtrusion: return visitor(*as<FillExtrusionLayer>()); } } @@ -123,8 +117,6 @@ public: // object here, so that separately-obtained references to this object share // identical platform-native peers. any peer; - - friend std::string layoutKey(const Layer&); }; } // namespace style diff --git a/include/mbgl/style/layer_type.hpp b/include/mbgl/style/layer_type.hpp new file mode 100644 index 0000000000..66ff834eee --- /dev/null +++ b/include/mbgl/style/layer_type.hpp @@ -0,0 +1,18 @@ +#pragma once + +namespace mbgl { +namespace style { + +enum class LayerType { + Fill, + Line, + Circle, + Symbol, + Raster, + Background, + Custom, + FillExtrusion, +}; + +} // namespace style +} // namespace mbgl
\ No newline at end of file diff --git a/include/mbgl/style/layers/background_layer.hpp b/include/mbgl/style/layers/background_layer.hpp index 0de3302b7a..6604a868f3 100644 --- a/include/mbgl/style/layers/background_layer.hpp +++ b/include/mbgl/style/layers/background_layer.hpp @@ -50,7 +50,7 @@ public: template <> inline bool Layer::is<BackgroundLayer>() const { - return type == Type::Background; + return type == LayerType::Background; } } // namespace style diff --git a/include/mbgl/style/layers/circle_layer.hpp b/include/mbgl/style/layers/circle_layer.hpp index c12d476706..3a3723249f 100644 --- a/include/mbgl/style/layers/circle_layer.hpp +++ b/include/mbgl/style/layers/circle_layer.hpp @@ -100,7 +100,7 @@ public: template <> inline bool Layer::is<CircleLayer>() const { - return type == Type::Circle; + return type == LayerType::Circle; } } // namespace style diff --git a/include/mbgl/style/layers/fill_extrusion_layer.hpp b/include/mbgl/style/layers/fill_extrusion_layer.hpp index 31d517d016..1f79f87fac 100644 --- a/include/mbgl/style/layers/fill_extrusion_layer.hpp +++ b/include/mbgl/style/layers/fill_extrusion_layer.hpp @@ -82,7 +82,7 @@ public: template <> inline bool Layer::is<FillExtrusionLayer>() const { - return type == Type::FillExtrusion; + return type == LayerType::FillExtrusion; } } // namespace style diff --git a/include/mbgl/style/layers/fill_layer.hpp b/include/mbgl/style/layers/fill_layer.hpp index aac4be92e2..8371ff7a8f 100644 --- a/include/mbgl/style/layers/fill_layer.hpp +++ b/include/mbgl/style/layers/fill_layer.hpp @@ -82,7 +82,7 @@ public: template <> inline bool Layer::is<FillLayer>() const { - return type == Type::Fill; + return type == LayerType::Fill; } } // namespace style diff --git a/include/mbgl/style/layers/layer.hpp.ejs b/include/mbgl/style/layers/layer.hpp.ejs index 972d932b59..59d7cd6415 100644 --- a/include/mbgl/style/layers/layer.hpp.ejs +++ b/include/mbgl/style/layers/layer.hpp.ejs @@ -75,7 +75,7 @@ public: template <> inline bool Layer::is<<%- camelize(type) %>Layer>() const { - return type == Type::<%- camelize(type) %>; + return type == LayerType::<%- camelize(type) %>; } } // namespace style diff --git a/include/mbgl/style/layers/line_layer.hpp b/include/mbgl/style/layers/line_layer.hpp index 756cc6f431..a5f08e553c 100644 --- a/include/mbgl/style/layers/line_layer.hpp +++ b/include/mbgl/style/layers/line_layer.hpp @@ -120,7 +120,7 @@ public: template <> inline bool Layer::is<LineLayer>() const { - return type == Type::Line; + return type == LayerType::Line; } } // namespace style diff --git a/include/mbgl/style/layers/raster_layer.hpp b/include/mbgl/style/layers/raster_layer.hpp index 3596a71f58..c0351da5d0 100644 --- a/include/mbgl/style/layers/raster_layer.hpp +++ b/include/mbgl/style/layers/raster_layer.hpp @@ -77,7 +77,7 @@ public: template <> inline bool Layer::is<RasterLayer>() const { - return type == Type::Raster; + return type == LayerType::Raster; } } // namespace style diff --git a/include/mbgl/style/layers/symbol_layer.hpp b/include/mbgl/style/layers/symbol_layer.hpp index 6e29faa949..ea6bda55d7 100644 --- a/include/mbgl/style/layers/symbol_layer.hpp +++ b/include/mbgl/style/layers/symbol_layer.hpp @@ -264,7 +264,7 @@ public: template <> inline bool Layer::is<SymbolLayer>() const { - return type == Type::Symbol; + return type == LayerType::Symbol; } } // namespace style diff --git a/src/mbgl/geometry/feature_index.cpp b/src/mbgl/geometry/feature_index.cpp index 6fae5fe9a1..8251e4d03a 100644 --- a/src/mbgl/geometry/feature_index.cpp +++ b/src/mbgl/geometry/feature_index.cpp @@ -1,8 +1,7 @@ #include <mbgl/geometry/feature_index.hpp> #include <mbgl/style/style.hpp> -#include <mbgl/style/layer.hpp> -#include <mbgl/style/layer_impl.hpp> -#include <mbgl/style/layers/symbol_layer.hpp> +#include <mbgl/renderer/render_layer.hpp> +#include <mbgl/renderer/render_symbol_layer.hpp> #include <mbgl/text/collision_tile.hpp> #include <mbgl/util/constants.hpp> #include <mbgl/util/math.hpp> @@ -61,7 +60,7 @@ static int16_t getAdditionalQueryRadius(const RenderedQueryOptions& queryOptions // Determine the additional radius needed factoring in property functions float additionalRadius = 0; - auto getQueryRadius = [&](const style::Layer& layer) { + auto getQueryRadius = [&](const RenderLayer& layer) { auto bucket = tile.getBucket(layer); if (bucket) { additionalRadius = std::max(additionalRadius, bucket->getQueryRadius(layer) * pixelsToTileUnits); @@ -70,13 +69,13 @@ static int16_t getAdditionalQueryRadius(const RenderedQueryOptions& queryOptions if (queryOptions.layerIDs) { for (const auto& layerID : *queryOptions.layerIDs) { - style::Layer* layer = style.getLayer(layerID); + RenderLayer* layer = style.getRenderLayer(layerID); if (layer) { getQueryRadius(*layer); } } } else { - for (const style::Layer* layer : style.getLayers()) { + for (const RenderLayer* layer : style.getRenderLayers()) { getQueryRadius(*layer); } } @@ -156,10 +155,10 @@ void FeatureIndex::addFeature( continue; } - auto styleLayer = style.getLayer(layerID); - if (!styleLayer || - (!styleLayer->is<style::SymbolLayer>() && - !styleLayer->baseImpl->queryIntersectsFeature(queryGeometry, *geometryTileFeature, tileID.z, bearing, pixelsToTileUnits))) { + auto renderLayer = style.getRenderLayer(layerID); + if (!renderLayer || + (!renderLayer->is<RenderSymbolLayer>() && + !renderLayer->queryIntersectsFeature(queryGeometry, *geometryTileFeature, tileID.z, bearing, pixelsToTileUnits))) { continue; } diff --git a/src/mbgl/layout/symbol_layout.cpp b/src/mbgl/layout/symbol_layout.cpp index 0b05d4f5e1..9aca316a00 100644 --- a/src/mbgl/layout/symbol_layout.cpp +++ b/src/mbgl/layout/symbol_layout.cpp @@ -3,8 +3,8 @@ #include <mbgl/layout/clip_lines.hpp> #include <mbgl/renderer/symbol_bucket.hpp> #include <mbgl/style/filter_evaluator.hpp> -#include <mbgl/style/bucket_parameters.hpp> -#include <mbgl/style/layers/symbol_layer.hpp> +#include <mbgl/renderer/bucket_parameters.hpp> +#include <mbgl/renderer/render_symbol_layer.hpp> #include <mbgl/style/layers/symbol_layer_impl.hpp> #include <mbgl/sprite/sprite_atlas.hpp> #include <mbgl/text/get_anchors.hpp> @@ -22,6 +22,7 @@ #include <mbgl/math/log2.hpp> #include <mbgl/util/platform.hpp> #include <mbgl/util/logging.hpp> +#include <mbgl/tile/geometry_tile_data.hpp> #include <mapbox/polylabel.hpp> @@ -38,7 +39,7 @@ static bool has(const style::SymbolLayoutProperties::PossiblyEvaluated& layout) } SymbolLayout::SymbolLayout(const BucketParameters& parameters, - const std::vector<const Layer*>& layers, + const std::vector<const RenderLayer*>& layers, const GeometryTileLayer& sourceLayer, IconDependencies& iconDependencies, uintptr_t _spriteAtlasMapIndex, @@ -51,11 +52,11 @@ SymbolLayout::SymbolLayout(const BucketParameters& parameters, spriteAtlasMapIndex(_spriteAtlasMapIndex), tileSize(util::tileSize * overscaling), tilePixelRatio(float(util::EXTENT) / tileSize), - textSize(layers.at(0)->as<SymbolLayer>()->impl->layout.unevaluated.get<TextSize>()), - iconSize(layers.at(0)->as<SymbolLayer>()->impl->layout.unevaluated.get<IconSize>()) + textSize(layers.at(0)->as<RenderSymbolLayer>()->impl->layout.unevaluated.get<TextSize>()), + iconSize(layers.at(0)->as<RenderSymbolLayer>()->impl->layout.unevaluated.get<IconSize>()) { - const SymbolLayer::Impl& leader = *layers.at(0)->as<SymbolLayer>()->impl; + const SymbolLayer::Impl& leader = *layers.at(0)->as<RenderSymbolLayer>()->impl; layout = leader.layout.evaluate(PropertyEvaluationParameters(zoom)); @@ -89,8 +90,8 @@ SymbolLayout::SymbolLayout(const BucketParameters& parameters, for (const auto& layer : layers) { layerPaintProperties.emplace(layer->getID(), std::make_pair( - layer->as<SymbolLayer>()->impl->iconPaintProperties(), - layer->as<SymbolLayer>()->impl->textPaintProperties() + layer->as<RenderSymbolLayer>()->iconPaintProperties(), + layer->as<RenderSymbolLayer>()->textPaintProperties() )); } diff --git a/src/mbgl/layout/symbol_layout.hpp b/src/mbgl/layout/symbol_layout.hpp index f49f93eaf1..55e4098451 100644 --- a/src/mbgl/layout/symbol_layout.hpp +++ b/src/mbgl/layout/symbol_layout.hpp @@ -15,21 +15,20 @@ namespace mbgl { -class GeometryTileLayer; +class BucketParameters; class CollisionTile; class SymbolBucket; class Anchor; +class RenderLayer; namespace style { -class BucketParameters; class Filter; -class Layer; } // namespace style class SymbolLayout { public: - SymbolLayout(const style::BucketParameters&, - const std::vector<const style::Layer*>&, + SymbolLayout(const BucketParameters&, + const std::vector<const RenderLayer*>&, const GeometryTileLayer&, IconDependencies&, uintptr_t, diff --git a/src/mbgl/programs/symbol_program.hpp b/src/mbgl/programs/symbol_program.hpp index ae50e790be..4895f6fca7 100644 --- a/src/mbgl/programs/symbol_program.hpp +++ b/src/mbgl/programs/symbol_program.hpp @@ -13,6 +13,7 @@ #include <mbgl/util/size.hpp> #include <mbgl/style/layers/symbol_layer_properties.hpp> #include <mbgl/style/layers/symbol_layer_impl.hpp> +#include <mbgl/renderer/render_symbol_layer.hpp> #include <cmath> diff --git a/src/mbgl/renderer/bucket.hpp b/src/mbgl/renderer/bucket.hpp index 84ecabe632..6c391cf014 100644 --- a/src/mbgl/renderer/bucket.hpp +++ b/src/mbgl/renderer/bucket.hpp @@ -3,6 +3,7 @@ #include <mbgl/renderer/render_pass.hpp> #include <mbgl/util/noncopyable.hpp> #include <mbgl/tile/geometry_tile_data.hpp> +#include <mbgl/renderer/render_layer.hpp> #include <atomic> #include <string> @@ -36,11 +37,11 @@ public: // Every time this bucket is getting rendered, this function is called. This happens either // once or twice (for Opaque and Transparent render passes). - virtual void render(Painter&, PaintParameters&, const style::Layer&, const RenderTile&) = 0; + virtual void render(Painter&, PaintParameters&, const RenderLayer&, const RenderTile&) = 0; virtual bool hasData() const = 0; - virtual float getQueryRadius(const style::Layer&) const { + virtual float getQueryRadius(const RenderLayer&) const { return 0; }; diff --git a/src/mbgl/renderer/bucket_parameters.cpp b/src/mbgl/renderer/bucket_parameters.cpp new file mode 100644 index 0000000000..35b87bffea --- /dev/null +++ b/src/mbgl/renderer/bucket_parameters.cpp @@ -0,0 +1,5 @@ +#include <mbgl/renderer/bucket_parameters.hpp> + +namespace mbgl { + +} // namespace mbgl diff --git a/src/mbgl/style/bucket_parameters.hpp b/src/mbgl/renderer/bucket_parameters.hpp index d0edbcac30..1774ba2bbe 100644 --- a/src/mbgl/style/bucket_parameters.hpp +++ b/src/mbgl/renderer/bucket_parameters.hpp @@ -4,7 +4,6 @@ #include <mbgl/tile/tile_id.hpp> namespace mbgl { -namespace style { class BucketParameters { public: @@ -12,5 +11,4 @@ public: const MapMode mode; }; -} // namespace style } // namespace mbgl diff --git a/src/mbgl/renderer/circle_bucket.cpp b/src/mbgl/renderer/circle_bucket.cpp index 94529a66d8..1e08eca478 100644 --- a/src/mbgl/renderer/circle_bucket.cpp +++ b/src/mbgl/renderer/circle_bucket.cpp @@ -1,9 +1,9 @@ #include <mbgl/renderer/circle_bucket.hpp> +#include <mbgl/renderer/bucket_parameters.hpp> #include <mbgl/renderer/painter.hpp> #include <mbgl/programs/circle_program.hpp> -#include <mbgl/style/bucket_parameters.hpp> -#include <mbgl/style/layers/circle_layer.hpp> #include <mbgl/style/layers/circle_layer_impl.hpp> +#include <mbgl/renderer/render_circle_layer.hpp> #include <mbgl/util/constants.hpp> #include <mbgl/util/math.hpp> @@ -11,14 +11,14 @@ namespace mbgl { using namespace style; -CircleBucket::CircleBucket(const BucketParameters& parameters, const std::vector<const Layer*>& layers) +CircleBucket::CircleBucket(const BucketParameters& parameters, const std::vector<const RenderLayer*>& layers) : mode(parameters.mode) { for (const auto& layer : layers) { paintPropertyBinders.emplace( std::piecewise_construct, std::forward_as_tuple(layer->getID()), std::forward_as_tuple( - layer->as<CircleLayer>()->impl->paint.evaluated, + layer->as<RenderCircleLayer>()->evaluated, parameters.tileID.overscaledZ)); } } @@ -36,9 +36,9 @@ void CircleBucket::upload(gl::Context& context) { void CircleBucket::render(Painter& painter, PaintParameters& parameters, - const Layer& layer, + const RenderLayer& layer, const RenderTile& tile) { - painter.renderCircle(parameters, *this, *layer.as<CircleLayer>(), tile); + painter.renderCircle(parameters, *this, *layer.as<RenderCircleLayer>(), tile); } bool CircleBucket::hasData() const { @@ -99,24 +99,24 @@ void CircleBucket::addFeature(const GeometryTileFeature& feature, } template <class Property> -static float get(const CircleLayer& layer, const std::map<std::string, CircleProgram::PaintPropertyBinders>& paintPropertyBinders) { +static float get(const RenderCircleLayer& layer, const std::map<std::string, CircleProgram::PaintPropertyBinders>& paintPropertyBinders) { auto it = paintPropertyBinders.find(layer.getID()); if (it == paintPropertyBinders.end() || !it->second.statistics<Property>().max()) { - return layer.impl->paint.evaluated.get<Property>().constantOr(Property::defaultValue()); + return layer.evaluated.get<Property>().constantOr(Property::defaultValue()); } else { return *it->second.statistics<Property>().max(); } } -float CircleBucket::getQueryRadius(const style::Layer& layer) const { - if (!layer.is<CircleLayer>()) { +float CircleBucket::getQueryRadius(const RenderLayer& layer) const { + if (!layer.is<RenderCircleLayer>()) { return 0; } - auto circleLayer = layer.as<CircleLayer>(); + auto circleLayer = layer.as<RenderCircleLayer>(); float radius = get<CircleRadius>(*circleLayer, paintPropertyBinders); - auto translate = circleLayer->impl->paint.evaluated.get<CircleTranslate>(); + auto translate = circleLayer->evaluated.get<CircleTranslate>(); return radius + util::length(translate[0], translate[1]); } diff --git a/src/mbgl/renderer/circle_bucket.hpp b/src/mbgl/renderer/circle_bucket.hpp index 02f60ad2ba..855565ebf4 100644 --- a/src/mbgl/renderer/circle_bucket.hpp +++ b/src/mbgl/renderer/circle_bucket.hpp @@ -11,22 +11,20 @@ namespace mbgl { -namespace style { class BucketParameters; -} // namespace style class CircleBucket : public Bucket { public: - CircleBucket(const style::BucketParameters&, const std::vector<const style::Layer*>&); + CircleBucket(const BucketParameters&, const std::vector<const RenderLayer*>&); void addFeature(const GeometryTileFeature&, const GeometryCollection&) override; bool hasData() const override; void upload(gl::Context&) override; - void render(Painter&, PaintParameters&, const style::Layer&, const RenderTile&) override; + void render(Painter&, PaintParameters&, const RenderLayer&, const RenderTile&) override; - float getQueryRadius(const style::Layer&) const override; + float getQueryRadius(const RenderLayer&) const override; gl::VertexVector<CircleLayoutVertex> vertices; gl::IndexVector<gl::Triangles> triangles; diff --git a/src/mbgl/renderer/fill_bucket.cpp b/src/mbgl/renderer/fill_bucket.cpp index 53bf825d48..2409fd365b 100644 --- a/src/mbgl/renderer/fill_bucket.cpp +++ b/src/mbgl/renderer/fill_bucket.cpp @@ -1,9 +1,9 @@ #include <mbgl/renderer/fill_bucket.hpp> #include <mbgl/renderer/painter.hpp> #include <mbgl/programs/fill_program.hpp> -#include <mbgl/style/bucket_parameters.hpp> -#include <mbgl/style/layers/fill_layer.hpp> +#include <mbgl/renderer/bucket_parameters.hpp> #include <mbgl/style/layers/fill_layer_impl.hpp> +#include <mbgl/renderer/render_fill_layer.hpp> #include <mbgl/util/math.hpp> #include <mapbox/earcut.hpp> @@ -28,13 +28,13 @@ using namespace style; struct GeometryTooLongException : std::exception {}; -FillBucket::FillBucket(const BucketParameters& parameters, const std::vector<const Layer*>& layers) { +FillBucket::FillBucket(const BucketParameters& parameters, const std::vector<const RenderLayer*>& layers) { for (const auto& layer : layers) { paintPropertyBinders.emplace( std::piecewise_construct, std::forward_as_tuple(layer->getID()), std::forward_as_tuple( - layer->as<FillLayer>()->impl->paint.evaluated, + layer->as<RenderFillLayer>()->evaluated, parameters.tileID.overscaledZ)); } } @@ -123,21 +123,21 @@ void FillBucket::upload(gl::Context& context) { void FillBucket::render(Painter& painter, PaintParameters& parameters, - const Layer& layer, + const RenderLayer& layer, const RenderTile& tile) { - painter.renderFill(parameters, *this, *layer.as<FillLayer>(), tile); + painter.renderFill(parameters, *this, *layer.as<RenderFillLayer>(), tile); } bool FillBucket::hasData() const { return !triangleSegments.empty() || !lineSegments.empty(); } -float FillBucket::getQueryRadius(const style::Layer& layer) const { - if (!layer.is<FillLayer>()) { +float FillBucket::getQueryRadius(const RenderLayer& layer) const { + if (!layer.is<RenderFillLayer>()) { return 0; } - const std::array<float, 2>& translate = layer.as<FillLayer>()->impl->paint.evaluated.get<FillTranslate>(); + const std::array<float, 2>& translate = layer.as<RenderFillLayer>()->evaluated.get<FillTranslate>(); return util::length(translate[0], translate[1]); } diff --git a/src/mbgl/renderer/fill_bucket.hpp b/src/mbgl/renderer/fill_bucket.hpp index e96cd2ac5e..421d8b332b 100644 --- a/src/mbgl/renderer/fill_bucket.hpp +++ b/src/mbgl/renderer/fill_bucket.hpp @@ -12,22 +12,20 @@ namespace mbgl { -namespace style { class BucketParameters; -} // namespace style class FillBucket : public Bucket { public: - FillBucket(const style::BucketParameters&, const std::vector<const style::Layer*>&); + FillBucket(const BucketParameters&, const std::vector<const RenderLayer*>&); void addFeature(const GeometryTileFeature&, const GeometryCollection&) override; bool hasData() const override; void upload(gl::Context&) override; - void render(Painter&, PaintParameters&, const style::Layer&, const RenderTile&) override; + void render(Painter&, PaintParameters&, const RenderLayer&, const RenderTile&) override; - float getQueryRadius(const style::Layer&) const override; + float getQueryRadius(const RenderLayer&) const override; gl::VertexVector<FillLayoutVertex> vertices; gl::IndexVector<gl::Lines> lines; diff --git a/src/mbgl/renderer/group_by_layout.cpp b/src/mbgl/renderer/group_by_layout.cpp new file mode 100644 index 0000000000..df1eb7c7dd --- /dev/null +++ b/src/mbgl/renderer/group_by_layout.cpp @@ -0,0 +1,48 @@ +#include <mbgl/renderer/group_by_layout.hpp> +#include <mbgl/renderer/render_layer.hpp> +#include <mbgl/style/layer_impl.hpp> +#include <mbgl/style/conversion/stringify.hpp> +#include <mbgl/util/rapidjson.hpp> + +#include <rapidjson/writer.h> +#include <rapidjson/stringbuffer.h> + +#include <unordered_map> + +namespace mbgl { + +std::string layoutKey(const RenderLayer& layer) { + using namespace style::conversion; + + rapidjson::StringBuffer s; + rapidjson::Writer<rapidjson::StringBuffer> writer(s); + + writer.StartArray(); + writer.Uint(static_cast<uint32_t>(layer.type)); + writer.String(layer.baseImpl.source); + writer.String(layer.baseImpl.sourceLayer); + writer.Double(layer.baseImpl.minZoom); + writer.Double(layer.baseImpl.maxZoom); + writer.Uint(static_cast<uint32_t>(layer.baseImpl.visibility)); + stringify(writer, layer.baseImpl.filter); + layer.baseImpl.stringifyLayout(writer); + writer.EndArray(); + + return s.GetString(); +} + +std::vector<std::vector<const RenderLayer*>> groupByLayout(const std::vector<std::unique_ptr<RenderLayer>>& layers) { + std::unordered_map<std::string, std::vector<const RenderLayer*>> map; + for (auto& layer : layers) { + map[layoutKey(*layer)].push_back(layer.get()); + } + + std::vector<std::vector<const RenderLayer*>> result; + for (auto& pair : map) { + result.push_back(pair.second); + } + + return result; +} + +} // namespace mbgl diff --git a/src/mbgl/renderer/group_by_layout.hpp b/src/mbgl/renderer/group_by_layout.hpp new file mode 100644 index 0000000000..bc3ecfae63 --- /dev/null +++ b/src/mbgl/renderer/group_by_layout.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include <vector> +#include <memory> + +namespace mbgl { + +class RenderLayer; + +std::vector<std::vector<const RenderLayer*>> groupByLayout(const std::vector<std::unique_ptr<RenderLayer>>&); + +} // namespace mbgl diff --git a/src/mbgl/renderer/line_bucket.cpp b/src/mbgl/renderer/line_bucket.cpp index 8c56524020..7bb4e2f202 100644 --- a/src/mbgl/renderer/line_bucket.cpp +++ b/src/mbgl/renderer/line_bucket.cpp @@ -1,7 +1,7 @@ #include <mbgl/renderer/line_bucket.hpp> #include <mbgl/renderer/painter.hpp> -#include <mbgl/style/layers/line_layer.hpp> -#include <mbgl/style/bucket_parameters.hpp> +#include <mbgl/renderer/render_line_layer.hpp> +#include <mbgl/renderer/bucket_parameters.hpp> #include <mbgl/style/layers/line_layer_impl.hpp> #include <mbgl/util/math.hpp> #include <mbgl/util/constants.hpp> @@ -13,7 +13,7 @@ namespace mbgl { using namespace style; LineBucket::LineBucket(const BucketParameters& parameters, - const std::vector<const Layer*>& layers, + const std::vector<const RenderLayer*>& layers, const style::LineLayoutProperties& layout_) : layout(layout_.evaluate(PropertyEvaluationParameters(parameters.tileID.overscaledZ))), overscaling(parameters.tileID.overscaleFactor()) { @@ -22,7 +22,7 @@ LineBucket::LineBucket(const BucketParameters& parameters, std::piecewise_construct, std::forward_as_tuple(layer->getID()), std::forward_as_tuple( - layer->as<LineLayer>()->impl->paint.evaluated, + layer->as<RenderLineLayer>()->evaluated, parameters.tileID.overscaledZ)); } } @@ -460,9 +460,9 @@ void LineBucket::upload(gl::Context& context) { void LineBucket::render(Painter& painter, PaintParameters& parameters, - const Layer& layer, + const RenderLayer& layer, const RenderTile& tile) { - painter.renderLine(parameters, *this, *layer.as<LineLayer>(), tile); + painter.renderLine(parameters, *this, *layer.as<RenderLineLayer>(), tile); } bool LineBucket::hasData() const { @@ -470,17 +470,17 @@ bool LineBucket::hasData() const { } template <class Property> -static float get(const LineLayer& layer, const std::map<std::string, LineProgram::PaintPropertyBinders>& paintPropertyBinders) { +static float get(const RenderLineLayer& layer, const std::map<std::string, LineProgram::PaintPropertyBinders>& paintPropertyBinders) { auto it = paintPropertyBinders.find(layer.getID()); if (it == paintPropertyBinders.end() || !it->second.statistics<Property>().max()) { - return layer.impl->paint.evaluated.get<Property>().constantOr(Property::defaultValue()); + return layer.evaluated.get<Property>().constantOr(Property::defaultValue()); } else { return *it->second.statistics<Property>().max(); } } -float LineBucket::getLineWidth(const style::LineLayer& layer) const { - float lineWidth = layer.impl->paint.evaluated.get<LineWidth>(); +float LineBucket::getLineWidth(const RenderLineLayer& layer) const { + float lineWidth = layer.evaluated.get<LineWidth>(); float gapWidth = get<LineGapWidth>(layer, paintPropertyBinders); if (gapWidth) { @@ -490,15 +490,14 @@ float LineBucket::getLineWidth(const style::LineLayer& layer) const { } } -float LineBucket::getQueryRadius(const style::Layer& layer) const { - if (!layer.is<LineLayer>()) { +float LineBucket::getQueryRadius(const RenderLayer& layer) const { + if (!layer.is<RenderLineLayer>()) { return 0; } - auto lineLayer = layer.as<LineLayer>(); - auto paint = lineLayer->impl->paint; + auto lineLayer = layer.as<RenderLineLayer>(); - const std::array<float, 2>& translate = paint.evaluated.get<LineTranslate>(); + const std::array<float, 2>& translate = lineLayer->evaluated.get<LineTranslate>(); float offset = get<LineOffset>(*lineLayer, paintPropertyBinders); return getLineWidth(*lineLayer) / 2.0 + std::abs(offset) + util::length(translate[0], translate[1]); } diff --git a/src/mbgl/renderer/line_bucket.hpp b/src/mbgl/renderer/line_bucket.hpp index 30198305ad..c319548714 100644 --- a/src/mbgl/renderer/line_bucket.hpp +++ b/src/mbgl/renderer/line_bucket.hpp @@ -12,15 +12,13 @@ namespace mbgl { -namespace style { class BucketParameters; -class LineLayer; -} // namespace style +class RenderLineLayer; class LineBucket : public Bucket { public: - LineBucket(const style::BucketParameters&, - const std::vector<const style::Layer*>&, + LineBucket(const BucketParameters&, + const std::vector<const RenderLayer*>&, const style::LineLayoutProperties&); void addFeature(const GeometryTileFeature&, @@ -28,9 +26,9 @@ public: bool hasData() const override; void upload(gl::Context&) override; - void render(Painter&, PaintParameters&, const style::Layer&, const RenderTile&) override; + void render(Painter&, PaintParameters&, const RenderLayer&, const RenderTile&) override; - float getQueryRadius(const style::Layer&) const override; + float getQueryRadius(const RenderLayer&) const override; style::LineLayoutProperties::PossiblyEvaluated layout; @@ -63,7 +61,7 @@ private: const uint32_t overscaling; - float getLineWidth(const style::LineLayer& layer) const; + float getLineWidth(const RenderLineLayer& layer) const; }; } // namespace mbgl diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index f7a498ecae..0c4915d3e9 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -13,8 +13,8 @@ #include <mbgl/style/style.hpp> #include <mbgl/style/layer_impl.hpp> -#include <mbgl/style/layers/background_layer.hpp> -#include <mbgl/style/layers/custom_layer.hpp> +#include <mbgl/renderer/render_background_layer.hpp> +#include <mbgl/renderer/render_custom_layer.hpp> #include <mbgl/style/layers/custom_layer_impl.hpp> #include <mbgl/sprite/sprite_atlas.hpp> @@ -279,16 +279,16 @@ void Painter::renderPass(PaintParameters& parameters, currentLayer = i; const auto& item = *it; - const Layer& layer = item.layer; + const RenderLayer& layer = item.layer; - if (!layer.baseImpl->hasRenderPass(pass)) + if (!layer.hasRenderPass(pass)) continue; - if (layer.is<BackgroundLayer>()) { + if (layer.is<RenderBackgroundLayer>()) { MBGL_DEBUG_GROUP(context, "background"); - renderBackground(parameters, *layer.as<BackgroundLayer>()); - } else if (layer.is<CustomLayer>()) { - MBGL_DEBUG_GROUP(context, layer.baseImpl->id + " - custom"); + renderBackground(parameters, *layer.as<RenderBackgroundLayer>()); + } else if (layer.is<RenderCustomLayer>()) { + MBGL_DEBUG_GROUP(context, layer.baseImpl.id + " - custom"); // Reset GL state to a known state so the CustomLayer always has a clean slate. context.vertexArrayObject = 0; @@ -296,14 +296,14 @@ void Painter::renderPass(PaintParameters& parameters, context.setStencilMode(gl::StencilMode::disabled()); context.setColorMode(colorModeForRenderPass()); - layer.as<CustomLayer>()->impl->render(state); + layer.as<RenderCustomLayer>()->impl->render(state); // Reset the view back to our original one, just in case the CustomLayer changed // the viewport or Framebuffer. parameters.view.bind(); context.setDirtyState(); } else { - MBGL_DEBUG_GROUP(context, layer.baseImpl->id + " - " + util::toString(item.tile->id)); + MBGL_DEBUG_GROUP(context, layer.baseImpl.id + " - " + util::toString(item.tile->id)); item.bucket->render(*this, parameters, layer, *item.tile); } } diff --git a/src/mbgl/renderer/painter.hpp b/src/mbgl/renderer/painter.hpp index 3dcc1d5d46..9c6dd4505f 100644 --- a/src/mbgl/renderer/painter.hpp +++ b/src/mbgl/renderer/painter.hpp @@ -42,6 +42,13 @@ class CircleBucket; class SymbolBucket; class RasterBucket; +class RenderFillLayer; +class RenderLineLayer; +class RenderCircleLayer; +class RenderSymbolLayer; +class RenderRasterLayer; +class RenderBackgroundLayer; + class Programs; class PaintParameters; @@ -50,12 +57,6 @@ struct ClipID; namespace style { class Style; class Source; -class FillLayer; -class LineLayer; -class CircleLayer; -class SymbolLayer; -class RasterLayer; -class BackgroundLayer; } // namespace style struct FrameData { @@ -80,12 +81,12 @@ public: void renderClippingMask(const UnwrappedTileID&, const ClipID&); void renderTileDebug(const RenderTile&); - void renderFill(PaintParameters&, FillBucket&, const style::FillLayer&, const RenderTile&); - void renderLine(PaintParameters&, LineBucket&, const style::LineLayer&, const RenderTile&); - void renderCircle(PaintParameters&, CircleBucket&, const style::CircleLayer&, const RenderTile&); - void renderSymbol(PaintParameters&, SymbolBucket&, const style::SymbolLayer&, const RenderTile&); - void renderRaster(PaintParameters&, RasterBucket&, const style::RasterLayer&, const RenderTile&); - void renderBackground(PaintParameters&, const style::BackgroundLayer&); + void renderFill(PaintParameters&, FillBucket&, const RenderFillLayer&, const RenderTile&); + void renderLine(PaintParameters&, LineBucket&, const RenderLineLayer&, const RenderTile&); + void renderCircle(PaintParameters&, CircleBucket&, const RenderCircleLayer&, const RenderTile&); + void renderSymbol(PaintParameters&, SymbolBucket&, const RenderSymbolLayer&, const RenderTile&); + void renderRaster(PaintParameters&, RasterBucket&, const RenderRasterLayer&, const RenderTile&); + void renderBackground(PaintParameters&, const RenderBackgroundLayer&); #ifndef NDEBUG // Renders tile clip boundaries, using stencil buffer to calculate fill color. diff --git a/src/mbgl/renderer/painter_background.cpp b/src/mbgl/renderer/painter_background.cpp index 4ac414335b..ac16627246 100644 --- a/src/mbgl/renderer/painter_background.cpp +++ b/src/mbgl/renderer/painter_background.cpp @@ -1,6 +1,6 @@ #include <mbgl/renderer/painter.hpp> #include <mbgl/renderer/paint_parameters.hpp> -#include <mbgl/style/layers/background_layer.hpp> +#include <mbgl/renderer/render_background_layer.hpp> #include <mbgl/style/layers/background_layer_impl.hpp> #include <mbgl/programs/programs.hpp> #include <mbgl/programs/fill_program.hpp> @@ -11,10 +11,10 @@ namespace mbgl { using namespace style; -void Painter::renderBackground(PaintParameters& parameters, const BackgroundLayer& layer) { +void Painter::renderBackground(PaintParameters& parameters, const RenderBackgroundLayer& layer) { // Note that for bottommost layers without a pattern, the background color is drawn with // glClear rather than this method. - const BackgroundPaintProperties::Evaluated& background = layer.impl->paint.evaluated; + const BackgroundPaintProperties::Evaluated& background = layer.evaluated; style::FillPaintProperties::Evaluated properties; properties.get<FillPattern>() = background.get<BackgroundPattern>(); diff --git a/src/mbgl/renderer/painter_circle.cpp b/src/mbgl/renderer/painter_circle.cpp index 8d47e75f71..7c9194f6dd 100644 --- a/src/mbgl/renderer/painter_circle.cpp +++ b/src/mbgl/renderer/painter_circle.cpp @@ -2,7 +2,7 @@ #include <mbgl/renderer/paint_parameters.hpp> #include <mbgl/renderer/circle_bucket.hpp> #include <mbgl/renderer/render_tile.hpp> -#include <mbgl/style/layers/circle_layer.hpp> +#include <mbgl/renderer/render_circle_layer.hpp> #include <mbgl/style/layers/circle_layer_impl.hpp> #include <mbgl/programs/programs.hpp> #include <mbgl/programs/circle_program.hpp> @@ -14,13 +14,13 @@ using namespace style; void Painter::renderCircle(PaintParameters& parameters, CircleBucket& bucket, - const CircleLayer& layer, + const RenderCircleLayer& layer, const RenderTile& tile) { if (pass == RenderPass::Opaque) { return; } - const CirclePaintProperties::Evaluated& properties = layer.impl->paint.evaluated; + const CirclePaintProperties::Evaluated& properties = layer.evaluated; const bool scaleWithMap = properties.get<CirclePitchScale>() == CirclePitchScaleType::Map; parameters.programs.circle.draw( diff --git a/src/mbgl/renderer/painter_fill.cpp b/src/mbgl/renderer/painter_fill.cpp index 4276bd06ed..622f6386ef 100644 --- a/src/mbgl/renderer/painter_fill.cpp +++ b/src/mbgl/renderer/painter_fill.cpp @@ -2,7 +2,7 @@ #include <mbgl/renderer/paint_parameters.hpp> #include <mbgl/renderer/fill_bucket.hpp> #include <mbgl/renderer/render_tile.hpp> -#include <mbgl/style/layers/fill_layer.hpp> +#include <mbgl/renderer/render_fill_layer.hpp> #include <mbgl/style/layers/fill_layer_impl.hpp> #include <mbgl/sprite/sprite_atlas.hpp> #include <mbgl/programs/programs.hpp> @@ -15,9 +15,9 @@ using namespace style; void Painter::renderFill(PaintParameters& parameters, FillBucket& bucket, - const FillLayer& layer, + const RenderFillLayer& layer, const RenderTile& tile) { - const FillPaintProperties::Evaluated& properties = layer.impl->paint.evaluated; + const FillPaintProperties::Evaluated& properties = layer.evaluated; if (!properties.get<FillPattern>().from.empty()) { if (pass != RenderPass::Translucent) { @@ -70,7 +70,7 @@ void Painter::renderFill(PaintParameters& parameters, *bucket.triangleIndexBuffer, bucket.triangleSegments); - if (!properties.get<FillAntialias>() || !layer.impl->paint.unevaluated.get<FillOutlineColor>().isUndefined()) { + if (!properties.get<FillAntialias>() || !layer.unevaluated.get<FillOutlineColor>().isUndefined()) { return; } @@ -108,7 +108,7 @@ void Painter::renderFill(PaintParameters& parameters, ); }; - if (properties.get<FillAntialias>() && !layer.impl->paint.unevaluated.get<FillOutlineColor>().isUndefined() && pass == RenderPass::Translucent) { + if (properties.get<FillAntialias>() && !layer.unevaluated.get<FillOutlineColor>().isUndefined() && pass == RenderPass::Translucent) { draw(2, parameters.programs.fillOutline, gl::Lines { 2.0f }, @@ -127,7 +127,7 @@ void Painter::renderFill(PaintParameters& parameters, bucket.triangleSegments); } - if (properties.get<FillAntialias>() && layer.impl->paint.unevaluated.get<FillOutlineColor>().isUndefined() && pass == RenderPass::Translucent) { + if (properties.get<FillAntialias>() && layer.unevaluated.get<FillOutlineColor>().isUndefined() && pass == RenderPass::Translucent) { draw(2, parameters.programs.fillOutline, gl::Lines { 2.0f }, diff --git a/src/mbgl/renderer/painter_line.cpp b/src/mbgl/renderer/painter_line.cpp index 4e19f841b1..4d7a27d0f6 100644 --- a/src/mbgl/renderer/painter_line.cpp +++ b/src/mbgl/renderer/painter_line.cpp @@ -2,7 +2,7 @@ #include <mbgl/renderer/paint_parameters.hpp> #include <mbgl/renderer/line_bucket.hpp> #include <mbgl/renderer/render_tile.hpp> -#include <mbgl/style/layers/line_layer.hpp> +#include <mbgl/renderer/render_line_layer.hpp> #include <mbgl/style/layers/line_layer_impl.hpp> #include <mbgl/programs/programs.hpp> #include <mbgl/programs/line_program.hpp> @@ -15,13 +15,13 @@ using namespace style; void Painter::renderLine(PaintParameters& parameters, LineBucket& bucket, - const LineLayer& layer, + const RenderLineLayer& layer, const RenderTile& tile) { if (pass == RenderPass::Opaque) { return; } - const LinePaintProperties::Evaluated& properties = layer.impl->paint.evaluated; + const LinePaintProperties::Evaluated& properties = layer.evaluated; auto draw = [&] (auto& program, auto&& uniformValues) { program.draw( @@ -57,7 +57,7 @@ void Painter::renderLine(PaintParameters& parameters, pixelsToGLUnits, posA, posB, - layer.impl->dashLineWidth, + layer.dashLineWidth, lineAtlas->getSize().width)); } else if (!properties.get<LinePattern>().from.empty()) { diff --git a/src/mbgl/renderer/painter_raster.cpp b/src/mbgl/renderer/painter_raster.cpp index c216955db8..31f10ed3ba 100644 --- a/src/mbgl/renderer/painter_raster.cpp +++ b/src/mbgl/renderer/painter_raster.cpp @@ -2,7 +2,7 @@ #include <mbgl/renderer/paint_parameters.hpp> #include <mbgl/renderer/render_tile.hpp> #include <mbgl/renderer/raster_bucket.hpp> -#include <mbgl/style/layers/raster_layer.hpp> +#include <mbgl/renderer/render_raster_layer.hpp> #include <mbgl/style/layers/raster_layer_impl.hpp> #include <mbgl/programs/programs.hpp> #include <mbgl/programs/raster_program.hpp> @@ -41,14 +41,14 @@ static std::array<float, 3> spinWeights(float spin) { void Painter::renderRaster(PaintParameters& parameters, RasterBucket& bucket, - const RasterLayer& layer, + const RenderRasterLayer& layer, const RenderTile& tile) { if (pass != RenderPass::Translucent) return; if (!bucket.hasData()) return; - const RasterPaintProperties::Evaluated& properties = layer.impl->paint.evaluated; + const RasterPaintProperties::Evaluated& properties = layer.evaluated; const RasterProgram::PaintPropertyBinders paintAttributeData(properties, 0); assert(bucket.texture); diff --git a/src/mbgl/renderer/painter_symbol.cpp b/src/mbgl/renderer/painter_symbol.cpp index d2f492d17a..9bafb5df80 100644 --- a/src/mbgl/renderer/painter_symbol.cpp +++ b/src/mbgl/renderer/painter_symbol.cpp @@ -2,7 +2,7 @@ #include <mbgl/renderer/paint_parameters.hpp> #include <mbgl/renderer/symbol_bucket.hpp> #include <mbgl/renderer/render_tile.hpp> -#include <mbgl/style/layers/symbol_layer.hpp> +#include <mbgl/renderer/render_symbol_layer.hpp> #include <mbgl/style/layers/symbol_layer_impl.hpp> #include <mbgl/text/glyph_atlas.hpp> #include <mbgl/sprite/sprite_atlas.hpp> @@ -20,7 +20,7 @@ using namespace style; void Painter::renderSymbol(PaintParameters& parameters, SymbolBucket& bucket, - const SymbolLayer& layer, + const RenderSymbolLayer& layer, const RenderTile& tile) { if (pass == RenderPass::Opaque) { return; @@ -64,8 +64,8 @@ void Painter::renderSymbol(PaintParameters& parameters, }; if (bucket.hasIconData()) { - auto values = layer.impl->iconPropertyValues(layout); - auto paintPropertyValues = layer.impl->iconPaintProperties(); + auto values = layer.iconPropertyValues(layout); + auto paintPropertyValues = layer.iconPaintProperties(); SpriteAtlas& atlas = *layer.impl->spriteAtlas; const bool iconScaled = layout.get<IconSize>().constantOr(1.0) != 1.0 || @@ -110,8 +110,8 @@ void Painter::renderSymbol(PaintParameters& parameters, if (bucket.hasTextData()) { glyphAtlas->bind(context, 0); - auto values = layer.impl->textPropertyValues(layout); - auto paintPropertyValues = layer.impl->textPaintProperties(); + auto values = layer.textPropertyValues(layout); + auto paintPropertyValues = layer.textPaintProperties(); const Size texsize = glyphAtlas->getSize(); diff --git a/src/mbgl/renderer/raster_bucket.cpp b/src/mbgl/renderer/raster_bucket.cpp index f328ad9313..ee8ef24071 100644 --- a/src/mbgl/renderer/raster_bucket.cpp +++ b/src/mbgl/renderer/raster_bucket.cpp @@ -1,5 +1,5 @@ #include <mbgl/renderer/raster_bucket.hpp> -#include <mbgl/style/layers/raster_layer.hpp> +#include <mbgl/renderer/render_raster_layer.hpp> #include <mbgl/programs/raster_program.hpp> #include <mbgl/renderer/painter.hpp> #include <mbgl/gl/context.hpp> @@ -18,9 +18,9 @@ void RasterBucket::upload(gl::Context& context) { void RasterBucket::render(Painter& painter, PaintParameters& parameters, - const Layer& layer, + const RenderLayer& layer, const RenderTile& tile) { - painter.renderRaster(parameters, *this, *layer.as<RasterLayer>(), tile); + painter.renderRaster(parameters, *this, *layer.as<RenderRasterLayer>(), tile); } bool RasterBucket::hasData() const { diff --git a/src/mbgl/renderer/raster_bucket.hpp b/src/mbgl/renderer/raster_bucket.hpp index 20969cf6b8..334954e3f4 100644 --- a/src/mbgl/renderer/raster_bucket.hpp +++ b/src/mbgl/renderer/raster_bucket.hpp @@ -12,7 +12,7 @@ public: RasterBucket(UnassociatedImage&&); void upload(gl::Context&) override; - void render(Painter&, PaintParameters&, const style::Layer&, const RenderTile&) override; + void render(Painter&, PaintParameters&, const RenderLayer&, const RenderTile&) override; bool hasData() const override; UnassociatedImage image; diff --git a/src/mbgl/renderer/render_background_layer.cpp b/src/mbgl/renderer/render_background_layer.cpp new file mode 100644 index 0000000000..5b98210975 --- /dev/null +++ b/src/mbgl/renderer/render_background_layer.cpp @@ -0,0 +1,35 @@ +#include <mbgl/renderer/render_background_layer.hpp> +#include <mbgl/style/layers/background_layer_impl.hpp> +#include <mbgl/renderer/bucket.hpp> + +namespace mbgl { + +RenderBackgroundLayer::RenderBackgroundLayer(const style::BackgroundLayer::Impl& _impl) + : RenderLayer(style::LayerType::Background, _impl), + impl(&_impl) { +} + +std::unique_ptr<RenderLayer> RenderBackgroundLayer::clone() const { + return std::make_unique<RenderBackgroundLayer>(*this); +} + +std::unique_ptr<Bucket> RenderBackgroundLayer::createBucket(const BucketParameters &, + const std::vector<const RenderLayer *> &) const { + assert(false); + return nullptr; +} + +void RenderBackgroundLayer::cascade(const style::CascadeParameters ¶meters) { + unevaluated = impl->cascading.cascade(parameters, std::move(unevaluated)); +} + +bool RenderBackgroundLayer::evaluate(const style::PropertyEvaluationParameters ¶meters) { + evaluated = unevaluated.evaluate(parameters); + + passes = evaluated.get<style::BackgroundOpacity>() > 0 ? RenderPass::Translucent + : RenderPass::None; + + return unevaluated.hasTransition(); +} + +} diff --git a/src/mbgl/renderer/render_background_layer.hpp b/src/mbgl/renderer/render_background_layer.hpp new file mode 100644 index 0000000000..bd74f7b390 --- /dev/null +++ b/src/mbgl/renderer/render_background_layer.hpp @@ -0,0 +1,34 @@ +#pragma once + +#include <mbgl/renderer/render_layer.hpp> +#include <mbgl/style/layers/background_layer.hpp> +#include <mbgl/style/layers/background_layer_properties.hpp> + +namespace mbgl { + +class RenderBackgroundLayer: public RenderLayer { +public: + + RenderBackgroundLayer(const style::BackgroundLayer::Impl&); + ~RenderBackgroundLayer() final = default; + + std::unique_ptr<RenderLayer> clone() const override; + + void cascade(const style::CascadeParameters&) override; + bool evaluate(const style::PropertyEvaluationParameters&) override; + + std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const RenderLayer*>&) const override; + + // Paint properties + style::BackgroundPaintProperties::Unevaluated unevaluated; + style::BackgroundPaintProperties::Evaluated evaluated; + + const style::BackgroundLayer::Impl* const impl; +}; + +template <> +inline bool RenderLayer::is<RenderBackgroundLayer>() const { + return type == style::LayerType::Background; +} + +} diff --git a/src/mbgl/renderer/render_circle_layer.cpp b/src/mbgl/renderer/render_circle_layer.cpp new file mode 100644 index 0000000000..aa127e9859 --- /dev/null +++ b/src/mbgl/renderer/render_circle_layer.cpp @@ -0,0 +1,65 @@ +#include <mbgl/renderer/render_circle_layer.hpp> +#include <mbgl/renderer/circle_bucket.hpp> +#include <mbgl/style/layers/circle_layer_impl.hpp> +#include <mbgl/geometry/feature_index.hpp> +#include <mbgl/util/math.hpp> +#include <mbgl/util/intersection_tests.hpp> + +namespace mbgl { + +RenderCircleLayer::RenderCircleLayer(const style::CircleLayer::Impl& _impl) + : RenderLayer(style::LayerType::Circle, _impl), + impl(&_impl) { +} + +std::unique_ptr<RenderLayer> RenderCircleLayer::clone() const { + return std::make_unique<RenderCircleLayer>(*this); +} + +std::unique_ptr<Bucket> RenderCircleLayer::createBucket(const BucketParameters& parameters, const std::vector<const RenderLayer*>& layers) const { + return std::make_unique<CircleBucket>(parameters, layers); +} + +void RenderCircleLayer::cascade(const style::CascadeParameters& parameters) { + unevaluated = impl->cascading.cascade(parameters, std::move(unevaluated)); +} + +bool RenderCircleLayer::evaluate(const style::PropertyEvaluationParameters& parameters) { + evaluated = unevaluated.evaluate(parameters); + + passes = ((evaluated.get<style::CircleRadius>().constantOr(1) > 0 || + evaluated.get<style::CircleStrokeWidth>().constantOr(1) > 0) + && (evaluated.get<style::CircleColor>().constantOr(Color::black()).a > 0 || + evaluated.get<style::CircleStrokeColor>().constantOr(Color::black()).a > 0) + && (evaluated.get<style::CircleOpacity>().constantOr(1) > 0 || + evaluated.get<style::CircleStrokeOpacity>().constantOr(1) > 0)) + ? RenderPass::Translucent : RenderPass::None; + + return unevaluated.hasTransition(); +} + +bool RenderCircleLayer::queryIntersectsFeature( + const GeometryCoordinates& queryGeometry, + const GeometryTileFeature& feature, + const float zoom, + const float bearing, + const float pixelsToTileUnits) const { + + // Translate query geometry + auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry( + queryGeometry, + evaluated.get<style::CircleTranslate>(), + evaluated.get<style::CircleTranslateAnchor>(), + bearing, + pixelsToTileUnits); + + // Evaluate function + auto circleRadius = evaluated.get<style::CircleRadius>() + .evaluate(feature, zoom, style::CircleRadius::defaultValue()) + * pixelsToTileUnits; + + // Test intersection + return util::polygonIntersectsBufferedMultiPoint(translatedQueryGeometry.value_or(queryGeometry), feature.getGeometries(), circleRadius); +} + +} diff --git a/src/mbgl/renderer/render_circle_layer.hpp b/src/mbgl/renderer/render_circle_layer.hpp new file mode 100644 index 0000000000..5117b12246 --- /dev/null +++ b/src/mbgl/renderer/render_circle_layer.hpp @@ -0,0 +1,41 @@ +#pragma once + +#include <mbgl/renderer/render_layer.hpp> +#include <mbgl/style/layers/circle_layer.hpp> +#include <mbgl/style/layers/circle_layer_properties.hpp> + +namespace mbgl { + +class RenderCircleLayer: public RenderLayer { +public: + + RenderCircleLayer(const style::CircleLayer::Impl&); + ~RenderCircleLayer() final = default; + + std::unique_ptr<RenderLayer> clone() const override; + + void cascade(const style::CascadeParameters&) override; + bool evaluate(const style::PropertyEvaluationParameters&) override; + + bool queryIntersectsFeature( + const GeometryCoordinates&, + const GeometryTileFeature&, + const float, + const float, + const float) const override; + + std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const RenderLayer*>&) const override; + + // Paint properties + style::CirclePaintProperties::Unevaluated unevaluated; + style::CirclePaintProperties::Evaluated evaluated; + + const style::CircleLayer::Impl* const impl; +}; + +template <> +inline bool RenderLayer::is<RenderCircleLayer>() const { + return type == style::LayerType::Circle; +} + +} diff --git a/src/mbgl/renderer/render_custom_layer.cpp b/src/mbgl/renderer/render_custom_layer.cpp new file mode 100644 index 0000000000..f9dda47d7a --- /dev/null +++ b/src/mbgl/renderer/render_custom_layer.cpp @@ -0,0 +1,26 @@ +#include <mbgl/renderer/render_custom_layer.hpp> +#include <mbgl/style/layers/custom_layer_impl.hpp> +#include <mbgl/renderer/bucket.hpp> + +namespace mbgl { + +RenderCustomLayer::RenderCustomLayer(const style::CustomLayer::Impl& _impl) + : RenderLayer(style::LayerType::Custom, _impl), + impl(&_impl) { +} + +std::unique_ptr<RenderLayer> RenderCustomLayer::clone() const { + return std::make_unique<RenderCustomLayer>(*this); +} + +bool RenderCustomLayer::evaluate(const style::PropertyEvaluationParameters&) { + passes = RenderPass::Translucent; + return false; +} + +std::unique_ptr<Bucket> RenderCustomLayer::createBucket(const BucketParameters&, const std::vector<const RenderLayer*>&) const { + assert(false); + return nullptr; +} + +} diff --git a/src/mbgl/renderer/render_custom_layer.hpp b/src/mbgl/renderer/render_custom_layer.hpp new file mode 100644 index 0000000000..3c6c06ff7c --- /dev/null +++ b/src/mbgl/renderer/render_custom_layer.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include <mbgl/renderer/render_layer.hpp> +#include <mbgl/style/layers/custom_layer.hpp> + +namespace mbgl { + +class RenderCustomLayer: public RenderLayer { +public: + + RenderCustomLayer(const style::CustomLayer::Impl&); + ~RenderCustomLayer() final = default; + + std::unique_ptr<RenderLayer> clone() const override; + + void cascade(const style::CascadeParameters&) final {} + bool evaluate(const style::PropertyEvaluationParameters&) final; + + std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const RenderLayer*>&) const final; + + const style::CustomLayer::Impl* const impl; +}; + +template <> +inline bool RenderLayer::is<RenderCustomLayer>() const { + return type == style::LayerType::Custom; +} + +} diff --git a/src/mbgl/renderer/render_fill_extrusion_layer.cpp b/src/mbgl/renderer/render_fill_extrusion_layer.cpp new file mode 100644 index 0000000000..a378f12cf0 --- /dev/null +++ b/src/mbgl/renderer/render_fill_extrusion_layer.cpp @@ -0,0 +1,26 @@ +#include <mbgl/renderer/render_fill_extrusion_layer.hpp> +#include <mbgl/renderer/bucket.hpp> +#include <mbgl/style/layers/fill_extrusion_layer_impl.hpp> + +namespace mbgl { + +RenderFillExtrusionLayer::RenderFillExtrusionLayer(const style::FillExtrusionLayer::Impl& _impl) + : RenderLayer(style::LayerType::FillExtrusion, _impl) { +} + +std::unique_ptr<RenderLayer> RenderFillExtrusionLayer::clone() const { + return std::make_unique<RenderFillExtrusionLayer>(*this); +} + +std::unique_ptr<Bucket> RenderFillExtrusionLayer::createBucket(const BucketParameters&, const std::vector<const RenderLayer*>&) const { + return nullptr; +} + +void RenderFillExtrusionLayer::cascade(const style::CascadeParameters&) { +} + +bool RenderFillExtrusionLayer::evaluate(const style::PropertyEvaluationParameters&) { + return false; +} + +} // namespace mbgl diff --git a/src/mbgl/renderer/render_fill_extrusion_layer.hpp b/src/mbgl/renderer/render_fill_extrusion_layer.hpp new file mode 100644 index 0000000000..596ba02fee --- /dev/null +++ b/src/mbgl/renderer/render_fill_extrusion_layer.hpp @@ -0,0 +1,32 @@ +#pragma once + +#include <mbgl/renderer/render_layer.hpp> +#include <mbgl/style/layers/fill_extrusion_layer.hpp> +#include <mbgl/style/layers/fill_extrusion_layer_properties.hpp> + +namespace mbgl { + +class RenderFillExtrusionLayer: public RenderLayer { +public: + + RenderFillExtrusionLayer(const style::FillExtrusionLayer::Impl&); + ~RenderFillExtrusionLayer() final = default; + + std::unique_ptr<RenderLayer> clone() const override; + + void cascade(const style::CascadeParameters&) override; + bool evaluate(const style::PropertyEvaluationParameters&) override; + + std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const RenderLayer*>&) const override; + + // Paint properties + style::FillExtrusionPaintProperties::Unevaluated unevaluated; + style::FillExtrusionPaintProperties::Evaluated evaluated; +}; + +template <> +inline bool RenderLayer::is<RenderFillExtrusionLayer>() const { + return type == style::LayerType::FillExtrusion; +} + +} // namespace mbgl diff --git a/src/mbgl/renderer/render_fill_layer.cpp b/src/mbgl/renderer/render_fill_layer.cpp new file mode 100644 index 0000000000..126189fc50 --- /dev/null +++ b/src/mbgl/renderer/render_fill_layer.cpp @@ -0,0 +1,70 @@ +#include <mbgl/renderer/render_fill_layer.hpp> +#include <mbgl/renderer/fill_bucket.hpp> +#include <mbgl/style/layers/fill_layer_impl.hpp> +#include <mbgl/geometry/feature_index.hpp> +#include <mbgl/util/math.hpp> +#include <mbgl/util/intersection_tests.hpp> + +namespace mbgl { + +RenderFillLayer::RenderFillLayer(const style::FillLayer::Impl& _impl) + : RenderLayer(style::LayerType::Fill, _impl), + impl(&_impl) { +} + +std::unique_ptr<RenderLayer> RenderFillLayer::clone() const { + return std::make_unique<RenderFillLayer>(*this); +} + +std::unique_ptr<Bucket> RenderFillLayer::createBucket(const BucketParameters& parameters, const std::vector<const RenderLayer*>& layers) const { + return std::make_unique<FillBucket>(parameters, layers); +} + +void RenderFillLayer::cascade(const style::CascadeParameters& parameters) { + unevaluated = impl->cascading.cascade(parameters, std::move(unevaluated)); +} + +bool RenderFillLayer::evaluate(const style::PropertyEvaluationParameters& parameters) { + evaluated = unevaluated.evaluate(parameters); + + if (unevaluated.get<style::FillOutlineColor>().isUndefined()) { + evaluated.get<style::FillOutlineColor>() = evaluated.get<style::FillColor>(); + } + + passes = RenderPass::None; + + if (evaluated.get<style::FillAntialias>()) { + passes |= RenderPass::Translucent; + } + + if (!unevaluated.get<style::FillPattern>().isUndefined() + || evaluated.get<style::FillColor>().constantOr(Color()).a < 1.0f + || evaluated.get<style::FillOpacity>().constantOr(0) < 1.0f) { + passes |= RenderPass::Translucent; + } else { + passes |= RenderPass::Opaque; + } + + return unevaluated.hasTransition(); +} + + +bool RenderFillLayer::queryIntersectsFeature( + const GeometryCoordinates& queryGeometry, + const GeometryTileFeature& feature, + const float, + const float bearing, + const float pixelsToTileUnits) const { + + auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry( + queryGeometry, + evaluated.get<style::FillTranslate>(), + evaluated.get<style::FillTranslateAnchor>(), + bearing, + pixelsToTileUnits); + + return util::polygonIntersectsMultiPolygon(translatedQueryGeometry.value_or(queryGeometry), feature.getGeometries()); +} + + +} diff --git a/src/mbgl/renderer/render_fill_layer.hpp b/src/mbgl/renderer/render_fill_layer.hpp new file mode 100644 index 0000000000..25b969d4c3 --- /dev/null +++ b/src/mbgl/renderer/render_fill_layer.hpp @@ -0,0 +1,41 @@ +#pragma once + +#include <mbgl/renderer/render_layer.hpp> +#include <mbgl/style/layers/fill_layer.hpp> +#include <mbgl/style/layers/fill_layer_properties.hpp> + +namespace mbgl { + +class RenderFillLayer: public RenderLayer { +public: + + RenderFillLayer(const style::FillLayer::Impl&); + ~RenderFillLayer() final = default; + + std::unique_ptr<RenderLayer> clone() const override; + + void cascade(const style::CascadeParameters&) override; + bool evaluate(const style::PropertyEvaluationParameters&) override; + + bool queryIntersectsFeature( + const GeometryCoordinates&, + const GeometryTileFeature&, + const float, + const float, + const float) const override; + + std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const RenderLayer*>&) const override; + + // Paint properties + style::FillPaintProperties::Unevaluated unevaluated; + style::FillPaintProperties::Evaluated evaluated; + + const style::FillLayer::Impl* const impl; +}; + +template <> +inline bool RenderLayer::is<RenderFillLayer>() const { + return type == style::LayerType::Fill; +} + +} // namespace mbgl diff --git a/src/mbgl/renderer/render_item.hpp b/src/mbgl/renderer/render_item.hpp index b4b1f4aec2..575287d9c6 100644 --- a/src/mbgl/renderer/render_item.hpp +++ b/src/mbgl/renderer/render_item.hpp @@ -7,17 +7,17 @@ namespace mbgl { +class RenderLayer; class RenderTile; class Bucket; namespace style { -class Layer; class Source; } // namespace style class RenderItem { public: - RenderItem(const style::Layer& layer_, + RenderItem(const RenderLayer& layer_, const RenderTile* tile_ = nullptr, Bucket* bucket_ = nullptr) : tile(tile_), bucket(bucket_), layer(layer_) { @@ -25,7 +25,7 @@ public: const RenderTile* const tile; Bucket* const bucket; - const style::Layer& layer; + const RenderLayer& layer; }; class RenderData { diff --git a/src/mbgl/renderer/render_layer.cpp b/src/mbgl/renderer/render_layer.cpp new file mode 100644 index 0000000000..6699f39144 --- /dev/null +++ b/src/mbgl/renderer/render_layer.cpp @@ -0,0 +1,25 @@ +#include <mbgl/renderer/render_layer.hpp> +#include <mbgl/style/types.hpp> + +namespace mbgl { + +RenderLayer::RenderLayer(style::LayerType type_, const style::Layer::Impl& baseImpl_) + : type(type_), baseImpl(baseImpl_) { +} + +const std::string& RenderLayer::getID() const { + return baseImpl.id; +} + +bool RenderLayer::hasRenderPass(RenderPass pass) const { + return bool(passes & pass); +} + +bool RenderLayer::needsRendering(float zoom) const { + return passes != RenderPass::None + && baseImpl.visibility != style::VisibilityType::None + && baseImpl.minZoom <= zoom + && baseImpl.maxZoom >= zoom; +} + +}
\ No newline at end of file diff --git a/src/mbgl/renderer/render_layer.hpp b/src/mbgl/renderer/render_layer.hpp new file mode 100644 index 0000000000..af5345d5e3 --- /dev/null +++ b/src/mbgl/renderer/render_layer.hpp @@ -0,0 +1,87 @@ +#pragma once + +#include <mbgl/renderer/render_pass.hpp> +#include <mbgl/style/layer_impl.hpp> +#include <mbgl/style/layer_type.hpp> +#include <mbgl/tile/geometry_tile_data.hpp> + +#include <memory> +#include <string> + +namespace mbgl { + +class Bucket; +class BucketParameters; + +namespace style { +class CascadeParameters; +class PropertyEvaluationParameters; +} // namespace style + +class RenderLayer { + +protected: + RenderLayer(style::LayerType, const style::Layer::Impl&); + + const style::LayerType type; + +public: + + virtual ~RenderLayer() = default; + + // Create an identical copy of this layer. + virtual std::unique_ptr<RenderLayer> clone() const = 0; + + // Partially evaluate paint properties based on a set of classes. + virtual void cascade(const style::CascadeParameters&) = 0; + + // Fully evaluate cascaded paint properties based on a zoom level. + // Returns true if any paint properties have active transitions. + virtual bool evaluate(const style::PropertyEvaluationParameters&) = 0; + + // Check whether this layer is of the given subtype. + template <class T> + bool is() const; + + // Dynamically cast this layer to the given subtype. + template <class T> + T* as() { + return is<T>() ? reinterpret_cast<T*>(this) : nullptr; + } + + template <class T> + const T* as() const { + return is<T>() ? reinterpret_cast<const T*>(this) : nullptr; + } + + const std::string& getID() const; + + // Checks whether this layer needs to be rendered in the given render pass. + bool hasRenderPass(RenderPass) const; + + // Checks whether this layer can be rendered. + bool needsRendering(float zoom) const; + + // Check wether the given geometry intersects + // with the feature + virtual bool queryIntersectsFeature( + const GeometryCoordinates&, + const GeometryTileFeature&, + const float, + const float, + const float) const { return false; }; + + virtual std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const RenderLayer*>&) const = 0; + + // Private implementation + const style::Layer::Impl& baseImpl; + + friend std::string layoutKey(const RenderLayer&); +protected: + + // Stores what render passes this layer is currently enabled for. This depends on the + // evaluated StyleProperties object and is updated accordingly. + RenderPass passes = RenderPass::None; +}; + +} // namespace mbgl diff --git a/src/mbgl/renderer/render_line_layer.cpp b/src/mbgl/renderer/render_line_layer.cpp new file mode 100644 index 0000000000..551d40bef5 --- /dev/null +++ b/src/mbgl/renderer/render_line_layer.cpp @@ -0,0 +1,114 @@ +#include <mbgl/renderer/render_line_layer.hpp> +#include <mbgl/renderer/line_bucket.hpp> +#include <mbgl/style/layers/line_layer_impl.hpp> +#include <mbgl/geometry/feature_index.hpp> +#include <mbgl/util/math.hpp> +#include <mbgl/util/intersection_tests.hpp> + +namespace mbgl { + +RenderLineLayer::RenderLineLayer(const style::LineLayer::Impl& _impl) + : RenderLayer(style::LayerType::Line, _impl), + impl(&_impl) { +} + +std::unique_ptr<RenderLayer> RenderLineLayer::clone() const { + return std::make_unique<RenderLineLayer>(*this); +} + +std::unique_ptr<Bucket> RenderLineLayer::createBucket(const BucketParameters& parameters, const std::vector<const RenderLayer*>& layers) const { + return std::make_unique<LineBucket>(parameters, layers, impl->layout); +} + +void RenderLineLayer::cascade(const style::CascadeParameters& parameters) { + unevaluated = impl->cascading.cascade(parameters, std::move(unevaluated)); +} + +bool RenderLineLayer::evaluate(const style::PropertyEvaluationParameters& parameters) { + // for scaling dasharrays + auto dashArrayParams = parameters; + dashArrayParams.z = std::floor(dashArrayParams.z); + dashLineWidth = unevaluated.evaluate<style::LineWidth>(dashArrayParams); + + evaluated = unevaluated.evaluate(parameters); + + passes = (evaluated.get<style::LineOpacity>().constantOr(1.0) > 0 + && evaluated.get<style::LineColor>().constantOr(Color::black()).a > 0 + && evaluated.get<style::LineWidth>() > 0) + ? RenderPass::Translucent : RenderPass::None; + + return unevaluated.hasTransition(); +} +optional<GeometryCollection> offsetLine(const GeometryCollection& rings, const double offset) { + if (offset == 0) return {}; + + GeometryCollection newRings; + Point<double> zero(0, 0); + for (const auto& ring : rings) { + newRings.emplace_back(); + auto& newRing = newRings.back(); + + for (auto i = ring.begin(); i != ring.end(); i++) { + auto& p = *i; + + Point<double> aToB = i == ring.begin() ? + zero : + util::perp(util::unit(convertPoint<double>(p - *(i - 1)))); + Point<double> bToC = i + 1 == ring.end() ? + zero : + util::perp(util::unit(convertPoint<double>(*(i + 1) - p))); + Point<double> extrude = util::unit(aToB + bToC); + + const double cosHalfAngle = extrude.x * bToC.x + extrude.y * bToC.y; + extrude *= (1.0 / cosHalfAngle); + + newRing.push_back(convertPoint<int16_t>(extrude * offset) + p); + } + } + + return newRings; +} + +bool RenderLineLayer::queryIntersectsFeature( + const GeometryCoordinates& queryGeometry, + const GeometryTileFeature& feature, + const float zoom, + const float bearing, + const float pixelsToTileUnits) const { + + // Translate query geometry + auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry( + queryGeometry, + evaluated.get<style::LineTranslate>(), + evaluated.get<style::LineTranslateAnchor>(), + bearing, + pixelsToTileUnits); + + // Evaluate function + auto offset = evaluated.get<style::LineOffset>() + .evaluate(feature, zoom, style::LineOffset::defaultValue()) * pixelsToTileUnits; + + // Apply offset to geometry + auto offsetGeometry = offsetLine(feature.getGeometries(), offset); + + // Test intersection + const float halfWidth = getLineWidth(feature, zoom) / 2.0 * pixelsToTileUnits; + return util::polygonIntersectsBufferedMultiLine( + translatedQueryGeometry.value_or(queryGeometry), + offsetGeometry.value_or(feature.getGeometries()), + halfWidth); +} + +float RenderLineLayer::getLineWidth(const GeometryTileFeature& feature, const float zoom) const { + float lineWidth = evaluated.get<style::LineWidth>(); + float gapWidth = evaluated.get<style::LineGapWidth>() + .evaluate(feature, zoom, style::LineGapWidth::defaultValue()); + if (gapWidth) { + return gapWidth + 2 * lineWidth; + } else { + return lineWidth; + } +} + + +} // namespace mbgl diff --git a/src/mbgl/renderer/render_line_layer.hpp b/src/mbgl/renderer/render_line_layer.hpp new file mode 100644 index 0000000000..0bde6f9a86 --- /dev/null +++ b/src/mbgl/renderer/render_line_layer.hpp @@ -0,0 +1,48 @@ +#pragma once + +#include <mbgl/renderer/render_layer.hpp> +#include <mbgl/style/layers/line_layer.hpp> +#include <mbgl/style/layers/line_layer_properties.hpp> + +namespace mbgl { + +class RenderLineLayer: public RenderLayer { +public: + + RenderLineLayer(const style::LineLayer::Impl&); + ~RenderLineLayer() final = default; + + std::unique_ptr<RenderLayer> clone() const override; + + void cascade(const style::CascadeParameters&) override; + bool evaluate(const style::PropertyEvaluationParameters&) override; + + bool queryIntersectsFeature( + const GeometryCoordinates&, + const GeometryTileFeature&, + const float, + const float, + const float) const override; + + std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const RenderLayer*>&) const override; + + // Paint properties + style::LinePaintProperties::Unevaluated unevaluated; + style::LinePaintProperties::Evaluated evaluated; + + const style::LineLayer::Impl* const impl; + + // Special case + float dashLineWidth = 1; + +private: + float getLineWidth(const GeometryTileFeature&, const float) const; + +}; + +template <> +inline bool RenderLayer::is<RenderLineLayer>() const { + return type == style::LayerType::Line; +} + +} // namespace mbgl diff --git a/src/mbgl/renderer/render_raster_layer.cpp b/src/mbgl/renderer/render_raster_layer.cpp new file mode 100644 index 0000000000..f877a02398 --- /dev/null +++ b/src/mbgl/renderer/render_raster_layer.cpp @@ -0,0 +1,33 @@ +#include <mbgl/renderer/render_raster_layer.hpp> +#include <mbgl/renderer/bucket.hpp> +#include <mbgl/style/layers/raster_layer_impl.hpp> + +namespace mbgl { + +RenderRasterLayer::RenderRasterLayer(const style::RasterLayer::Impl& _impl) + : RenderLayer(style::LayerType::Raster, _impl), + impl(&_impl) { +} + +std::unique_ptr<RenderLayer> RenderRasterLayer::clone() const { + return std::make_unique<RenderRasterLayer>(*this); +} + +std::unique_ptr<Bucket> RenderRasterLayer::createBucket(const BucketParameters&, const std::vector<const RenderLayer*>&) const { + assert(false); + return nullptr; +} + +void RenderRasterLayer::cascade(const style::CascadeParameters& parameters) { + unevaluated = impl->cascading.cascade(parameters, std::move(unevaluated)); +} + +bool RenderRasterLayer::evaluate(const style::PropertyEvaluationParameters& parameters) { + evaluated = unevaluated.evaluate(parameters); + + passes = evaluated.get<style::RasterOpacity>() > 0 ? RenderPass::Translucent : RenderPass::None; + + return unevaluated.hasTransition(); +} + +} // namespace mbgl diff --git a/src/mbgl/renderer/render_raster_layer.hpp b/src/mbgl/renderer/render_raster_layer.hpp new file mode 100644 index 0000000000..1fd0fe7c47 --- /dev/null +++ b/src/mbgl/renderer/render_raster_layer.hpp @@ -0,0 +1,34 @@ +#pragma once + +#include <mbgl/renderer/render_layer.hpp> +#include <mbgl/style/layers/raster_layer.hpp> +#include <mbgl/style/layers/raster_layer_properties.hpp> + +namespace mbgl { + +class RenderRasterLayer: public RenderLayer { +public: + + RenderRasterLayer(const style::RasterLayer::Impl&); + ~RenderRasterLayer() final = default; + + std::unique_ptr<RenderLayer> clone() const override; + + void cascade(const style::CascadeParameters&) override; + bool evaluate(const style::PropertyEvaluationParameters&) override; + + std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const RenderLayer*>&) const override; + + // Paint properties + style::RasterPaintProperties::Unevaluated unevaluated; + style::RasterPaintProperties::Evaluated evaluated; + + const style::RasterLayer::Impl* const impl; +}; + +template <> +inline bool RenderLayer::is<RenderRasterLayer>() const { + return type == style::LayerType::Raster; +} + +} // namespace mbgl diff --git a/src/mbgl/renderer/render_symbol_layer.cpp b/src/mbgl/renderer/render_symbol_layer.cpp new file mode 100644 index 0000000000..90cc0a7615 --- /dev/null +++ b/src/mbgl/renderer/render_symbol_layer.cpp @@ -0,0 +1,113 @@ +#include <mbgl/renderer/render_symbol_layer.hpp> +#include <mbgl/layout/symbol_layout.hpp> +#include <mbgl/renderer/bucket.hpp> +#include <mbgl/renderer/bucket_parameters.hpp> +#include <mbgl/style/layers/symbol_layer_impl.hpp> +#include <mbgl/style/property_evaluation_parameters.hpp> +#include <mbgl/tile/geometry_tile_data.hpp> + +namespace mbgl { + +RenderSymbolLayer::RenderSymbolLayer(const style::SymbolLayer::Impl& _impl) + : RenderLayer(style::LayerType::Symbol, _impl), + impl(&_impl) { +} + +std::unique_ptr<RenderLayer> RenderSymbolLayer::clone() const { + return std::make_unique<RenderSymbolLayer>(*this); +} + +std::unique_ptr<Bucket> RenderSymbolLayer::createBucket(const BucketParameters&, const std::vector<const RenderLayer*>&) const { + assert(false); // Should be calling createLayout() instead. + return nullptr; +} + +std::unique_ptr<SymbolLayout> RenderSymbolLayer::createLayout(const BucketParameters& parameters, + const std::vector<const RenderLayer*>& group, + const GeometryTileLayer& layer, + GlyphDependencies& glyphDependencies, + IconDependencyMap& iconDependencyMap) const { + return std::make_unique<SymbolLayout>(parameters, + group, + layer, + iconDependencyMap[impl->spriteAtlas], + (uintptr_t) impl->spriteAtlas, + glyphDependencies); +} + +void RenderSymbolLayer::cascade(const style::CascadeParameters& parameters) { + unevaluated = impl->cascading.cascade(parameters, std::move(unevaluated)); +} + +bool RenderSymbolLayer::evaluate(const style::PropertyEvaluationParameters& parameters) { + evaluated = unevaluated.evaluate(parameters); + + auto hasIconOpacity = evaluated.get<style::IconColor>().constantOr(Color::black()).a > 0 || + evaluated.get<style::IconHaloColor>().constantOr(Color::black()).a > 0; + auto hasTextOpacity = evaluated.get<style::TextColor>().constantOr(Color::black()).a > 0 || + evaluated.get<style::TextHaloColor>().constantOr(Color::black()).a > 0; + + passes = ((evaluated.get<style::IconOpacity>().constantOr(1) > 0 && hasIconOpacity && iconSize > 0) + || (evaluated.get<style::TextOpacity>().constantOr(1) > 0 && hasTextOpacity && textSize > 0)) + ? RenderPass::Translucent : RenderPass::None; + + return unevaluated.hasTransition(); +} + + +style::IconPaintProperties::Evaluated RenderSymbolLayer::iconPaintProperties() const { + return style::IconPaintProperties::Evaluated { + evaluated.get<style::IconOpacity>(), + evaluated.get<style::IconColor>(), + evaluated.get<style::IconHaloColor>(), + evaluated.get<style::IconHaloWidth>(), + evaluated.get<style::IconHaloBlur>(), + evaluated.get<style::IconTranslate>(), + evaluated.get<style::IconTranslateAnchor>() + }; +} + +style::TextPaintProperties::Evaluated RenderSymbolLayer::textPaintProperties() const { + return style::TextPaintProperties::Evaluated { + evaluated.get<style::TextOpacity>(), + evaluated.get<style::TextColor>(), + evaluated.get<style::TextHaloColor>(), + evaluated.get<style::TextHaloWidth>(), + evaluated.get<style::TextHaloBlur>(), + evaluated.get<style::TextTranslate>(), + evaluated.get<style::TextTranslateAnchor>() + }; +} + + +style::SymbolPropertyValues RenderSymbolLayer::iconPropertyValues(const style::SymbolLayoutProperties::PossiblyEvaluated& layout_) const { + return style::SymbolPropertyValues { + layout_.get<style::IconRotationAlignment>(), // icon-pitch-alignment is not yet implemented; inherit the rotation alignment + layout_.get<style::IconRotationAlignment>(), + layout_.get<style::IconSize>(), + evaluated.get<style::IconTranslate>(), + evaluated.get<style::IconTranslateAnchor>(), + iconSize, + 1.0f, + evaluated.get<style::IconHaloColor>().constantOr(Color::black()).a > 0 && + evaluated.get<style::IconHaloWidth>().constantOr(1), + evaluated.get<style::IconColor>().constantOr(Color::black()).a > 0 + }; +} + +style::SymbolPropertyValues RenderSymbolLayer::textPropertyValues(const style::SymbolLayoutProperties::PossiblyEvaluated& layout_) const { + return style::SymbolPropertyValues { + layout_.get<style::TextPitchAlignment>(), + layout_.get<style::TextRotationAlignment>(), + layout_.get<style::TextSize>(), + evaluated.get<style::TextTranslate>(), + evaluated.get<style::TextTranslateAnchor>(), + textSize, + 24.0f, + evaluated.get<style::TextHaloColor>().constantOr(Color::black()).a > 0 && + evaluated.get<style::TextHaloWidth>().constantOr(1), + evaluated.get<style::TextColor>().constantOr(Color::black()).a > 0 + }; +} + +} // namespace mbgl diff --git a/src/mbgl/renderer/render_symbol_layer.hpp b/src/mbgl/renderer/render_symbol_layer.hpp new file mode 100644 index 0000000000..dbe7c4ea83 --- /dev/null +++ b/src/mbgl/renderer/render_symbol_layer.hpp @@ -0,0 +1,97 @@ +#pragma once + +#include <mbgl/text/glyph.hpp> +#include <mbgl/renderer/render_layer.hpp> +#include <mbgl/sprite/sprite_atlas.hpp> +#include <mbgl/style/layers/symbol_layer.hpp> +#include <mbgl/style/layers/symbol_layer_properties.hpp> + +namespace mbgl { + +namespace style { + +// {icon,text}-specific paint-property packs for use in the symbol Programs. +// Since each program deals either with icons or text, using a smaller property set +// lets us avoid unnecessarily binding attributes for properties the program wouldn't use. +class IconPaintProperties : public PaintProperties< + IconOpacity, + IconColor, + IconHaloColor, + IconHaloWidth, + IconHaloBlur, + IconTranslate, + IconTranslateAnchor +> {}; + +class TextPaintProperties : public PaintProperties< + TextOpacity, + TextColor, + TextHaloColor, + TextHaloWidth, + TextHaloBlur, + TextTranslate, + TextTranslateAnchor +> {}; + +// Repackaging evaluated values from SymbolLayoutProperties + SymbolPaintProperties +// for genericity over icons vs. text. +class SymbolPropertyValues { +public: + // Layout + AlignmentType pitchAlignment; + AlignmentType rotationAlignment; + PossiblyEvaluatedPropertyValue<float> layoutSize; + + // Paint + std::array<float, 2> translate; + TranslateAnchorType translateAnchor; + float paintSize; + + float sdfScale; // Constant (1.0 or 24.0) + + bool hasHalo; + bool hasFill; +}; + +} // namespace style + +class BucketParameters; +class SymbolLayout; +class GeometryTileLayer; + +class RenderSymbolLayer: public RenderLayer { +public: + RenderSymbolLayer(const style::SymbolLayer::Impl&); + ~RenderSymbolLayer() final = default; + + std::unique_ptr<RenderLayer> clone() const override; + + void cascade(const style::CascadeParameters&) override; + bool evaluate(const style::PropertyEvaluationParameters&) override; + + style::IconPaintProperties::Evaluated iconPaintProperties() const; + style::TextPaintProperties::Evaluated textPaintProperties() const; + + style::SymbolPropertyValues iconPropertyValues(const style::SymbolLayoutProperties::PossiblyEvaluated&) const; + style::SymbolPropertyValues textPropertyValues(const style::SymbolLayoutProperties::PossiblyEvaluated&) const; + + std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const RenderLayer*>&) const override; + std::unique_ptr<SymbolLayout> createLayout(const BucketParameters&, const std::vector<const RenderLayer*>&, + const GeometryTileLayer&, GlyphDependencies&, IconDependencyMap&) const; + + // Paint properties + style::SymbolPaintProperties::Unevaluated unevaluated; + style::SymbolPaintProperties::Evaluated evaluated; + + float iconSize = 1.0f; + float textSize = 16.0f; + + const style::SymbolLayer::Impl* const impl; +}; + +template <> +inline bool RenderLayer::is<RenderSymbolLayer>() const { + return type == style::LayerType::Symbol; +} + +} // namespace mbgl diff --git a/src/mbgl/renderer/symbol_bucket.cpp b/src/mbgl/renderer/symbol_bucket.cpp index 77a9a75ef1..9b016c16f9 100644 --- a/src/mbgl/renderer/symbol_bucket.cpp +++ b/src/mbgl/renderer/symbol_bucket.cpp @@ -1,7 +1,7 @@ #include <mbgl/renderer/symbol_bucket.hpp> #include <mbgl/renderer/painter.hpp> -#include <mbgl/style/bucket_parameters.hpp> -#include <mbgl/style/layers/symbol_layer.hpp> +#include <mbgl/renderer/render_symbol_layer.hpp> +#include <mbgl/renderer/bucket_parameters.hpp> #include <mbgl/style/layers/symbol_layer_impl.hpp> namespace mbgl { @@ -61,9 +61,9 @@ void SymbolBucket::upload(gl::Context& context) { void SymbolBucket::render(Painter& painter, PaintParameters& parameters, - const Layer& layer, + const RenderLayer& layer, const RenderTile& tile) { - painter.renderSymbol(parameters, *this, *layer.as<SymbolLayer>(), tile); + painter.renderSymbol(parameters, *this, *layer.as<RenderSymbolLayer>(), tile); } bool SymbolBucket::hasData() const { diff --git a/src/mbgl/renderer/symbol_bucket.hpp b/src/mbgl/renderer/symbol_bucket.hpp index 659d7a3788..e00de03fd2 100644 --- a/src/mbgl/renderer/symbol_bucket.hpp +++ b/src/mbgl/renderer/symbol_bucket.hpp @@ -26,7 +26,7 @@ public: bool iconsNeedLinear); void upload(gl::Context&) override; - void render(Painter&, PaintParameters&, const style::Layer&, const RenderTile&) override; + void render(Painter&, PaintParameters&, const RenderLayer&, const RenderTile&) override; bool hasData() const override; bool hasTextData() const; bool hasIconData() const; diff --git a/src/mbgl/style/bucket_parameters.cpp b/src/mbgl/style/bucket_parameters.cpp deleted file mode 100644 index 2b02ac4a4a..0000000000 --- a/src/mbgl/style/bucket_parameters.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include <mbgl/style/bucket_parameters.hpp> - -namespace mbgl { -namespace style { - -} // namespace style -} // namespace mbgl diff --git a/src/mbgl/style/group_by_layout.cpp b/src/mbgl/style/group_by_layout.cpp deleted file mode 100644 index b15fe1ca0d..0000000000 --- a/src/mbgl/style/group_by_layout.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include <mbgl/style/group_by_layout.hpp> -#include <mbgl/style/layer.hpp> -#include <mbgl/style/layer_impl.hpp> -#include <mbgl/style/conversion/stringify.hpp> -#include <mbgl/util/rapidjson.hpp> - -#include <rapidjson/writer.h> -#include <rapidjson/stringbuffer.h> - -#include <unordered_map> - -namespace mbgl { -namespace style { - -std::string layoutKey(const Layer& layer) { - using namespace conversion; - - rapidjson::StringBuffer s; - rapidjson::Writer<rapidjson::StringBuffer> writer(s); - - writer.StartArray(); - writer.Uint(static_cast<uint32_t>(layer.type)); - writer.String(layer.baseImpl->source); - writer.String(layer.baseImpl->sourceLayer); - writer.Double(layer.baseImpl->minZoom); - writer.Double(layer.baseImpl->maxZoom); - writer.Uint(static_cast<uint32_t>(layer.baseImpl->visibility)); - stringify(writer, layer.baseImpl->filter); - layer.baseImpl->stringifyLayout(writer); - writer.EndArray(); - - return s.GetString(); -} - -std::vector<std::vector<const Layer*>> groupByLayout(const std::vector<std::unique_ptr<Layer>>& layers) { - std::unordered_map<std::string, std::vector<const Layer*>> map; - for (auto& layer : layers) { - map[layoutKey(*layer)].push_back(layer.get()); - } - - std::vector<std::vector<const Layer*>> result; - for (auto& pair : map) { - result.push_back(pair.second); - } - - return result; -} - -} // namespace style -} // namespace mbgl diff --git a/src/mbgl/style/group_by_layout.hpp b/src/mbgl/style/group_by_layout.hpp deleted file mode 100644 index 3a89ac95f3..0000000000 --- a/src/mbgl/style/group_by_layout.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include <vector> -#include <memory> - -namespace mbgl { -namespace style { - -class Layer; - -std::vector<std::vector<const Layer*>> groupByLayout(const std::vector<std::unique_ptr<Layer>>&); - -} // namespace style -} // namespace mbgl diff --git a/src/mbgl/style/layer.cpp b/src/mbgl/style/layer.cpp index a78f8c29bc..e2eba0e2e0 100644 --- a/src/mbgl/style/layer.cpp +++ b/src/mbgl/style/layer.cpp @@ -1,10 +1,11 @@ #include <mbgl/style/layer.hpp> #include <mbgl/style/layer_impl.hpp> +#include <mbgl/style/layer_type.hpp> namespace mbgl { namespace style { -Layer::Layer(Type type_, std::unique_ptr<Impl> baseImpl_) +Layer::Layer(LayerType type_, std::unique_ptr<Impl> baseImpl_) : type(type_), baseImpl(std::move(baseImpl_)) { } diff --git a/src/mbgl/style/layer_impl.cpp b/src/mbgl/style/layer_impl.cpp index 5840318724..44b1a8dd62 100644 --- a/src/mbgl/style/layer_impl.cpp +++ b/src/mbgl/style/layer_impl.cpp @@ -11,17 +11,6 @@ std::unique_ptr<Layer> Layer::Impl::copy(const std::string& id_, return result; } -bool Layer::Impl::hasRenderPass(RenderPass pass) const { - return bool(passes & pass); -} - -bool Layer::Impl::needsRendering(float zoom) const { - return passes != RenderPass::None - && visibility != VisibilityType::None - && minZoom <= zoom - && maxZoom >= zoom; -} - void Layer::Impl::setObserver(LayerObserver* observer_) { observer = observer_; } diff --git a/src/mbgl/style/layer_impl.hpp b/src/mbgl/style/layer_impl.hpp index 5179192c94..6aa8fccaf0 100644 --- a/src/mbgl/style/layer_impl.hpp +++ b/src/mbgl/style/layer_impl.hpp @@ -4,9 +4,7 @@ #include <mbgl/style/types.hpp> #include <mbgl/style/filter.hpp> #include <mbgl/style/layer_observer.hpp> -#include <mbgl/renderer/render_pass.hpp> #include <mbgl/util/noncopyable.hpp> -#include <mbgl/tile/geometry_tile_data.hpp> #include <rapidjson/writer.h> #include <rapidjson/stringbuffer.h> @@ -17,14 +15,10 @@ namespace mbgl { -class Bucket; +class RenderLayer; namespace style { -class CascadeParameters; -class PropertyEvaluationParameters; -class BucketParameters; - /** * `Layer::Impl` contains the internal implementation of `Layer`: the details that need to be accessible to other parts * of the code, but hidden from the public API. Like `Layer`, it is an abstract base class, with derived classes for @@ -54,27 +48,7 @@ public: // Utility function for automatic layer grouping. virtual void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const = 0; - // Partially evaluate paint properties based on a set of classes. - virtual void cascade(const CascadeParameters&) = 0; - - // Fully evaluate cascaded paint properties based on a zoom level. - // Returns true if any paint properties have active transitions. - virtual bool evaluate(const PropertyEvaluationParameters&) = 0; - - virtual std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const Layer*>&) const = 0; - - // Checks whether this layer needs to be rendered in the given render pass. - bool hasRenderPass(RenderPass) const; - - // Checks whether this layer can be rendered. - bool needsRendering(float zoom) const; - - virtual bool queryIntersectsFeature( - const GeometryCoordinates&, - const GeometryTileFeature&, - const float, - const float, - const float) const { return false; }; + virtual std::unique_ptr<RenderLayer> createRenderLayer() const = 0; void setObserver(LayerObserver*); @@ -94,10 +68,6 @@ protected: Impl() = default; Impl(const Impl&) = default; Impl& operator=(const Impl&) = delete; - - // Stores what render passes this layer is currently enabled for. This depends on the - // evaluated StyleProperties object and is updated accordingly. - RenderPass passes = RenderPass::None; }; } // namespace style diff --git a/src/mbgl/style/layers/background_layer.cpp b/src/mbgl/style/layers/background_layer.cpp index e2a517b9f4..b4ffea138b 100644 --- a/src/mbgl/style/layers/background_layer.cpp +++ b/src/mbgl/style/layers/background_layer.cpp @@ -8,13 +8,13 @@ namespace mbgl { namespace style { BackgroundLayer::BackgroundLayer(const std::string& layerID) - : Layer(Type::Background, std::make_unique<Impl>()) + : Layer(LayerType::Background, std::make_unique<Impl>()) , impl(static_cast<Impl*>(baseImpl.get())) { impl->id = layerID; } BackgroundLayer::BackgroundLayer(const Impl& other) - : Layer(Type::Background, std::make_unique<Impl>(other)) + : Layer(LayerType::Background, std::make_unique<Impl>(other)) , impl(static_cast<Impl*>(baseImpl.get())) { } @@ -27,7 +27,7 @@ std::unique_ptr<Layer> BackgroundLayer::Impl::clone() const { std::unique_ptr<Layer> BackgroundLayer::Impl::cloneRef(const std::string& id_) const { auto result = std::make_unique<BackgroundLayer>(*this); result->impl->id = id_; - result->impl->paint = BackgroundPaintProperties(); + result->impl->cascading = BackgroundPaintProperties::Cascading(); return std::move(result); } @@ -45,22 +45,22 @@ PropertyValue<Color> BackgroundLayer::getDefaultBackgroundColor() { } PropertyValue<Color> BackgroundLayer::getBackgroundColor(const optional<std::string>& klass) const { - return impl->paint.get<BackgroundColor>(klass); + return impl->cascading.template get<BackgroundColor>().get(klass); } void BackgroundLayer::setBackgroundColor(PropertyValue<Color> value, const optional<std::string>& klass) { if (value == getBackgroundColor(klass)) return; - impl->paint.set<BackgroundColor>(value, klass); + impl->cascading.template get<BackgroundColor>().set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } void BackgroundLayer::setBackgroundColorTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<BackgroundColor>(value, klass); + impl->cascading.template get<BackgroundColor>().setTransition(value, klass); } TransitionOptions BackgroundLayer::getBackgroundColorTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<BackgroundColor>(klass); + return impl->cascading.template get<BackgroundColor>().getTransition(klass); } PropertyValue<std::string> BackgroundLayer::getDefaultBackgroundPattern() { @@ -68,22 +68,22 @@ PropertyValue<std::string> BackgroundLayer::getDefaultBackgroundPattern() { } PropertyValue<std::string> BackgroundLayer::getBackgroundPattern(const optional<std::string>& klass) const { - return impl->paint.get<BackgroundPattern>(klass); + return impl->cascading.template get<BackgroundPattern>().get(klass); } void BackgroundLayer::setBackgroundPattern(PropertyValue<std::string> value, const optional<std::string>& klass) { if (value == getBackgroundPattern(klass)) return; - impl->paint.set<BackgroundPattern>(value, klass); + impl->cascading.template get<BackgroundPattern>().set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } void BackgroundLayer::setBackgroundPatternTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<BackgroundPattern>(value, klass); + impl->cascading.template get<BackgroundPattern>().setTransition(value, klass); } TransitionOptions BackgroundLayer::getBackgroundPatternTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<BackgroundPattern>(klass); + return impl->cascading.template get<BackgroundPattern>().getTransition(klass); } PropertyValue<float> BackgroundLayer::getDefaultBackgroundOpacity() { @@ -91,22 +91,22 @@ PropertyValue<float> BackgroundLayer::getDefaultBackgroundOpacity() { } PropertyValue<float> BackgroundLayer::getBackgroundOpacity(const optional<std::string>& klass) const { - return impl->paint.get<BackgroundOpacity>(klass); + return impl->cascading.template get<BackgroundOpacity>().get(klass); } void BackgroundLayer::setBackgroundOpacity(PropertyValue<float> value, const optional<std::string>& klass) { if (value == getBackgroundOpacity(klass)) return; - impl->paint.set<BackgroundOpacity>(value, klass); + impl->cascading.template get<BackgroundOpacity>().set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } void BackgroundLayer::setBackgroundOpacityTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<BackgroundOpacity>(value, klass); + impl->cascading.template get<BackgroundOpacity>().setTransition(value, klass); } TransitionOptions BackgroundLayer::getBackgroundOpacityTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<BackgroundOpacity>(klass); + return impl->cascading.template get<BackgroundOpacity>().getTransition(klass); } } // namespace style diff --git a/src/mbgl/style/layers/background_layer_impl.cpp b/src/mbgl/style/layers/background_layer_impl.cpp index f25ba9cfb4..6c4a4c26d9 100644 --- a/src/mbgl/style/layers/background_layer_impl.cpp +++ b/src/mbgl/style/layers/background_layer_impl.cpp @@ -1,24 +1,11 @@ #include <mbgl/style/layers/background_layer_impl.hpp> -#include <mbgl/renderer/bucket.hpp> +#include <mbgl/renderer/render_background_layer.hpp> namespace mbgl { namespace style { -void BackgroundLayer::Impl::cascade(const CascadeParameters& parameters) { - paint.cascade(parameters); -} - -bool BackgroundLayer::Impl::evaluate(const PropertyEvaluationParameters& parameters) { - paint.evaluate(parameters); - - passes = paint.evaluated.get<BackgroundOpacity>() > 0 ? RenderPass::Translucent : RenderPass::None; - - return paint.hasTransition(); -} - -std::unique_ptr<Bucket> BackgroundLayer::Impl::createBucket(const BucketParameters&, const std::vector<const Layer*>&) const { - assert(false); - return nullptr; +std::unique_ptr<RenderLayer> BackgroundLayer::Impl::createRenderLayer() const { + return std::make_unique<RenderBackgroundLayer>(*this); } } // namespace style diff --git a/src/mbgl/style/layers/background_layer_impl.hpp b/src/mbgl/style/layers/background_layer_impl.hpp index 02a8c423d6..85152da4ec 100644 --- a/src/mbgl/style/layers/background_layer_impl.hpp +++ b/src/mbgl/style/layers/background_layer_impl.hpp @@ -13,12 +13,9 @@ public: std::unique_ptr<Layer> cloneRef(const std::string& id) const override; void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override; - void cascade(const CascadeParameters&) override; - bool evaluate(const PropertyEvaluationParameters&) override; + std::unique_ptr<RenderLayer> createRenderLayer() const override; - std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const Layer*>&) const override; - - BackgroundPaintProperties paint; + BackgroundPaintProperties::Cascading cascading; }; } // namespace style diff --git a/src/mbgl/style/layers/circle_layer.cpp b/src/mbgl/style/layers/circle_layer.cpp index a628d7a417..8b3431a9a1 100644 --- a/src/mbgl/style/layers/circle_layer.cpp +++ b/src/mbgl/style/layers/circle_layer.cpp @@ -8,14 +8,14 @@ namespace mbgl { namespace style { CircleLayer::CircleLayer(const std::string& layerID, const std::string& sourceID) - : Layer(Type::Circle, std::make_unique<Impl>()) + : Layer(LayerType::Circle, std::make_unique<Impl>()) , impl(static_cast<Impl*>(baseImpl.get())) { impl->id = layerID; impl->source = sourceID; } CircleLayer::CircleLayer(const Impl& other) - : Layer(Type::Circle, std::make_unique<Impl>(other)) + : Layer(LayerType::Circle, std::make_unique<Impl>(other)) , impl(static_cast<Impl*>(baseImpl.get())) { } @@ -28,7 +28,7 @@ std::unique_ptr<Layer> CircleLayer::Impl::clone() const { std::unique_ptr<Layer> CircleLayer::Impl::cloneRef(const std::string& id_) const { auto result = std::make_unique<CircleLayer>(*this); result->impl->id = id_; - result->impl->paint = CirclePaintProperties(); + result->impl->cascading = CirclePaintProperties::Cascading(); return std::move(result); } @@ -70,13 +70,13 @@ DataDrivenPropertyValue<float> CircleLayer::getDefaultCircleRadius() { } DataDrivenPropertyValue<float> CircleLayer::getCircleRadius(const optional<std::string>& klass) const { - return impl->paint.get<CircleRadius>(klass); + return impl->cascading.template get<CircleRadius>().get(klass); } void CircleLayer::setCircleRadius(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) { if (value == getCircleRadius(klass)) return; - impl->paint.set<CircleRadius>(value, klass); + impl->cascading.template get<CircleRadius>().set(value, klass); if (value.isDataDriven()) { impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); } else { @@ -85,11 +85,11 @@ void CircleLayer::setCircleRadius(DataDrivenPropertyValue<float> value, const op } void CircleLayer::setCircleRadiusTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<CircleRadius>(value, klass); + impl->cascading.template get<CircleRadius>().setTransition(value, klass); } TransitionOptions CircleLayer::getCircleRadiusTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<CircleRadius>(klass); + return impl->cascading.template get<CircleRadius>().getTransition(klass); } DataDrivenPropertyValue<Color> CircleLayer::getDefaultCircleColor() { @@ -97,13 +97,13 @@ DataDrivenPropertyValue<Color> CircleLayer::getDefaultCircleColor() { } DataDrivenPropertyValue<Color> CircleLayer::getCircleColor(const optional<std::string>& klass) const { - return impl->paint.get<CircleColor>(klass); + return impl->cascading.template get<CircleColor>().get(klass); } void CircleLayer::setCircleColor(DataDrivenPropertyValue<Color> value, const optional<std::string>& klass) { if (value == getCircleColor(klass)) return; - impl->paint.set<CircleColor>(value, klass); + impl->cascading.template get<CircleColor>().set(value, klass); if (value.isDataDriven()) { impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); } else { @@ -112,11 +112,11 @@ void CircleLayer::setCircleColor(DataDrivenPropertyValue<Color> value, const opt } void CircleLayer::setCircleColorTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<CircleColor>(value, klass); + impl->cascading.template get<CircleColor>().setTransition(value, klass); } TransitionOptions CircleLayer::getCircleColorTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<CircleColor>(klass); + return impl->cascading.template get<CircleColor>().getTransition(klass); } DataDrivenPropertyValue<float> CircleLayer::getDefaultCircleBlur() { @@ -124,13 +124,13 @@ DataDrivenPropertyValue<float> CircleLayer::getDefaultCircleBlur() { } DataDrivenPropertyValue<float> CircleLayer::getCircleBlur(const optional<std::string>& klass) const { - return impl->paint.get<CircleBlur>(klass); + return impl->cascading.template get<CircleBlur>().get(klass); } void CircleLayer::setCircleBlur(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) { if (value == getCircleBlur(klass)) return; - impl->paint.set<CircleBlur>(value, klass); + impl->cascading.template get<CircleBlur>().set(value, klass); if (value.isDataDriven()) { impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); } else { @@ -139,11 +139,11 @@ void CircleLayer::setCircleBlur(DataDrivenPropertyValue<float> value, const opti } void CircleLayer::setCircleBlurTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<CircleBlur>(value, klass); + impl->cascading.template get<CircleBlur>().setTransition(value, klass); } TransitionOptions CircleLayer::getCircleBlurTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<CircleBlur>(klass); + return impl->cascading.template get<CircleBlur>().getTransition(klass); } DataDrivenPropertyValue<float> CircleLayer::getDefaultCircleOpacity() { @@ -151,13 +151,13 @@ DataDrivenPropertyValue<float> CircleLayer::getDefaultCircleOpacity() { } DataDrivenPropertyValue<float> CircleLayer::getCircleOpacity(const optional<std::string>& klass) const { - return impl->paint.get<CircleOpacity>(klass); + return impl->cascading.template get<CircleOpacity>().get(klass); } void CircleLayer::setCircleOpacity(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) { if (value == getCircleOpacity(klass)) return; - impl->paint.set<CircleOpacity>(value, klass); + impl->cascading.template get<CircleOpacity>().set(value, klass); if (value.isDataDriven()) { impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); } else { @@ -166,11 +166,11 @@ void CircleLayer::setCircleOpacity(DataDrivenPropertyValue<float> value, const o } void CircleLayer::setCircleOpacityTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<CircleOpacity>(value, klass); + impl->cascading.template get<CircleOpacity>().setTransition(value, klass); } TransitionOptions CircleLayer::getCircleOpacityTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<CircleOpacity>(klass); + return impl->cascading.template get<CircleOpacity>().getTransition(klass); } PropertyValue<std::array<float, 2>> CircleLayer::getDefaultCircleTranslate() { @@ -178,22 +178,22 @@ PropertyValue<std::array<float, 2>> CircleLayer::getDefaultCircleTranslate() { } PropertyValue<std::array<float, 2>> CircleLayer::getCircleTranslate(const optional<std::string>& klass) const { - return impl->paint.get<CircleTranslate>(klass); + return impl->cascading.template get<CircleTranslate>().get(klass); } void CircleLayer::setCircleTranslate(PropertyValue<std::array<float, 2>> value, const optional<std::string>& klass) { if (value == getCircleTranslate(klass)) return; - impl->paint.set<CircleTranslate>(value, klass); + impl->cascading.template get<CircleTranslate>().set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } void CircleLayer::setCircleTranslateTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<CircleTranslate>(value, klass); + impl->cascading.template get<CircleTranslate>().setTransition(value, klass); } TransitionOptions CircleLayer::getCircleTranslateTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<CircleTranslate>(klass); + return impl->cascading.template get<CircleTranslate>().getTransition(klass); } PropertyValue<TranslateAnchorType> CircleLayer::getDefaultCircleTranslateAnchor() { @@ -201,22 +201,22 @@ PropertyValue<TranslateAnchorType> CircleLayer::getDefaultCircleTranslateAnchor( } PropertyValue<TranslateAnchorType> CircleLayer::getCircleTranslateAnchor(const optional<std::string>& klass) const { - return impl->paint.get<CircleTranslateAnchor>(klass); + return impl->cascading.template get<CircleTranslateAnchor>().get(klass); } void CircleLayer::setCircleTranslateAnchor(PropertyValue<TranslateAnchorType> value, const optional<std::string>& klass) { if (value == getCircleTranslateAnchor(klass)) return; - impl->paint.set<CircleTranslateAnchor>(value, klass); + impl->cascading.template get<CircleTranslateAnchor>().set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } void CircleLayer::setCircleTranslateAnchorTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<CircleTranslateAnchor>(value, klass); + impl->cascading.template get<CircleTranslateAnchor>().setTransition(value, klass); } TransitionOptions CircleLayer::getCircleTranslateAnchorTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<CircleTranslateAnchor>(klass); + return impl->cascading.template get<CircleTranslateAnchor>().getTransition(klass); } PropertyValue<CirclePitchScaleType> CircleLayer::getDefaultCirclePitchScale() { @@ -224,22 +224,22 @@ PropertyValue<CirclePitchScaleType> CircleLayer::getDefaultCirclePitchScale() { } PropertyValue<CirclePitchScaleType> CircleLayer::getCirclePitchScale(const optional<std::string>& klass) const { - return impl->paint.get<CirclePitchScale>(klass); + return impl->cascading.template get<CirclePitchScale>().get(klass); } void CircleLayer::setCirclePitchScale(PropertyValue<CirclePitchScaleType> value, const optional<std::string>& klass) { if (value == getCirclePitchScale(klass)) return; - impl->paint.set<CirclePitchScale>(value, klass); + impl->cascading.template get<CirclePitchScale>().set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } void CircleLayer::setCirclePitchScaleTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<CirclePitchScale>(value, klass); + impl->cascading.template get<CirclePitchScale>().setTransition(value, klass); } TransitionOptions CircleLayer::getCirclePitchScaleTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<CirclePitchScale>(klass); + return impl->cascading.template get<CirclePitchScale>().getTransition(klass); } DataDrivenPropertyValue<float> CircleLayer::getDefaultCircleStrokeWidth() { @@ -247,13 +247,13 @@ DataDrivenPropertyValue<float> CircleLayer::getDefaultCircleStrokeWidth() { } DataDrivenPropertyValue<float> CircleLayer::getCircleStrokeWidth(const optional<std::string>& klass) const { - return impl->paint.get<CircleStrokeWidth>(klass); + return impl->cascading.template get<CircleStrokeWidth>().get(klass); } void CircleLayer::setCircleStrokeWidth(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) { if (value == getCircleStrokeWidth(klass)) return; - impl->paint.set<CircleStrokeWidth>(value, klass); + impl->cascading.template get<CircleStrokeWidth>().set(value, klass); if (value.isDataDriven()) { impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); } else { @@ -262,11 +262,11 @@ void CircleLayer::setCircleStrokeWidth(DataDrivenPropertyValue<float> value, con } void CircleLayer::setCircleStrokeWidthTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<CircleStrokeWidth>(value, klass); + impl->cascading.template get<CircleStrokeWidth>().setTransition(value, klass); } TransitionOptions CircleLayer::getCircleStrokeWidthTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<CircleStrokeWidth>(klass); + return impl->cascading.template get<CircleStrokeWidth>().getTransition(klass); } DataDrivenPropertyValue<Color> CircleLayer::getDefaultCircleStrokeColor() { @@ -274,13 +274,13 @@ DataDrivenPropertyValue<Color> CircleLayer::getDefaultCircleStrokeColor() { } DataDrivenPropertyValue<Color> CircleLayer::getCircleStrokeColor(const optional<std::string>& klass) const { - return impl->paint.get<CircleStrokeColor>(klass); + return impl->cascading.template get<CircleStrokeColor>().get(klass); } void CircleLayer::setCircleStrokeColor(DataDrivenPropertyValue<Color> value, const optional<std::string>& klass) { if (value == getCircleStrokeColor(klass)) return; - impl->paint.set<CircleStrokeColor>(value, klass); + impl->cascading.template get<CircleStrokeColor>().set(value, klass); if (value.isDataDriven()) { impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); } else { @@ -289,11 +289,11 @@ void CircleLayer::setCircleStrokeColor(DataDrivenPropertyValue<Color> value, con } void CircleLayer::setCircleStrokeColorTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<CircleStrokeColor>(value, klass); + impl->cascading.template get<CircleStrokeColor>().setTransition(value, klass); } TransitionOptions CircleLayer::getCircleStrokeColorTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<CircleStrokeColor>(klass); + return impl->cascading.template get<CircleStrokeColor>().getTransition(klass); } DataDrivenPropertyValue<float> CircleLayer::getDefaultCircleStrokeOpacity() { @@ -301,13 +301,13 @@ DataDrivenPropertyValue<float> CircleLayer::getDefaultCircleStrokeOpacity() { } DataDrivenPropertyValue<float> CircleLayer::getCircleStrokeOpacity(const optional<std::string>& klass) const { - return impl->paint.get<CircleStrokeOpacity>(klass); + return impl->cascading.template get<CircleStrokeOpacity>().get(klass); } void CircleLayer::setCircleStrokeOpacity(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) { if (value == getCircleStrokeOpacity(klass)) return; - impl->paint.set<CircleStrokeOpacity>(value, klass); + impl->cascading.template get<CircleStrokeOpacity>().set(value, klass); if (value.isDataDriven()) { impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); } else { @@ -316,11 +316,11 @@ void CircleLayer::setCircleStrokeOpacity(DataDrivenPropertyValue<float> value, c } void CircleLayer::setCircleStrokeOpacityTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<CircleStrokeOpacity>(value, klass); + impl->cascading.template get<CircleStrokeOpacity>().setTransition(value, klass); } TransitionOptions CircleLayer::getCircleStrokeOpacityTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<CircleStrokeOpacity>(klass); + return impl->cascading.template get<CircleStrokeOpacity>().getTransition(klass); } } // namespace style diff --git a/src/mbgl/style/layers/circle_layer_impl.cpp b/src/mbgl/style/layers/circle_layer_impl.cpp index 2dde632f6e..31b286f273 100644 --- a/src/mbgl/style/layers/circle_layer_impl.cpp +++ b/src/mbgl/style/layers/circle_layer_impl.cpp @@ -1,52 +1,11 @@ #include <mbgl/style/layers/circle_layer_impl.hpp> -#include <mbgl/renderer/circle_bucket.hpp> -#include <mbgl/geometry/feature_index.hpp> -#include <mbgl/util/math.hpp> -#include <mbgl/util/intersection_tests.hpp> +#include <mbgl/renderer/render_circle_layer.hpp> namespace mbgl { namespace style { -void CircleLayer::Impl::cascade(const CascadeParameters& parameters) { - paint.cascade(parameters); -} - -bool CircleLayer::Impl::evaluate(const PropertyEvaluationParameters& parameters) { - paint.evaluate(parameters); - - passes = ((paint.evaluated.get<CircleRadius>().constantOr(1) > 0 || - paint.evaluated.get<CircleStrokeWidth>().constantOr(1) > 0) - && (paint.evaluated.get<CircleColor>().constantOr(Color::black()).a > 0 || - paint.evaluated.get<CircleStrokeColor>().constantOr(Color::black()).a > 0) - && (paint.evaluated.get<CircleOpacity>().constantOr(1) > 0 || - paint.evaluated.get<CircleStrokeOpacity>().constantOr(1) > 0)) - ? RenderPass::Translucent : RenderPass::None; - - return paint.hasTransition(); -} - -std::unique_ptr<Bucket> CircleLayer::Impl::createBucket(const BucketParameters& parameters, const std::vector<const Layer*>& layers) const { - return std::make_unique<CircleBucket>(parameters, layers); -} - -bool CircleLayer::Impl::queryIntersectsFeature( - const GeometryCoordinates& queryGeometry, - const GeometryTileFeature& feature, - const float zoom, - const float bearing, - const float pixelsToTileUnits) const { - - // Translate query geometry - auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry( - queryGeometry, paint.evaluated.get<CircleTranslate>(), paint.evaluated.get<CircleTranslateAnchor>(), bearing, pixelsToTileUnits); - - // Evaluate function - auto circleRadius = paint.evaluated.get<CircleRadius>() - .evaluate(feature, zoom, CircleRadius::defaultValue()) - * pixelsToTileUnits; - - // Test intersection - return util::polygonIntersectsBufferedMultiPoint(translatedQueryGeometry.value_or(queryGeometry), feature.getGeometries(), circleRadius); +std::unique_ptr<RenderLayer> CircleLayer::Impl::createRenderLayer() const { + return std::make_unique<RenderCircleLayer>(*this); } } // namespace style diff --git a/src/mbgl/style/layers/circle_layer_impl.hpp b/src/mbgl/style/layers/circle_layer_impl.hpp index 2e3f37e1f9..886815f0d1 100644 --- a/src/mbgl/style/layers/circle_layer_impl.hpp +++ b/src/mbgl/style/layers/circle_layer_impl.hpp @@ -13,19 +13,9 @@ public: std::unique_ptr<Layer> cloneRef(const std::string& id) const override; void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override; - void cascade(const CascadeParameters&) override; - bool evaluate(const PropertyEvaluationParameters&) override; + std::unique_ptr<RenderLayer> createRenderLayer() const override; - std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const Layer*>&) const override; - - bool queryIntersectsFeature( - const GeometryCoordinates&, - const GeometryTileFeature&, - const float, - const float, - const float) const override; - - CirclePaintProperties paint; + CirclePaintProperties::Cascading cascading; }; } // namespace style diff --git a/src/mbgl/style/layers/custom_layer.cpp b/src/mbgl/style/layers/custom_layer.cpp index 2504f3f15c..cda8a157f0 100644 --- a/src/mbgl/style/layers/custom_layer.cpp +++ b/src/mbgl/style/layers/custom_layer.cpp @@ -1,5 +1,6 @@ #include <mbgl/style/layers/custom_layer.hpp> #include <mbgl/style/layers/custom_layer_impl.hpp> +#include <mbgl/util/logging.hpp> namespace mbgl { namespace style { @@ -9,12 +10,13 @@ CustomLayer::CustomLayer(const std::string& layerID, CustomLayerRenderFunction render, CustomLayerDeinitializeFunction deinit, void* context) - : Layer(Type::Custom, std::make_unique<Impl>(layerID, init, render, deinit, context)) + : Layer(LayerType::Custom, std::make_unique<Impl>(layerID, init, render, deinit, context)) , impl(static_cast<Impl*>(baseImpl.get())) { + Log::Info(Event::General, "New custom layer: %s", layerID.c_str()); } CustomLayer::CustomLayer(const Impl& other) - : Layer(Type::Custom, std::make_unique<Impl>(other)) + : Layer(LayerType::Custom, std::make_unique<Impl>(other)) , impl(static_cast<Impl*>(baseImpl.get())) { } @@ -22,7 +24,7 @@ CustomLayer::~CustomLayer() = default; template <> bool Layer::is<CustomLayer>() const { - return type == Type::Custom; + return type == LayerType::Custom; } } // namespace style diff --git a/src/mbgl/style/layers/custom_layer_impl.cpp b/src/mbgl/style/layers/custom_layer_impl.cpp index 375c9ee27b..1d3e9af8d6 100644 --- a/src/mbgl/style/layers/custom_layer_impl.cpp +++ b/src/mbgl/style/layers/custom_layer_impl.cpp @@ -1,15 +1,20 @@ #include <mbgl/style/layers/custom_layer_impl.hpp> -#include <mbgl/renderer/bucket.hpp> +#include <mbgl/renderer/render_custom_layer.hpp> #include <mbgl/map/transform_state.hpp> - +#include <mbgl/util/logging.hpp> namespace mbgl { namespace style { +std::unique_ptr<RenderLayer> CustomLayer::Impl::createRenderLayer() const { + return std::make_unique<RenderCustomLayer>(*this); +} + CustomLayer::Impl::Impl(const std::string& id_, CustomLayerInitializeFunction initializeFn_, CustomLayerRenderFunction renderFn_, CustomLayerDeinitializeFunction deinitializeFn_, void* context_) { + Log::Info(Event::General, "New custom layer Impl: %s", id_.c_str()); id = id_; initializeFn = initializeFn_; renderFn = renderFn_; @@ -17,8 +22,8 @@ CustomLayer::Impl::Impl(const std::string& id_, context = context_; } -CustomLayer::Impl::Impl(const CustomLayer::Impl& other) - : Layer::Impl(other) { +CustomLayer::Impl::Impl(const CustomLayer::Impl &other) + : Layer::Impl(other) { id = other.id; // Don't copy anything else. } @@ -65,15 +70,5 @@ void CustomLayer::Impl::render(const TransformState& state) const { renderFn(context, parameters); } -bool CustomLayer::Impl::evaluate(const PropertyEvaluationParameters&) { - passes = RenderPass::Translucent; - return false; -} - -std::unique_ptr<Bucket> CustomLayer::Impl::createBucket(const BucketParameters&, const std::vector<const Layer*>&) const { - assert(false); - return nullptr; -} - } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/layers/custom_layer_impl.hpp b/src/mbgl/style/layers/custom_layer_impl.hpp index 33eb86828c..e612d17f14 100644 --- a/src/mbgl/style/layers/custom_layer_impl.hpp +++ b/src/mbgl/style/layers/custom_layer_impl.hpp @@ -29,10 +29,7 @@ private: std::unique_ptr<Layer> cloneRef(const std::string& id) const override; void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override; - void cascade(const CascadeParameters&) final {} - bool evaluate(const PropertyEvaluationParameters&) final; - - std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const Layer*>&) const final; + std::unique_ptr<RenderLayer> createRenderLayer() const final; CustomLayerInitializeFunction initializeFn = nullptr; CustomLayerRenderFunction renderFn = nullptr; diff --git a/src/mbgl/style/layers/fill_extrusion_layer.cpp b/src/mbgl/style/layers/fill_extrusion_layer.cpp index 53f7fc0757..6f11d6052c 100644 --- a/src/mbgl/style/layers/fill_extrusion_layer.cpp +++ b/src/mbgl/style/layers/fill_extrusion_layer.cpp @@ -8,14 +8,14 @@ namespace mbgl { namespace style { FillExtrusionLayer::FillExtrusionLayer(const std::string& layerID, const std::string& sourceID) - : Layer(Type::FillExtrusion, std::make_unique<Impl>()) + : Layer(LayerType::FillExtrusion, std::make_unique<Impl>()) , impl(static_cast<Impl*>(baseImpl.get())) { impl->id = layerID; impl->source = sourceID; } FillExtrusionLayer::FillExtrusionLayer(const Impl& other) - : Layer(Type::FillExtrusion, std::make_unique<Impl>(other)) + : Layer(LayerType::FillExtrusion, std::make_unique<Impl>(other)) , impl(static_cast<Impl*>(baseImpl.get())) { } @@ -28,7 +28,7 @@ std::unique_ptr<Layer> FillExtrusionLayer::Impl::clone() const { std::unique_ptr<Layer> FillExtrusionLayer::Impl::cloneRef(const std::string& id_) const { auto result = std::make_unique<FillExtrusionLayer>(*this); result->impl->id = id_; - result->impl->paint = FillExtrusionPaintProperties(); + result->impl->cascading = FillExtrusionPaintProperties::Cascading(); return std::move(result); } @@ -70,22 +70,22 @@ PropertyValue<float> FillExtrusionLayer::getDefaultFillExtrusionOpacity() { } PropertyValue<float> FillExtrusionLayer::getFillExtrusionOpacity(const optional<std::string>& klass) const { - return impl->paint.get<FillExtrusionOpacity>(klass); + return impl->cascading.template get<FillExtrusionOpacity>().get(klass); } void FillExtrusionLayer::setFillExtrusionOpacity(PropertyValue<float> value, const optional<std::string>& klass) { if (value == getFillExtrusionOpacity(klass)) return; - impl->paint.set<FillExtrusionOpacity>(value, klass); + impl->cascading.template get<FillExtrusionOpacity>().set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } void FillExtrusionLayer::setFillExtrusionOpacityTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<FillExtrusionOpacity>(value, klass); + impl->cascading.template get<FillExtrusionOpacity>().setTransition(value, klass); } TransitionOptions FillExtrusionLayer::getFillExtrusionOpacityTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<FillExtrusionOpacity>(klass); + return impl->cascading.template get<FillExtrusionOpacity>().getTransition(klass); } DataDrivenPropertyValue<Color> FillExtrusionLayer::getDefaultFillExtrusionColor() { @@ -93,13 +93,13 @@ DataDrivenPropertyValue<Color> FillExtrusionLayer::getDefaultFillExtrusionColor( } DataDrivenPropertyValue<Color> FillExtrusionLayer::getFillExtrusionColor(const optional<std::string>& klass) const { - return impl->paint.get<FillExtrusionColor>(klass); + return impl->cascading.template get<FillExtrusionColor>().get(klass); } void FillExtrusionLayer::setFillExtrusionColor(DataDrivenPropertyValue<Color> value, const optional<std::string>& klass) { if (value == getFillExtrusionColor(klass)) return; - impl->paint.set<FillExtrusionColor>(value, klass); + impl->cascading.template get<FillExtrusionColor>().set(value, klass); if (value.isDataDriven()) { impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); } else { @@ -108,11 +108,11 @@ void FillExtrusionLayer::setFillExtrusionColor(DataDrivenPropertyValue<Color> va } void FillExtrusionLayer::setFillExtrusionColorTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<FillExtrusionColor>(value, klass); + impl->cascading.template get<FillExtrusionColor>().setTransition(value, klass); } TransitionOptions FillExtrusionLayer::getFillExtrusionColorTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<FillExtrusionColor>(klass); + return impl->cascading.template get<FillExtrusionColor>().getTransition(klass); } PropertyValue<std::array<float, 2>> FillExtrusionLayer::getDefaultFillExtrusionTranslate() { @@ -120,22 +120,22 @@ PropertyValue<std::array<float, 2>> FillExtrusionLayer::getDefaultFillExtrusionT } PropertyValue<std::array<float, 2>> FillExtrusionLayer::getFillExtrusionTranslate(const optional<std::string>& klass) const { - return impl->paint.get<FillExtrusionTranslate>(klass); + return impl->cascading.template get<FillExtrusionTranslate>().get(klass); } void FillExtrusionLayer::setFillExtrusionTranslate(PropertyValue<std::array<float, 2>> value, const optional<std::string>& klass) { if (value == getFillExtrusionTranslate(klass)) return; - impl->paint.set<FillExtrusionTranslate>(value, klass); + impl->cascading.template get<FillExtrusionTranslate>().set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } void FillExtrusionLayer::setFillExtrusionTranslateTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<FillExtrusionTranslate>(value, klass); + impl->cascading.template get<FillExtrusionTranslate>().setTransition(value, klass); } TransitionOptions FillExtrusionLayer::getFillExtrusionTranslateTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<FillExtrusionTranslate>(klass); + return impl->cascading.template get<FillExtrusionTranslate>().getTransition(klass); } PropertyValue<TranslateAnchorType> FillExtrusionLayer::getDefaultFillExtrusionTranslateAnchor() { @@ -143,22 +143,22 @@ PropertyValue<TranslateAnchorType> FillExtrusionLayer::getDefaultFillExtrusionTr } PropertyValue<TranslateAnchorType> FillExtrusionLayer::getFillExtrusionTranslateAnchor(const optional<std::string>& klass) const { - return impl->paint.get<FillExtrusionTranslateAnchor>(klass); + return impl->cascading.template get<FillExtrusionTranslateAnchor>().get(klass); } void FillExtrusionLayer::setFillExtrusionTranslateAnchor(PropertyValue<TranslateAnchorType> value, const optional<std::string>& klass) { if (value == getFillExtrusionTranslateAnchor(klass)) return; - impl->paint.set<FillExtrusionTranslateAnchor>(value, klass); + impl->cascading.template get<FillExtrusionTranslateAnchor>().set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } void FillExtrusionLayer::setFillExtrusionTranslateAnchorTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<FillExtrusionTranslateAnchor>(value, klass); + impl->cascading.template get<FillExtrusionTranslateAnchor>().setTransition(value, klass); } TransitionOptions FillExtrusionLayer::getFillExtrusionTranslateAnchorTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<FillExtrusionTranslateAnchor>(klass); + return impl->cascading.template get<FillExtrusionTranslateAnchor>().getTransition(klass); } PropertyValue<std::string> FillExtrusionLayer::getDefaultFillExtrusionPattern() { @@ -166,22 +166,22 @@ PropertyValue<std::string> FillExtrusionLayer::getDefaultFillExtrusionPattern() } PropertyValue<std::string> FillExtrusionLayer::getFillExtrusionPattern(const optional<std::string>& klass) const { - return impl->paint.get<FillExtrusionPattern>(klass); + return impl->cascading.template get<FillExtrusionPattern>().get(klass); } void FillExtrusionLayer::setFillExtrusionPattern(PropertyValue<std::string> value, const optional<std::string>& klass) { if (value == getFillExtrusionPattern(klass)) return; - impl->paint.set<FillExtrusionPattern>(value, klass); + impl->cascading.template get<FillExtrusionPattern>().set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } void FillExtrusionLayer::setFillExtrusionPatternTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<FillExtrusionPattern>(value, klass); + impl->cascading.template get<FillExtrusionPattern>().setTransition(value, klass); } TransitionOptions FillExtrusionLayer::getFillExtrusionPatternTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<FillExtrusionPattern>(klass); + return impl->cascading.template get<FillExtrusionPattern>().getTransition(klass); } DataDrivenPropertyValue<float> FillExtrusionLayer::getDefaultFillExtrusionHeight() { @@ -189,13 +189,13 @@ DataDrivenPropertyValue<float> FillExtrusionLayer::getDefaultFillExtrusionHeight } DataDrivenPropertyValue<float> FillExtrusionLayer::getFillExtrusionHeight(const optional<std::string>& klass) const { - return impl->paint.get<FillExtrusionHeight>(klass); + return impl->cascading.template get<FillExtrusionHeight>().get(klass); } void FillExtrusionLayer::setFillExtrusionHeight(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) { if (value == getFillExtrusionHeight(klass)) return; - impl->paint.set<FillExtrusionHeight>(value, klass); + impl->cascading.template get<FillExtrusionHeight>().set(value, klass); if (value.isDataDriven()) { impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); } else { @@ -204,11 +204,11 @@ void FillExtrusionLayer::setFillExtrusionHeight(DataDrivenPropertyValue<float> v } void FillExtrusionLayer::setFillExtrusionHeightTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<FillExtrusionHeight>(value, klass); + impl->cascading.template get<FillExtrusionHeight>().setTransition(value, klass); } TransitionOptions FillExtrusionLayer::getFillExtrusionHeightTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<FillExtrusionHeight>(klass); + return impl->cascading.template get<FillExtrusionHeight>().getTransition(klass); } DataDrivenPropertyValue<float> FillExtrusionLayer::getDefaultFillExtrusionBase() { @@ -216,13 +216,13 @@ DataDrivenPropertyValue<float> FillExtrusionLayer::getDefaultFillExtrusionBase() } DataDrivenPropertyValue<float> FillExtrusionLayer::getFillExtrusionBase(const optional<std::string>& klass) const { - return impl->paint.get<FillExtrusionBase>(klass); + return impl->cascading.template get<FillExtrusionBase>().get(klass); } void FillExtrusionLayer::setFillExtrusionBase(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) { if (value == getFillExtrusionBase(klass)) return; - impl->paint.set<FillExtrusionBase>(value, klass); + impl->cascading.template get<FillExtrusionBase>().set(value, klass); if (value.isDataDriven()) { impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); } else { @@ -231,11 +231,11 @@ void FillExtrusionLayer::setFillExtrusionBase(DataDrivenPropertyValue<float> val } void FillExtrusionLayer::setFillExtrusionBaseTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<FillExtrusionBase>(value, klass); + impl->cascading.template get<FillExtrusionBase>().setTransition(value, klass); } TransitionOptions FillExtrusionLayer::getFillExtrusionBaseTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<FillExtrusionBase>(klass); + return impl->cascading.template get<FillExtrusionBase>().getTransition(klass); } } // namespace style diff --git a/src/mbgl/style/layers/fill_extrusion_layer_impl.cpp b/src/mbgl/style/layers/fill_extrusion_layer_impl.cpp index a809820644..5340541221 100644 --- a/src/mbgl/style/layers/fill_extrusion_layer_impl.cpp +++ b/src/mbgl/style/layers/fill_extrusion_layer_impl.cpp @@ -1,18 +1,11 @@ #include <mbgl/style/layers/fill_extrusion_layer_impl.hpp> -#include <mbgl/renderer/bucket.hpp> +#include <mbgl/renderer/render_fill_extrusion_layer.hpp> namespace mbgl { namespace style { -void FillExtrusionLayer::Impl::cascade(const CascadeParameters&) { -} - -bool FillExtrusionLayer::Impl::evaluate(const PropertyEvaluationParameters&) { - return false; -} - -std::unique_ptr<Bucket> FillExtrusionLayer::Impl::createBucket(const BucketParameters&, const std::vector<const Layer*>&) const { - return nullptr; +std::unique_ptr<RenderLayer> FillExtrusionLayer::Impl::createRenderLayer() const { + return std::make_unique<RenderFillExtrusionLayer>(*this); } } // namespace style diff --git a/src/mbgl/style/layers/fill_extrusion_layer_impl.hpp b/src/mbgl/style/layers/fill_extrusion_layer_impl.hpp index ed7ef747fb..f6f9753460 100644 --- a/src/mbgl/style/layers/fill_extrusion_layer_impl.hpp +++ b/src/mbgl/style/layers/fill_extrusion_layer_impl.hpp @@ -13,12 +13,11 @@ public: std::unique_ptr<Layer> cloneRef(const std::string& id) const override; void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override; - void cascade(const CascadeParameters&) override; - bool evaluate(const PropertyEvaluationParameters&) override; + std::unique_ptr<RenderLayer> createRenderLayer() const override; - std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const Layer*>&) const override; + FillExtrusionPaintProperties::Cascading cascading; - FillExtrusionPaintProperties paint; + //style::FillExtrusionLayer::Impl* const impl; }; } // namespace style diff --git a/src/mbgl/style/layers/fill_layer.cpp b/src/mbgl/style/layers/fill_layer.cpp index 34203a10c0..9fd9d33af3 100644 --- a/src/mbgl/style/layers/fill_layer.cpp +++ b/src/mbgl/style/layers/fill_layer.cpp @@ -8,14 +8,14 @@ namespace mbgl { namespace style { FillLayer::FillLayer(const std::string& layerID, const std::string& sourceID) - : Layer(Type::Fill, std::make_unique<Impl>()) + : Layer(LayerType::Fill, std::make_unique<Impl>()) , impl(static_cast<Impl*>(baseImpl.get())) { impl->id = layerID; impl->source = sourceID; } FillLayer::FillLayer(const Impl& other) - : Layer(Type::Fill, std::make_unique<Impl>(other)) + : Layer(LayerType::Fill, std::make_unique<Impl>(other)) , impl(static_cast<Impl*>(baseImpl.get())) { } @@ -28,7 +28,7 @@ std::unique_ptr<Layer> FillLayer::Impl::clone() const { std::unique_ptr<Layer> FillLayer::Impl::cloneRef(const std::string& id_) const { auto result = std::make_unique<FillLayer>(*this); result->impl->id = id_; - result->impl->paint = FillPaintProperties(); + result->impl->cascading = FillPaintProperties::Cascading(); return std::move(result); } @@ -70,22 +70,22 @@ PropertyValue<bool> FillLayer::getDefaultFillAntialias() { } PropertyValue<bool> FillLayer::getFillAntialias(const optional<std::string>& klass) const { - return impl->paint.get<FillAntialias>(klass); + return impl->cascading.template get<FillAntialias>().get(klass); } void FillLayer::setFillAntialias(PropertyValue<bool> value, const optional<std::string>& klass) { if (value == getFillAntialias(klass)) return; - impl->paint.set<FillAntialias>(value, klass); + impl->cascading.template get<FillAntialias>().set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } void FillLayer::setFillAntialiasTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<FillAntialias>(value, klass); + impl->cascading.template get<FillAntialias>().setTransition(value, klass); } TransitionOptions FillLayer::getFillAntialiasTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<FillAntialias>(klass); + return impl->cascading.template get<FillAntialias>().getTransition(klass); } DataDrivenPropertyValue<float> FillLayer::getDefaultFillOpacity() { @@ -93,13 +93,13 @@ DataDrivenPropertyValue<float> FillLayer::getDefaultFillOpacity() { } DataDrivenPropertyValue<float> FillLayer::getFillOpacity(const optional<std::string>& klass) const { - return impl->paint.get<FillOpacity>(klass); + return impl->cascading.template get<FillOpacity>().get(klass); } void FillLayer::setFillOpacity(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) { if (value == getFillOpacity(klass)) return; - impl->paint.set<FillOpacity>(value, klass); + impl->cascading.template get<FillOpacity>().set(value, klass); if (value.isDataDriven()) { impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); } else { @@ -108,11 +108,11 @@ void FillLayer::setFillOpacity(DataDrivenPropertyValue<float> value, const optio } void FillLayer::setFillOpacityTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<FillOpacity>(value, klass); + impl->cascading.template get<FillOpacity>().setTransition(value, klass); } TransitionOptions FillLayer::getFillOpacityTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<FillOpacity>(klass); + return impl->cascading.template get<FillOpacity>().getTransition(klass); } DataDrivenPropertyValue<Color> FillLayer::getDefaultFillColor() { @@ -120,13 +120,13 @@ DataDrivenPropertyValue<Color> FillLayer::getDefaultFillColor() { } DataDrivenPropertyValue<Color> FillLayer::getFillColor(const optional<std::string>& klass) const { - return impl->paint.get<FillColor>(klass); + return impl->cascading.template get<FillColor>().get(klass); } void FillLayer::setFillColor(DataDrivenPropertyValue<Color> value, const optional<std::string>& klass) { if (value == getFillColor(klass)) return; - impl->paint.set<FillColor>(value, klass); + impl->cascading.template get<FillColor>().set(value, klass); if (value.isDataDriven()) { impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); } else { @@ -135,11 +135,11 @@ void FillLayer::setFillColor(DataDrivenPropertyValue<Color> value, const optiona } void FillLayer::setFillColorTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<FillColor>(value, klass); + impl->cascading.template get<FillColor>().setTransition(value, klass); } TransitionOptions FillLayer::getFillColorTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<FillColor>(klass); + return impl->cascading.template get<FillColor>().getTransition(klass); } DataDrivenPropertyValue<Color> FillLayer::getDefaultFillOutlineColor() { @@ -147,13 +147,13 @@ DataDrivenPropertyValue<Color> FillLayer::getDefaultFillOutlineColor() { } DataDrivenPropertyValue<Color> FillLayer::getFillOutlineColor(const optional<std::string>& klass) const { - return impl->paint.get<FillOutlineColor>(klass); + return impl->cascading.template get<FillOutlineColor>().get(klass); } void FillLayer::setFillOutlineColor(DataDrivenPropertyValue<Color> value, const optional<std::string>& klass) { if (value == getFillOutlineColor(klass)) return; - impl->paint.set<FillOutlineColor>(value, klass); + impl->cascading.template get<FillOutlineColor>().set(value, klass); if (value.isDataDriven()) { impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); } else { @@ -162,11 +162,11 @@ void FillLayer::setFillOutlineColor(DataDrivenPropertyValue<Color> value, const } void FillLayer::setFillOutlineColorTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<FillOutlineColor>(value, klass); + impl->cascading.template get<FillOutlineColor>().setTransition(value, klass); } TransitionOptions FillLayer::getFillOutlineColorTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<FillOutlineColor>(klass); + return impl->cascading.template get<FillOutlineColor>().getTransition(klass); } PropertyValue<std::array<float, 2>> FillLayer::getDefaultFillTranslate() { @@ -174,22 +174,22 @@ PropertyValue<std::array<float, 2>> FillLayer::getDefaultFillTranslate() { } PropertyValue<std::array<float, 2>> FillLayer::getFillTranslate(const optional<std::string>& klass) const { - return impl->paint.get<FillTranslate>(klass); + return impl->cascading.template get<FillTranslate>().get(klass); } void FillLayer::setFillTranslate(PropertyValue<std::array<float, 2>> value, const optional<std::string>& klass) { if (value == getFillTranslate(klass)) return; - impl->paint.set<FillTranslate>(value, klass); + impl->cascading.template get<FillTranslate>().set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } void FillLayer::setFillTranslateTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<FillTranslate>(value, klass); + impl->cascading.template get<FillTranslate>().setTransition(value, klass); } TransitionOptions FillLayer::getFillTranslateTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<FillTranslate>(klass); + return impl->cascading.template get<FillTranslate>().getTransition(klass); } PropertyValue<TranslateAnchorType> FillLayer::getDefaultFillTranslateAnchor() { @@ -197,22 +197,22 @@ PropertyValue<TranslateAnchorType> FillLayer::getDefaultFillTranslateAnchor() { } PropertyValue<TranslateAnchorType> FillLayer::getFillTranslateAnchor(const optional<std::string>& klass) const { - return impl->paint.get<FillTranslateAnchor>(klass); + return impl->cascading.template get<FillTranslateAnchor>().get(klass); } void FillLayer::setFillTranslateAnchor(PropertyValue<TranslateAnchorType> value, const optional<std::string>& klass) { if (value == getFillTranslateAnchor(klass)) return; - impl->paint.set<FillTranslateAnchor>(value, klass); + impl->cascading.template get<FillTranslateAnchor>().set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } void FillLayer::setFillTranslateAnchorTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<FillTranslateAnchor>(value, klass); + impl->cascading.template get<FillTranslateAnchor>().setTransition(value, klass); } TransitionOptions FillLayer::getFillTranslateAnchorTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<FillTranslateAnchor>(klass); + return impl->cascading.template get<FillTranslateAnchor>().getTransition(klass); } PropertyValue<std::string> FillLayer::getDefaultFillPattern() { @@ -220,22 +220,22 @@ PropertyValue<std::string> FillLayer::getDefaultFillPattern() { } PropertyValue<std::string> FillLayer::getFillPattern(const optional<std::string>& klass) const { - return impl->paint.get<FillPattern>(klass); + return impl->cascading.template get<FillPattern>().get(klass); } void FillLayer::setFillPattern(PropertyValue<std::string> value, const optional<std::string>& klass) { if (value == getFillPattern(klass)) return; - impl->paint.set<FillPattern>(value, klass); + impl->cascading.template get<FillPattern>().set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } void FillLayer::setFillPatternTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<FillPattern>(value, klass); + impl->cascading.template get<FillPattern>().setTransition(value, klass); } TransitionOptions FillLayer::getFillPatternTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<FillPattern>(klass); + return impl->cascading.template get<FillPattern>().getTransition(klass); } } // namespace style diff --git a/src/mbgl/style/layers/fill_layer_impl.cpp b/src/mbgl/style/layers/fill_layer_impl.cpp index 19675ca9fb..6ec55a58e3 100644 --- a/src/mbgl/style/layers/fill_layer_impl.cpp +++ b/src/mbgl/style/layers/fill_layer_impl.cpp @@ -1,55 +1,11 @@ #include <mbgl/style/layers/fill_layer_impl.hpp> -#include <mbgl/renderer/fill_bucket.hpp> -#include <mbgl/geometry/feature_index.hpp> -#include <mbgl/util/math.hpp> -#include <mbgl/util/intersection_tests.hpp> +#include <mbgl/renderer/render_fill_layer.hpp> namespace mbgl { namespace style { -void FillLayer::Impl::cascade(const CascadeParameters& parameters) { - paint.cascade(parameters); -} - -bool FillLayer::Impl::evaluate(const PropertyEvaluationParameters& parameters) { - paint.evaluate(parameters); - - if (paint.unevaluated.get<FillOutlineColor>().isUndefined()) { - paint.evaluated.get<FillOutlineColor>() = paint.evaluated.get<FillColor>(); - } - - passes = RenderPass::None; - - if (paint.evaluated.get<FillAntialias>()) { - passes |= RenderPass::Translucent; - } - - if (!paint.unevaluated.get<FillPattern>().isUndefined() - || paint.evaluated.get<FillColor>().constantOr(Color()).a < 1.0f - || paint.evaluated.get<FillOpacity>().constantOr(0) < 1.0f) { - passes |= RenderPass::Translucent; - } else { - passes |= RenderPass::Opaque; - } - - return paint.hasTransition(); -} - -std::unique_ptr<Bucket> FillLayer::Impl::createBucket(const BucketParameters& parameters, const std::vector<const Layer*>& layers) const { - return std::make_unique<FillBucket>(parameters, layers); -} - -bool FillLayer::Impl::queryIntersectsFeature( - const GeometryCoordinates& queryGeometry, - const GeometryTileFeature& feature, - const float, - const float bearing, - const float pixelsToTileUnits) const { - - auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry( - queryGeometry, paint.evaluated.get<FillTranslate>(), paint.evaluated.get<FillTranslateAnchor>(), bearing, pixelsToTileUnits); - - return util::polygonIntersectsMultiPolygon(translatedQueryGeometry.value_or(queryGeometry), feature.getGeometries()); +std::unique_ptr<RenderLayer> FillLayer::Impl::createRenderLayer() const { + return std::make_unique<RenderFillLayer>(*this); } } // namespace style diff --git a/src/mbgl/style/layers/fill_layer_impl.hpp b/src/mbgl/style/layers/fill_layer_impl.hpp index 712cb0a6e0..215558962e 100644 --- a/src/mbgl/style/layers/fill_layer_impl.hpp +++ b/src/mbgl/style/layers/fill_layer_impl.hpp @@ -13,19 +13,9 @@ public: std::unique_ptr<Layer> cloneRef(const std::string& id) const override; void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override; - void cascade(const CascadeParameters&) override; - bool evaluate(const PropertyEvaluationParameters&) override; + std::unique_ptr<RenderLayer> createRenderLayer() const override; - std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const Layer*>&) const override; - - bool queryIntersectsFeature( - const GeometryCoordinates&, - const GeometryTileFeature&, - const float, - const float, - const float) const override; - - FillPaintProperties paint; + FillPaintProperties::Cascading cascading; }; } // namespace style diff --git a/src/mbgl/style/layers/layer.cpp.ejs b/src/mbgl/style/layers/layer.cpp.ejs index 76c83f474a..2f690c3158 100644 --- a/src/mbgl/style/layers/layer.cpp.ejs +++ b/src/mbgl/style/layers/layer.cpp.ejs @@ -14,13 +14,13 @@ namespace style { <% if (type === 'background') { -%> <%- camelize(type) %>Layer::<%- camelize(type) %>Layer(const std::string& layerID) - : Layer(Type::<%- camelize(type) %>, std::make_unique<Impl>()) + : Layer(LayerType::<%- camelize(type) %>, std::make_unique<Impl>()) , impl(static_cast<Impl*>(baseImpl.get())) { impl->id = layerID; } <% } else { -%> <%- camelize(type) %>Layer::<%- camelize(type) %>Layer(const std::string& layerID, const std::string& sourceID) - : Layer(Type::<%- camelize(type) %>, std::make_unique<Impl>()) + : Layer(LayerType::<%- camelize(type) %>, std::make_unique<Impl>()) , impl(static_cast<Impl*>(baseImpl.get())) { impl->id = layerID; impl->source = sourceID; @@ -28,7 +28,7 @@ namespace style { <% } -%> <%- camelize(type) %>Layer::<%- camelize(type) %>Layer(const Impl& other) - : Layer(Type::<%- camelize(type) %>, std::make_unique<Impl>(other)) + : Layer(LayerType::<%- camelize(type) %>, std::make_unique<Impl>(other)) , impl(static_cast<Impl*>(baseImpl.get())) { } @@ -41,7 +41,7 @@ std::unique_ptr<Layer> <%- camelize(type) %>Layer::Impl::clone() const { std::unique_ptr<Layer> <%- camelize(type) %>Layer::Impl::cloneRef(const std::string& id_) const { auto result = std::make_unique<<%- camelize(type) %>Layer>(*this); result->impl->id = id_; - result->impl->paint = <%- camelize(type) %>PaintProperties(); + result->impl->cascading = <%- camelize(type) %>PaintProperties::Cascading(); return std::move(result); } @@ -109,13 +109,13 @@ void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(<%- propertyV } <%- propertyValueType(property) %> <%- camelize(type) %>Layer::get<%- camelize(property.name) %>(const optional<std::string>& klass) const { - return impl->paint.get<<%- camelize(property.name) %>>(klass); + return impl->cascading.template get<<%- camelize(property.name) %>>().get(klass); } void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(<%- propertyValueType(property) %> value, const optional<std::string>& klass) { if (value == get<%- camelize(property.name) %>(klass)) return; - impl->paint.set<<%- camelize(property.name) %>>(value, klass); + impl->cascading.template get<<%- camelize(property.name) %>>().set(value, klass); <% if (isDataDriven(property)) { -%> if (value.isDataDriven()) { impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); @@ -128,11 +128,11 @@ void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(<%- propertyV } void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>Transition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<<%- camelize(property.name) %>>(value, klass); + impl->cascading.template get<<%- camelize(property.name) %>>().setTransition(value, klass); } TransitionOptions <%- camelize(type) %>Layer::get<%- camelize(property.name) %>Transition(const optional<std::string>& klass) const { - return impl->paint.getTransition<<%- camelize(property.name) %>>(klass); + return impl->cascading.template get<<%- camelize(property.name) %>>().getTransition(klass); } <% } -%> diff --git a/src/mbgl/style/layers/line_layer.cpp b/src/mbgl/style/layers/line_layer.cpp index cfb68f3262..7f1575aad5 100644 --- a/src/mbgl/style/layers/line_layer.cpp +++ b/src/mbgl/style/layers/line_layer.cpp @@ -8,14 +8,14 @@ namespace mbgl { namespace style { LineLayer::LineLayer(const std::string& layerID, const std::string& sourceID) - : Layer(Type::Line, std::make_unique<Impl>()) + : Layer(LayerType::Line, std::make_unique<Impl>()) , impl(static_cast<Impl*>(baseImpl.get())) { impl->id = layerID; impl->source = sourceID; } LineLayer::LineLayer(const Impl& other) - : Layer(Type::Line, std::make_unique<Impl>(other)) + : Layer(LayerType::Line, std::make_unique<Impl>(other)) , impl(static_cast<Impl*>(baseImpl.get())) { } @@ -28,7 +28,7 @@ std::unique_ptr<Layer> LineLayer::Impl::clone() const { std::unique_ptr<Layer> LineLayer::Impl::cloneRef(const std::string& id_) const { auto result = std::make_unique<LineLayer>(*this); result->impl->id = id_; - result->impl->paint = LinePaintProperties(); + result->impl->cascading = LinePaintProperties::Cascading(); return std::move(result); } @@ -127,13 +127,13 @@ DataDrivenPropertyValue<float> LineLayer::getDefaultLineOpacity() { } DataDrivenPropertyValue<float> LineLayer::getLineOpacity(const optional<std::string>& klass) const { - return impl->paint.get<LineOpacity>(klass); + return impl->cascading.template get<LineOpacity>().get(klass); } void LineLayer::setLineOpacity(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) { if (value == getLineOpacity(klass)) return; - impl->paint.set<LineOpacity>(value, klass); + impl->cascading.template get<LineOpacity>().set(value, klass); if (value.isDataDriven()) { impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); } else { @@ -142,11 +142,11 @@ void LineLayer::setLineOpacity(DataDrivenPropertyValue<float> value, const optio } void LineLayer::setLineOpacityTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<LineOpacity>(value, klass); + impl->cascading.template get<LineOpacity>().setTransition(value, klass); } TransitionOptions LineLayer::getLineOpacityTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<LineOpacity>(klass); + return impl->cascading.template get<LineOpacity>().getTransition(klass); } DataDrivenPropertyValue<Color> LineLayer::getDefaultLineColor() { @@ -154,13 +154,13 @@ DataDrivenPropertyValue<Color> LineLayer::getDefaultLineColor() { } DataDrivenPropertyValue<Color> LineLayer::getLineColor(const optional<std::string>& klass) const { - return impl->paint.get<LineColor>(klass); + return impl->cascading.template get<LineColor>().get(klass); } void LineLayer::setLineColor(DataDrivenPropertyValue<Color> value, const optional<std::string>& klass) { if (value == getLineColor(klass)) return; - impl->paint.set<LineColor>(value, klass); + impl->cascading.template get<LineColor>().set(value, klass); if (value.isDataDriven()) { impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); } else { @@ -169,11 +169,11 @@ void LineLayer::setLineColor(DataDrivenPropertyValue<Color> value, const optiona } void LineLayer::setLineColorTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<LineColor>(value, klass); + impl->cascading.template get<LineColor>().setTransition(value, klass); } TransitionOptions LineLayer::getLineColorTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<LineColor>(klass); + return impl->cascading.template get<LineColor>().getTransition(klass); } PropertyValue<std::array<float, 2>> LineLayer::getDefaultLineTranslate() { @@ -181,22 +181,22 @@ PropertyValue<std::array<float, 2>> LineLayer::getDefaultLineTranslate() { } PropertyValue<std::array<float, 2>> LineLayer::getLineTranslate(const optional<std::string>& klass) const { - return impl->paint.get<LineTranslate>(klass); + return impl->cascading.template get<LineTranslate>().get(klass); } void LineLayer::setLineTranslate(PropertyValue<std::array<float, 2>> value, const optional<std::string>& klass) { if (value == getLineTranslate(klass)) return; - impl->paint.set<LineTranslate>(value, klass); + impl->cascading.template get<LineTranslate>().set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } void LineLayer::setLineTranslateTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<LineTranslate>(value, klass); + impl->cascading.template get<LineTranslate>().setTransition(value, klass); } TransitionOptions LineLayer::getLineTranslateTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<LineTranslate>(klass); + return impl->cascading.template get<LineTranslate>().getTransition(klass); } PropertyValue<TranslateAnchorType> LineLayer::getDefaultLineTranslateAnchor() { @@ -204,22 +204,22 @@ PropertyValue<TranslateAnchorType> LineLayer::getDefaultLineTranslateAnchor() { } PropertyValue<TranslateAnchorType> LineLayer::getLineTranslateAnchor(const optional<std::string>& klass) const { - return impl->paint.get<LineTranslateAnchor>(klass); + return impl->cascading.template get<LineTranslateAnchor>().get(klass); } void LineLayer::setLineTranslateAnchor(PropertyValue<TranslateAnchorType> value, const optional<std::string>& klass) { if (value == getLineTranslateAnchor(klass)) return; - impl->paint.set<LineTranslateAnchor>(value, klass); + impl->cascading.template get<LineTranslateAnchor>().set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } void LineLayer::setLineTranslateAnchorTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<LineTranslateAnchor>(value, klass); + impl->cascading.template get<LineTranslateAnchor>().setTransition(value, klass); } TransitionOptions LineLayer::getLineTranslateAnchorTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<LineTranslateAnchor>(klass); + return impl->cascading.template get<LineTranslateAnchor>().getTransition(klass); } PropertyValue<float> LineLayer::getDefaultLineWidth() { @@ -227,22 +227,22 @@ PropertyValue<float> LineLayer::getDefaultLineWidth() { } PropertyValue<float> LineLayer::getLineWidth(const optional<std::string>& klass) const { - return impl->paint.get<LineWidth>(klass); + return impl->cascading.template get<LineWidth>().get(klass); } void LineLayer::setLineWidth(PropertyValue<float> value, const optional<std::string>& klass) { if (value == getLineWidth(klass)) return; - impl->paint.set<LineWidth>(value, klass); + impl->cascading.template get<LineWidth>().set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } void LineLayer::setLineWidthTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<LineWidth>(value, klass); + impl->cascading.template get<LineWidth>().setTransition(value, klass); } TransitionOptions LineLayer::getLineWidthTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<LineWidth>(klass); + return impl->cascading.template get<LineWidth>().getTransition(klass); } DataDrivenPropertyValue<float> LineLayer::getDefaultLineGapWidth() { @@ -250,13 +250,13 @@ DataDrivenPropertyValue<float> LineLayer::getDefaultLineGapWidth() { } DataDrivenPropertyValue<float> LineLayer::getLineGapWidth(const optional<std::string>& klass) const { - return impl->paint.get<LineGapWidth>(klass); + return impl->cascading.template get<LineGapWidth>().get(klass); } void LineLayer::setLineGapWidth(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) { if (value == getLineGapWidth(klass)) return; - impl->paint.set<LineGapWidth>(value, klass); + impl->cascading.template get<LineGapWidth>().set(value, klass); if (value.isDataDriven()) { impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); } else { @@ -265,11 +265,11 @@ void LineLayer::setLineGapWidth(DataDrivenPropertyValue<float> value, const opti } void LineLayer::setLineGapWidthTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<LineGapWidth>(value, klass); + impl->cascading.template get<LineGapWidth>().setTransition(value, klass); } TransitionOptions LineLayer::getLineGapWidthTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<LineGapWidth>(klass); + return impl->cascading.template get<LineGapWidth>().getTransition(klass); } DataDrivenPropertyValue<float> LineLayer::getDefaultLineOffset() { @@ -277,13 +277,13 @@ DataDrivenPropertyValue<float> LineLayer::getDefaultLineOffset() { } DataDrivenPropertyValue<float> LineLayer::getLineOffset(const optional<std::string>& klass) const { - return impl->paint.get<LineOffset>(klass); + return impl->cascading.template get<LineOffset>().get(klass); } void LineLayer::setLineOffset(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) { if (value == getLineOffset(klass)) return; - impl->paint.set<LineOffset>(value, klass); + impl->cascading.template get<LineOffset>().set(value, klass); if (value.isDataDriven()) { impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); } else { @@ -292,11 +292,11 @@ void LineLayer::setLineOffset(DataDrivenPropertyValue<float> value, const option } void LineLayer::setLineOffsetTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<LineOffset>(value, klass); + impl->cascading.template get<LineOffset>().setTransition(value, klass); } TransitionOptions LineLayer::getLineOffsetTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<LineOffset>(klass); + return impl->cascading.template get<LineOffset>().getTransition(klass); } DataDrivenPropertyValue<float> LineLayer::getDefaultLineBlur() { @@ -304,13 +304,13 @@ DataDrivenPropertyValue<float> LineLayer::getDefaultLineBlur() { } DataDrivenPropertyValue<float> LineLayer::getLineBlur(const optional<std::string>& klass) const { - return impl->paint.get<LineBlur>(klass); + return impl->cascading.template get<LineBlur>().get(klass); } void LineLayer::setLineBlur(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) { if (value == getLineBlur(klass)) return; - impl->paint.set<LineBlur>(value, klass); + impl->cascading.template get<LineBlur>().set(value, klass); if (value.isDataDriven()) { impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); } else { @@ -319,11 +319,11 @@ void LineLayer::setLineBlur(DataDrivenPropertyValue<float> value, const optional } void LineLayer::setLineBlurTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<LineBlur>(value, klass); + impl->cascading.template get<LineBlur>().setTransition(value, klass); } TransitionOptions LineLayer::getLineBlurTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<LineBlur>(klass); + return impl->cascading.template get<LineBlur>().getTransition(klass); } PropertyValue<std::vector<float>> LineLayer::getDefaultLineDasharray() { @@ -331,22 +331,22 @@ PropertyValue<std::vector<float>> LineLayer::getDefaultLineDasharray() { } PropertyValue<std::vector<float>> LineLayer::getLineDasharray(const optional<std::string>& klass) const { - return impl->paint.get<LineDasharray>(klass); + return impl->cascading.template get<LineDasharray>().get(klass); } void LineLayer::setLineDasharray(PropertyValue<std::vector<float>> value, const optional<std::string>& klass) { if (value == getLineDasharray(klass)) return; - impl->paint.set<LineDasharray>(value, klass); + impl->cascading.template get<LineDasharray>().set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } void LineLayer::setLineDasharrayTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<LineDasharray>(value, klass); + impl->cascading.template get<LineDasharray>().setTransition(value, klass); } TransitionOptions LineLayer::getLineDasharrayTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<LineDasharray>(klass); + return impl->cascading.template get<LineDasharray>().getTransition(klass); } PropertyValue<std::string> LineLayer::getDefaultLinePattern() { @@ -354,22 +354,22 @@ PropertyValue<std::string> LineLayer::getDefaultLinePattern() { } PropertyValue<std::string> LineLayer::getLinePattern(const optional<std::string>& klass) const { - return impl->paint.get<LinePattern>(klass); + return impl->cascading.template get<LinePattern>().get(klass); } void LineLayer::setLinePattern(PropertyValue<std::string> value, const optional<std::string>& klass) { if (value == getLinePattern(klass)) return; - impl->paint.set<LinePattern>(value, klass); + impl->cascading.template get<LinePattern>().set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } void LineLayer::setLinePatternTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<LinePattern>(value, klass); + impl->cascading.template get<LinePattern>().setTransition(value, klass); } TransitionOptions LineLayer::getLinePatternTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<LinePattern>(klass); + return impl->cascading.template get<LinePattern>().getTransition(klass); } } // namespace style diff --git a/src/mbgl/style/layers/line_layer_impl.cpp b/src/mbgl/style/layers/line_layer_impl.cpp index d283292914..973a77abf4 100644 --- a/src/mbgl/style/layers/line_layer_impl.cpp +++ b/src/mbgl/style/layers/line_layer_impl.cpp @@ -1,102 +1,11 @@ #include <mbgl/style/layers/line_layer_impl.hpp> -#include <mbgl/style/property_evaluation_parameters.hpp> -#include <mbgl/renderer/line_bucket.hpp> -#include <mbgl/geometry/feature_index.hpp> -#include <mbgl/util/math.hpp> -#include <mbgl/util/intersection_tests.hpp> +#include <mbgl/renderer/render_line_layer.hpp> namespace mbgl { namespace style { -void LineLayer::Impl::cascade(const CascadeParameters& parameters) { - paint.cascade(parameters); -} - -bool LineLayer::Impl::evaluate(const PropertyEvaluationParameters& parameters) { - // for scaling dasharrays - PropertyEvaluationParameters dashArrayParams = parameters; - dashArrayParams.z = std::floor(dashArrayParams.z); - dashLineWidth = paint.evaluate<LineWidth>(dashArrayParams); - - paint.evaluate(parameters); - - passes = (paint.evaluated.get<LineOpacity>().constantOr(1.0) > 0 - && paint.evaluated.get<LineColor>().constantOr(Color::black()).a > 0 - && paint.evaluated.get<LineWidth>() > 0) - ? RenderPass::Translucent : RenderPass::None; - - return paint.hasTransition(); -} - -std::unique_ptr<Bucket> LineLayer::Impl::createBucket(const BucketParameters& parameters, const std::vector<const Layer*>& layers) const { - return std::make_unique<LineBucket>(parameters, layers, layout); -} - -float LineLayer::Impl::getLineWidth(const GeometryTileFeature& feature, const float zoom) const { - float lineWidth = paint.evaluated.get<LineWidth>(); - float gapWidth = paint.evaluated.get<LineGapWidth>() - .evaluate(feature, zoom, LineGapWidth::defaultValue()); - if (gapWidth) { - return gapWidth + 2 * lineWidth; - } else { - return lineWidth; - } -} - -optional<GeometryCollection> offsetLine(const GeometryCollection& rings, const double offset) { - if (offset == 0) return {}; - - GeometryCollection newRings; - Point<double> zero(0, 0); - for (const auto& ring : rings) { - newRings.emplace_back(); - auto& newRing = newRings.back(); - - for (auto i = ring.begin(); i != ring.end(); i++) { - auto& p = *i; - - Point<double> aToB = i == ring.begin() ? - zero : - util::perp(util::unit(convertPoint<double>(p - *(i - 1)))); - Point<double> bToC = i + 1 == ring.end() ? - zero : - util::perp(util::unit(convertPoint<double>(*(i + 1) - p))); - Point<double> extrude = util::unit(aToB + bToC); - - const double cosHalfAngle = extrude.x * bToC.x + extrude.y * bToC.y; - extrude *= (1.0 / cosHalfAngle); - - newRing.push_back(convertPoint<int16_t>(extrude * offset) + p); - } - } - - return newRings; -} - -bool LineLayer::Impl::queryIntersectsFeature( - const GeometryCoordinates& queryGeometry, - const GeometryTileFeature& feature, - const float zoom, - const float bearing, - const float pixelsToTileUnits) const { - - // Translate query geometry - auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry( - queryGeometry, paint.evaluated.get<LineTranslate>(), paint.evaluated.get<LineTranslateAnchor>(), bearing, pixelsToTileUnits); - - - // Evaluate function - auto offset = paint.evaluated.get<LineOffset>().evaluate(feature, zoom, LineOffset::defaultValue()) * pixelsToTileUnits; - - // Apply offset to geometry - auto offsetGeometry = offsetLine(feature.getGeometries(), offset); - - // Test intersection - const float halfWidth = getLineWidth(feature, zoom) / 2.0 * pixelsToTileUnits; - return util::polygonIntersectsBufferedMultiLine( - translatedQueryGeometry.value_or(queryGeometry), - offsetGeometry.value_or(feature.getGeometries()), - halfWidth); +std::unique_ptr<RenderLayer> LineLayer::Impl::createRenderLayer() const { + return std::make_unique<RenderLineLayer>(*this); } } // namespace style diff --git a/src/mbgl/style/layers/line_layer_impl.hpp b/src/mbgl/style/layers/line_layer_impl.hpp index b25ece3100..02c9c85f00 100644 --- a/src/mbgl/style/layers/line_layer_impl.hpp +++ b/src/mbgl/style/layers/line_layer_impl.hpp @@ -13,26 +13,10 @@ public: std::unique_ptr<Layer> cloneRef(const std::string& id) const override; void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override; - void cascade(const CascadeParameters&) override; - bool evaluate(const PropertyEvaluationParameters&) override; - - std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const Layer*>&) const override; - - bool queryIntersectsFeature( - const GeometryCoordinates&, - const GeometryTileFeature&, - const float, - const float, - const float) const override; + std::unique_ptr<RenderLayer> createRenderLayer() const override; LineLayoutProperties layout; - LinePaintProperties paint; - - // Special case - float dashLineWidth = 1; - -private: - float getLineWidth(const GeometryTileFeature&, const float) const; + LinePaintProperties::Cascading cascading; }; } // namespace style diff --git a/src/mbgl/style/layers/raster_layer.cpp b/src/mbgl/style/layers/raster_layer.cpp index dfdd13e63c..b525f9eaa4 100644 --- a/src/mbgl/style/layers/raster_layer.cpp +++ b/src/mbgl/style/layers/raster_layer.cpp @@ -8,14 +8,14 @@ namespace mbgl { namespace style { RasterLayer::RasterLayer(const std::string& layerID, const std::string& sourceID) - : Layer(Type::Raster, std::make_unique<Impl>()) + : Layer(LayerType::Raster, std::make_unique<Impl>()) , impl(static_cast<Impl*>(baseImpl.get())) { impl->id = layerID; impl->source = sourceID; } RasterLayer::RasterLayer(const Impl& other) - : Layer(Type::Raster, std::make_unique<Impl>(other)) + : Layer(LayerType::Raster, std::make_unique<Impl>(other)) , impl(static_cast<Impl*>(baseImpl.get())) { } @@ -28,7 +28,7 @@ std::unique_ptr<Layer> RasterLayer::Impl::clone() const { std::unique_ptr<Layer> RasterLayer::Impl::cloneRef(const std::string& id_) const { auto result = std::make_unique<RasterLayer>(*this); result->impl->id = id_; - result->impl->paint = RasterPaintProperties(); + result->impl->cascading = RasterPaintProperties::Cascading(); return std::move(result); } @@ -52,22 +52,22 @@ PropertyValue<float> RasterLayer::getDefaultRasterOpacity() { } PropertyValue<float> RasterLayer::getRasterOpacity(const optional<std::string>& klass) const { - return impl->paint.get<RasterOpacity>(klass); + return impl->cascading.template get<RasterOpacity>().get(klass); } void RasterLayer::setRasterOpacity(PropertyValue<float> value, const optional<std::string>& klass) { if (value == getRasterOpacity(klass)) return; - impl->paint.set<RasterOpacity>(value, klass); + impl->cascading.template get<RasterOpacity>().set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } void RasterLayer::setRasterOpacityTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<RasterOpacity>(value, klass); + impl->cascading.template get<RasterOpacity>().setTransition(value, klass); } TransitionOptions RasterLayer::getRasterOpacityTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<RasterOpacity>(klass); + return impl->cascading.template get<RasterOpacity>().getTransition(klass); } PropertyValue<float> RasterLayer::getDefaultRasterHueRotate() { @@ -75,22 +75,22 @@ PropertyValue<float> RasterLayer::getDefaultRasterHueRotate() { } PropertyValue<float> RasterLayer::getRasterHueRotate(const optional<std::string>& klass) const { - return impl->paint.get<RasterHueRotate>(klass); + return impl->cascading.template get<RasterHueRotate>().get(klass); } void RasterLayer::setRasterHueRotate(PropertyValue<float> value, const optional<std::string>& klass) { if (value == getRasterHueRotate(klass)) return; - impl->paint.set<RasterHueRotate>(value, klass); + impl->cascading.template get<RasterHueRotate>().set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } void RasterLayer::setRasterHueRotateTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<RasterHueRotate>(value, klass); + impl->cascading.template get<RasterHueRotate>().setTransition(value, klass); } TransitionOptions RasterLayer::getRasterHueRotateTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<RasterHueRotate>(klass); + return impl->cascading.template get<RasterHueRotate>().getTransition(klass); } PropertyValue<float> RasterLayer::getDefaultRasterBrightnessMin() { @@ -98,22 +98,22 @@ PropertyValue<float> RasterLayer::getDefaultRasterBrightnessMin() { } PropertyValue<float> RasterLayer::getRasterBrightnessMin(const optional<std::string>& klass) const { - return impl->paint.get<RasterBrightnessMin>(klass); + return impl->cascading.template get<RasterBrightnessMin>().get(klass); } void RasterLayer::setRasterBrightnessMin(PropertyValue<float> value, const optional<std::string>& klass) { if (value == getRasterBrightnessMin(klass)) return; - impl->paint.set<RasterBrightnessMin>(value, klass); + impl->cascading.template get<RasterBrightnessMin>().set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } void RasterLayer::setRasterBrightnessMinTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<RasterBrightnessMin>(value, klass); + impl->cascading.template get<RasterBrightnessMin>().setTransition(value, klass); } TransitionOptions RasterLayer::getRasterBrightnessMinTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<RasterBrightnessMin>(klass); + return impl->cascading.template get<RasterBrightnessMin>().getTransition(klass); } PropertyValue<float> RasterLayer::getDefaultRasterBrightnessMax() { @@ -121,22 +121,22 @@ PropertyValue<float> RasterLayer::getDefaultRasterBrightnessMax() { } PropertyValue<float> RasterLayer::getRasterBrightnessMax(const optional<std::string>& klass) const { - return impl->paint.get<RasterBrightnessMax>(klass); + return impl->cascading.template get<RasterBrightnessMax>().get(klass); } void RasterLayer::setRasterBrightnessMax(PropertyValue<float> value, const optional<std::string>& klass) { if (value == getRasterBrightnessMax(klass)) return; - impl->paint.set<RasterBrightnessMax>(value, klass); + impl->cascading.template get<RasterBrightnessMax>().set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } void RasterLayer::setRasterBrightnessMaxTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<RasterBrightnessMax>(value, klass); + impl->cascading.template get<RasterBrightnessMax>().setTransition(value, klass); } TransitionOptions RasterLayer::getRasterBrightnessMaxTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<RasterBrightnessMax>(klass); + return impl->cascading.template get<RasterBrightnessMax>().getTransition(klass); } PropertyValue<float> RasterLayer::getDefaultRasterSaturation() { @@ -144,22 +144,22 @@ PropertyValue<float> RasterLayer::getDefaultRasterSaturation() { } PropertyValue<float> RasterLayer::getRasterSaturation(const optional<std::string>& klass) const { - return impl->paint.get<RasterSaturation>(klass); + return impl->cascading.template get<RasterSaturation>().get(klass); } void RasterLayer::setRasterSaturation(PropertyValue<float> value, const optional<std::string>& klass) { if (value == getRasterSaturation(klass)) return; - impl->paint.set<RasterSaturation>(value, klass); + impl->cascading.template get<RasterSaturation>().set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } void RasterLayer::setRasterSaturationTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<RasterSaturation>(value, klass); + impl->cascading.template get<RasterSaturation>().setTransition(value, klass); } TransitionOptions RasterLayer::getRasterSaturationTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<RasterSaturation>(klass); + return impl->cascading.template get<RasterSaturation>().getTransition(klass); } PropertyValue<float> RasterLayer::getDefaultRasterContrast() { @@ -167,22 +167,22 @@ PropertyValue<float> RasterLayer::getDefaultRasterContrast() { } PropertyValue<float> RasterLayer::getRasterContrast(const optional<std::string>& klass) const { - return impl->paint.get<RasterContrast>(klass); + return impl->cascading.template get<RasterContrast>().get(klass); } void RasterLayer::setRasterContrast(PropertyValue<float> value, const optional<std::string>& klass) { if (value == getRasterContrast(klass)) return; - impl->paint.set<RasterContrast>(value, klass); + impl->cascading.template get<RasterContrast>().set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } void RasterLayer::setRasterContrastTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<RasterContrast>(value, klass); + impl->cascading.template get<RasterContrast>().setTransition(value, klass); } TransitionOptions RasterLayer::getRasterContrastTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<RasterContrast>(klass); + return impl->cascading.template get<RasterContrast>().getTransition(klass); } PropertyValue<float> RasterLayer::getDefaultRasterFadeDuration() { @@ -190,22 +190,22 @@ PropertyValue<float> RasterLayer::getDefaultRasterFadeDuration() { } PropertyValue<float> RasterLayer::getRasterFadeDuration(const optional<std::string>& klass) const { - return impl->paint.get<RasterFadeDuration>(klass); + return impl->cascading.template get<RasterFadeDuration>().get(klass); } void RasterLayer::setRasterFadeDuration(PropertyValue<float> value, const optional<std::string>& klass) { if (value == getRasterFadeDuration(klass)) return; - impl->paint.set<RasterFadeDuration>(value, klass); + impl->cascading.template get<RasterFadeDuration>().set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } void RasterLayer::setRasterFadeDurationTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<RasterFadeDuration>(value, klass); + impl->cascading.template get<RasterFadeDuration>().setTransition(value, klass); } TransitionOptions RasterLayer::getRasterFadeDurationTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<RasterFadeDuration>(klass); + return impl->cascading.template get<RasterFadeDuration>().getTransition(klass); } } // namespace style diff --git a/src/mbgl/style/layers/raster_layer_impl.cpp b/src/mbgl/style/layers/raster_layer_impl.cpp index a667ccb5a8..fa9f80dac6 100644 --- a/src/mbgl/style/layers/raster_layer_impl.cpp +++ b/src/mbgl/style/layers/raster_layer_impl.cpp @@ -1,24 +1,11 @@ #include <mbgl/style/layers/raster_layer_impl.hpp> -#include <mbgl/renderer/bucket.hpp> +#include <mbgl/renderer/render_raster_layer.hpp> namespace mbgl { namespace style { -void RasterLayer::Impl::cascade(const CascadeParameters& parameters) { - paint.cascade(parameters); -} - -bool RasterLayer::Impl::evaluate(const PropertyEvaluationParameters& parameters) { - paint.evaluate(parameters); - - passes = paint.evaluated.get<RasterOpacity>() > 0 ? RenderPass::Translucent : RenderPass::None; - - return paint.hasTransition(); -} - -std::unique_ptr<Bucket> RasterLayer::Impl::createBucket(const BucketParameters&, const std::vector<const Layer*>&) const { - assert(false); - return nullptr; +std::unique_ptr<RenderLayer> RasterLayer::Impl::createRenderLayer() const { + return std::make_unique<RenderRasterLayer>(*this); } } // namespace style diff --git a/src/mbgl/style/layers/raster_layer_impl.hpp b/src/mbgl/style/layers/raster_layer_impl.hpp index 42985ce0f1..edf5f9111b 100644 --- a/src/mbgl/style/layers/raster_layer_impl.hpp +++ b/src/mbgl/style/layers/raster_layer_impl.hpp @@ -13,12 +13,9 @@ public: std::unique_ptr<Layer> cloneRef(const std::string& id) const override; void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override; - void cascade(const CascadeParameters&) override; - bool evaluate(const PropertyEvaluationParameters&) override; + std::unique_ptr<RenderLayer> createRenderLayer() const override; - std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const Layer*>&) const override; - - RasterPaintProperties paint; + RasterPaintProperties::Cascading cascading; }; } // namespace style diff --git a/src/mbgl/style/layers/symbol_layer.cpp b/src/mbgl/style/layers/symbol_layer.cpp index e79a3f967f..273a9fd24e 100644 --- a/src/mbgl/style/layers/symbol_layer.cpp +++ b/src/mbgl/style/layers/symbol_layer.cpp @@ -8,14 +8,14 @@ namespace mbgl { namespace style { SymbolLayer::SymbolLayer(const std::string& layerID, const std::string& sourceID) - : Layer(Type::Symbol, std::make_unique<Impl>()) + : Layer(LayerType::Symbol, std::make_unique<Impl>()) , impl(static_cast<Impl*>(baseImpl.get())) { impl->id = layerID; impl->source = sourceID; } SymbolLayer::SymbolLayer(const Impl& other) - : Layer(Type::Symbol, std::make_unique<Impl>(other)) + : Layer(LayerType::Symbol, std::make_unique<Impl>(other)) , impl(static_cast<Impl*>(baseImpl.get())) { } @@ -28,7 +28,7 @@ std::unique_ptr<Layer> SymbolLayer::Impl::clone() const { std::unique_ptr<Layer> SymbolLayer::Impl::cloneRef(const std::string& id_) const { auto result = std::make_unique<SymbolLayer>(*this); result->impl->id = id_; - result->impl->paint = SymbolPaintProperties(); + result->impl->cascading = SymbolPaintProperties::Cascading(); return std::move(result); } @@ -547,13 +547,13 @@ DataDrivenPropertyValue<float> SymbolLayer::getDefaultIconOpacity() { } DataDrivenPropertyValue<float> SymbolLayer::getIconOpacity(const optional<std::string>& klass) const { - return impl->paint.get<IconOpacity>(klass); + return impl->cascading.template get<IconOpacity>().get(klass); } void SymbolLayer::setIconOpacity(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) { if (value == getIconOpacity(klass)) return; - impl->paint.set<IconOpacity>(value, klass); + impl->cascading.template get<IconOpacity>().set(value, klass); if (value.isDataDriven()) { impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); } else { @@ -562,11 +562,11 @@ void SymbolLayer::setIconOpacity(DataDrivenPropertyValue<float> value, const opt } void SymbolLayer::setIconOpacityTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<IconOpacity>(value, klass); + impl->cascading.template get<IconOpacity>().setTransition(value, klass); } TransitionOptions SymbolLayer::getIconOpacityTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<IconOpacity>(klass); + return impl->cascading.template get<IconOpacity>().getTransition(klass); } DataDrivenPropertyValue<Color> SymbolLayer::getDefaultIconColor() { @@ -574,13 +574,13 @@ DataDrivenPropertyValue<Color> SymbolLayer::getDefaultIconColor() { } DataDrivenPropertyValue<Color> SymbolLayer::getIconColor(const optional<std::string>& klass) const { - return impl->paint.get<IconColor>(klass); + return impl->cascading.template get<IconColor>().get(klass); } void SymbolLayer::setIconColor(DataDrivenPropertyValue<Color> value, const optional<std::string>& klass) { if (value == getIconColor(klass)) return; - impl->paint.set<IconColor>(value, klass); + impl->cascading.template get<IconColor>().set(value, klass); if (value.isDataDriven()) { impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); } else { @@ -589,11 +589,11 @@ void SymbolLayer::setIconColor(DataDrivenPropertyValue<Color> value, const optio } void SymbolLayer::setIconColorTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<IconColor>(value, klass); + impl->cascading.template get<IconColor>().setTransition(value, klass); } TransitionOptions SymbolLayer::getIconColorTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<IconColor>(klass); + return impl->cascading.template get<IconColor>().getTransition(klass); } DataDrivenPropertyValue<Color> SymbolLayer::getDefaultIconHaloColor() { @@ -601,13 +601,13 @@ DataDrivenPropertyValue<Color> SymbolLayer::getDefaultIconHaloColor() { } DataDrivenPropertyValue<Color> SymbolLayer::getIconHaloColor(const optional<std::string>& klass) const { - return impl->paint.get<IconHaloColor>(klass); + return impl->cascading.template get<IconHaloColor>().get(klass); } void SymbolLayer::setIconHaloColor(DataDrivenPropertyValue<Color> value, const optional<std::string>& klass) { if (value == getIconHaloColor(klass)) return; - impl->paint.set<IconHaloColor>(value, klass); + impl->cascading.template get<IconHaloColor>().set(value, klass); if (value.isDataDriven()) { impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); } else { @@ -616,11 +616,11 @@ void SymbolLayer::setIconHaloColor(DataDrivenPropertyValue<Color> value, const o } void SymbolLayer::setIconHaloColorTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<IconHaloColor>(value, klass); + impl->cascading.template get<IconHaloColor>().setTransition(value, klass); } TransitionOptions SymbolLayer::getIconHaloColorTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<IconHaloColor>(klass); + return impl->cascading.template get<IconHaloColor>().getTransition(klass); } DataDrivenPropertyValue<float> SymbolLayer::getDefaultIconHaloWidth() { @@ -628,13 +628,13 @@ DataDrivenPropertyValue<float> SymbolLayer::getDefaultIconHaloWidth() { } DataDrivenPropertyValue<float> SymbolLayer::getIconHaloWidth(const optional<std::string>& klass) const { - return impl->paint.get<IconHaloWidth>(klass); + return impl->cascading.template get<IconHaloWidth>().get(klass); } void SymbolLayer::setIconHaloWidth(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) { if (value == getIconHaloWidth(klass)) return; - impl->paint.set<IconHaloWidth>(value, klass); + impl->cascading.template get<IconHaloWidth>().set(value, klass); if (value.isDataDriven()) { impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); } else { @@ -643,11 +643,11 @@ void SymbolLayer::setIconHaloWidth(DataDrivenPropertyValue<float> value, const o } void SymbolLayer::setIconHaloWidthTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<IconHaloWidth>(value, klass); + impl->cascading.template get<IconHaloWidth>().setTransition(value, klass); } TransitionOptions SymbolLayer::getIconHaloWidthTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<IconHaloWidth>(klass); + return impl->cascading.template get<IconHaloWidth>().getTransition(klass); } DataDrivenPropertyValue<float> SymbolLayer::getDefaultIconHaloBlur() { @@ -655,13 +655,13 @@ DataDrivenPropertyValue<float> SymbolLayer::getDefaultIconHaloBlur() { } DataDrivenPropertyValue<float> SymbolLayer::getIconHaloBlur(const optional<std::string>& klass) const { - return impl->paint.get<IconHaloBlur>(klass); + return impl->cascading.template get<IconHaloBlur>().get(klass); } void SymbolLayer::setIconHaloBlur(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) { if (value == getIconHaloBlur(klass)) return; - impl->paint.set<IconHaloBlur>(value, klass); + impl->cascading.template get<IconHaloBlur>().set(value, klass); if (value.isDataDriven()) { impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); } else { @@ -670,11 +670,11 @@ void SymbolLayer::setIconHaloBlur(DataDrivenPropertyValue<float> value, const op } void SymbolLayer::setIconHaloBlurTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<IconHaloBlur>(value, klass); + impl->cascading.template get<IconHaloBlur>().setTransition(value, klass); } TransitionOptions SymbolLayer::getIconHaloBlurTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<IconHaloBlur>(klass); + return impl->cascading.template get<IconHaloBlur>().getTransition(klass); } PropertyValue<std::array<float, 2>> SymbolLayer::getDefaultIconTranslate() { @@ -682,22 +682,22 @@ PropertyValue<std::array<float, 2>> SymbolLayer::getDefaultIconTranslate() { } PropertyValue<std::array<float, 2>> SymbolLayer::getIconTranslate(const optional<std::string>& klass) const { - return impl->paint.get<IconTranslate>(klass); + return impl->cascading.template get<IconTranslate>().get(klass); } void SymbolLayer::setIconTranslate(PropertyValue<std::array<float, 2>> value, const optional<std::string>& klass) { if (value == getIconTranslate(klass)) return; - impl->paint.set<IconTranslate>(value, klass); + impl->cascading.template get<IconTranslate>().set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } void SymbolLayer::setIconTranslateTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<IconTranslate>(value, klass); + impl->cascading.template get<IconTranslate>().setTransition(value, klass); } TransitionOptions SymbolLayer::getIconTranslateTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<IconTranslate>(klass); + return impl->cascading.template get<IconTranslate>().getTransition(klass); } PropertyValue<TranslateAnchorType> SymbolLayer::getDefaultIconTranslateAnchor() { @@ -705,22 +705,22 @@ PropertyValue<TranslateAnchorType> SymbolLayer::getDefaultIconTranslateAnchor() } PropertyValue<TranslateAnchorType> SymbolLayer::getIconTranslateAnchor(const optional<std::string>& klass) const { - return impl->paint.get<IconTranslateAnchor>(klass); + return impl->cascading.template get<IconTranslateAnchor>().get(klass); } void SymbolLayer::setIconTranslateAnchor(PropertyValue<TranslateAnchorType> value, const optional<std::string>& klass) { if (value == getIconTranslateAnchor(klass)) return; - impl->paint.set<IconTranslateAnchor>(value, klass); + impl->cascading.template get<IconTranslateAnchor>().set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } void SymbolLayer::setIconTranslateAnchorTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<IconTranslateAnchor>(value, klass); + impl->cascading.template get<IconTranslateAnchor>().setTransition(value, klass); } TransitionOptions SymbolLayer::getIconTranslateAnchorTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<IconTranslateAnchor>(klass); + return impl->cascading.template get<IconTranslateAnchor>().getTransition(klass); } DataDrivenPropertyValue<float> SymbolLayer::getDefaultTextOpacity() { @@ -728,13 +728,13 @@ DataDrivenPropertyValue<float> SymbolLayer::getDefaultTextOpacity() { } DataDrivenPropertyValue<float> SymbolLayer::getTextOpacity(const optional<std::string>& klass) const { - return impl->paint.get<TextOpacity>(klass); + return impl->cascading.template get<TextOpacity>().get(klass); } void SymbolLayer::setTextOpacity(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) { if (value == getTextOpacity(klass)) return; - impl->paint.set<TextOpacity>(value, klass); + impl->cascading.template get<TextOpacity>().set(value, klass); if (value.isDataDriven()) { impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); } else { @@ -743,11 +743,11 @@ void SymbolLayer::setTextOpacity(DataDrivenPropertyValue<float> value, const opt } void SymbolLayer::setTextOpacityTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<TextOpacity>(value, klass); + impl->cascading.template get<TextOpacity>().setTransition(value, klass); } TransitionOptions SymbolLayer::getTextOpacityTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<TextOpacity>(klass); + return impl->cascading.template get<TextOpacity>().getTransition(klass); } DataDrivenPropertyValue<Color> SymbolLayer::getDefaultTextColor() { @@ -755,13 +755,13 @@ DataDrivenPropertyValue<Color> SymbolLayer::getDefaultTextColor() { } DataDrivenPropertyValue<Color> SymbolLayer::getTextColor(const optional<std::string>& klass) const { - return impl->paint.get<TextColor>(klass); + return impl->cascading.template get<TextColor>().get(klass); } void SymbolLayer::setTextColor(DataDrivenPropertyValue<Color> value, const optional<std::string>& klass) { if (value == getTextColor(klass)) return; - impl->paint.set<TextColor>(value, klass); + impl->cascading.template get<TextColor>().set(value, klass); if (value.isDataDriven()) { impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); } else { @@ -770,11 +770,11 @@ void SymbolLayer::setTextColor(DataDrivenPropertyValue<Color> value, const optio } void SymbolLayer::setTextColorTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<TextColor>(value, klass); + impl->cascading.template get<TextColor>().setTransition(value, klass); } TransitionOptions SymbolLayer::getTextColorTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<TextColor>(klass); + return impl->cascading.template get<TextColor>().getTransition(klass); } DataDrivenPropertyValue<Color> SymbolLayer::getDefaultTextHaloColor() { @@ -782,13 +782,13 @@ DataDrivenPropertyValue<Color> SymbolLayer::getDefaultTextHaloColor() { } DataDrivenPropertyValue<Color> SymbolLayer::getTextHaloColor(const optional<std::string>& klass) const { - return impl->paint.get<TextHaloColor>(klass); + return impl->cascading.template get<TextHaloColor>().get(klass); } void SymbolLayer::setTextHaloColor(DataDrivenPropertyValue<Color> value, const optional<std::string>& klass) { if (value == getTextHaloColor(klass)) return; - impl->paint.set<TextHaloColor>(value, klass); + impl->cascading.template get<TextHaloColor>().set(value, klass); if (value.isDataDriven()) { impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); } else { @@ -797,11 +797,11 @@ void SymbolLayer::setTextHaloColor(DataDrivenPropertyValue<Color> value, const o } void SymbolLayer::setTextHaloColorTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<TextHaloColor>(value, klass); + impl->cascading.template get<TextHaloColor>().setTransition(value, klass); } TransitionOptions SymbolLayer::getTextHaloColorTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<TextHaloColor>(klass); + return impl->cascading.template get<TextHaloColor>().getTransition(klass); } DataDrivenPropertyValue<float> SymbolLayer::getDefaultTextHaloWidth() { @@ -809,13 +809,13 @@ DataDrivenPropertyValue<float> SymbolLayer::getDefaultTextHaloWidth() { } DataDrivenPropertyValue<float> SymbolLayer::getTextHaloWidth(const optional<std::string>& klass) const { - return impl->paint.get<TextHaloWidth>(klass); + return impl->cascading.template get<TextHaloWidth>().get(klass); } void SymbolLayer::setTextHaloWidth(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) { if (value == getTextHaloWidth(klass)) return; - impl->paint.set<TextHaloWidth>(value, klass); + impl->cascading.template get<TextHaloWidth>().set(value, klass); if (value.isDataDriven()) { impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); } else { @@ -824,11 +824,11 @@ void SymbolLayer::setTextHaloWidth(DataDrivenPropertyValue<float> value, const o } void SymbolLayer::setTextHaloWidthTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<TextHaloWidth>(value, klass); + impl->cascading.template get<TextHaloWidth>().setTransition(value, klass); } TransitionOptions SymbolLayer::getTextHaloWidthTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<TextHaloWidth>(klass); + return impl->cascading.template get<TextHaloWidth>().getTransition(klass); } DataDrivenPropertyValue<float> SymbolLayer::getDefaultTextHaloBlur() { @@ -836,13 +836,13 @@ DataDrivenPropertyValue<float> SymbolLayer::getDefaultTextHaloBlur() { } DataDrivenPropertyValue<float> SymbolLayer::getTextHaloBlur(const optional<std::string>& klass) const { - return impl->paint.get<TextHaloBlur>(klass); + return impl->cascading.template get<TextHaloBlur>().get(klass); } void SymbolLayer::setTextHaloBlur(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) { if (value == getTextHaloBlur(klass)) return; - impl->paint.set<TextHaloBlur>(value, klass); + impl->cascading.template get<TextHaloBlur>().set(value, klass); if (value.isDataDriven()) { impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); } else { @@ -851,11 +851,11 @@ void SymbolLayer::setTextHaloBlur(DataDrivenPropertyValue<float> value, const op } void SymbolLayer::setTextHaloBlurTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<TextHaloBlur>(value, klass); + impl->cascading.template get<TextHaloBlur>().setTransition(value, klass); } TransitionOptions SymbolLayer::getTextHaloBlurTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<TextHaloBlur>(klass); + return impl->cascading.template get<TextHaloBlur>().getTransition(klass); } PropertyValue<std::array<float, 2>> SymbolLayer::getDefaultTextTranslate() { @@ -863,22 +863,22 @@ PropertyValue<std::array<float, 2>> SymbolLayer::getDefaultTextTranslate() { } PropertyValue<std::array<float, 2>> SymbolLayer::getTextTranslate(const optional<std::string>& klass) const { - return impl->paint.get<TextTranslate>(klass); + return impl->cascading.template get<TextTranslate>().get(klass); } void SymbolLayer::setTextTranslate(PropertyValue<std::array<float, 2>> value, const optional<std::string>& klass) { if (value == getTextTranslate(klass)) return; - impl->paint.set<TextTranslate>(value, klass); + impl->cascading.template get<TextTranslate>().set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } void SymbolLayer::setTextTranslateTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<TextTranslate>(value, klass); + impl->cascading.template get<TextTranslate>().setTransition(value, klass); } TransitionOptions SymbolLayer::getTextTranslateTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<TextTranslate>(klass); + return impl->cascading.template get<TextTranslate>().getTransition(klass); } PropertyValue<TranslateAnchorType> SymbolLayer::getDefaultTextTranslateAnchor() { @@ -886,22 +886,22 @@ PropertyValue<TranslateAnchorType> SymbolLayer::getDefaultTextTranslateAnchor() } PropertyValue<TranslateAnchorType> SymbolLayer::getTextTranslateAnchor(const optional<std::string>& klass) const { - return impl->paint.get<TextTranslateAnchor>(klass); + return impl->cascading.template get<TextTranslateAnchor>().get(klass); } void SymbolLayer::setTextTranslateAnchor(PropertyValue<TranslateAnchorType> value, const optional<std::string>& klass) { if (value == getTextTranslateAnchor(klass)) return; - impl->paint.set<TextTranslateAnchor>(value, klass); + impl->cascading.template get<TextTranslateAnchor>().set(value, klass); impl->observer->onLayerPaintPropertyChanged(*this); } void SymbolLayer::setTextTranslateAnchorTransition(const TransitionOptions& value, const optional<std::string>& klass) { - impl->paint.setTransition<TextTranslateAnchor>(value, klass); + impl->cascading.template get<TextTranslateAnchor>().setTransition(value, klass); } TransitionOptions SymbolLayer::getTextTranslateAnchorTransition(const optional<std::string>& klass) const { - return impl->paint.getTransition<TextTranslateAnchor>(klass); + return impl->cascading.template get<TextTranslateAnchor>().getTransition(klass); } } // namespace style diff --git a/src/mbgl/style/layers/symbol_layer_impl.cpp b/src/mbgl/style/layers/symbol_layer_impl.cpp index 109d1c43e7..c99dd8ad70 100644 --- a/src/mbgl/style/layers/symbol_layer_impl.cpp +++ b/src/mbgl/style/layers/symbol_layer_impl.cpp @@ -1,101 +1,11 @@ #include <mbgl/style/layers/symbol_layer_impl.hpp> -#include <mbgl/style/property_evaluation_parameters.hpp> -#include <mbgl/layout/symbol_layout.hpp> -#include <mbgl/renderer/bucket.hpp> +#include <mbgl/renderer/render_symbol_layer.hpp> namespace mbgl { namespace style { -void SymbolLayer::Impl::cascade(const CascadeParameters& parameters) { - paint.cascade(parameters); -} - -bool SymbolLayer::Impl::evaluate(const PropertyEvaluationParameters& parameters) { - paint.evaluate(parameters); - - auto hasIconOpacity = paint.evaluated.get<IconColor>().constantOr(Color::black()).a > 0 || - paint.evaluated.get<IconHaloColor>().constantOr(Color::black()).a > 0; - auto hasTextOpacity = paint.evaluated.get<TextColor>().constantOr(Color::black()).a > 0 || - paint.evaluated.get<TextHaloColor>().constantOr(Color::black()).a > 0; - - passes = ((paint.evaluated.get<IconOpacity>().constantOr(1) > 0 && hasIconOpacity && iconSize > 0) - || (paint.evaluated.get<TextOpacity>().constantOr(1) > 0 && hasTextOpacity && textSize > 0)) - ? RenderPass::Translucent : RenderPass::None; - - return paint.hasTransition(); -} - -std::unique_ptr<Bucket> SymbolLayer::Impl::createBucket(const BucketParameters&, const std::vector<const Layer*>&) const { - assert(false); // Should be calling createLayout() instead. - return nullptr; -} - -std::unique_ptr<SymbolLayout> SymbolLayer::Impl::createLayout(const BucketParameters& parameters, - const std::vector<const Layer*>& group, - const GeometryTileLayer& layer, - GlyphDependencies& glyphDependencies, - IconDependencyMap& iconDependencyMap) const { - return std::make_unique<SymbolLayout>(parameters, - group, - layer, - iconDependencyMap[spriteAtlas], - (uintptr_t)spriteAtlas, - glyphDependencies); -} - -IconPaintProperties::Evaluated SymbolLayer::Impl::iconPaintProperties() const { - return IconPaintProperties::Evaluated { - paint.evaluated.get<IconOpacity>(), - paint.evaluated.get<IconColor>(), - paint.evaluated.get<IconHaloColor>(), - paint.evaluated.get<IconHaloWidth>(), - paint.evaluated.get<IconHaloBlur>(), - paint.evaluated.get<IconTranslate>(), - paint.evaluated.get<IconTranslateAnchor>() - }; -} - -TextPaintProperties::Evaluated SymbolLayer::Impl::textPaintProperties() const { - return TextPaintProperties::Evaluated { - paint.evaluated.get<TextOpacity>(), - paint.evaluated.get<TextColor>(), - paint.evaluated.get<TextHaloColor>(), - paint.evaluated.get<TextHaloWidth>(), - paint.evaluated.get<TextHaloBlur>(), - paint.evaluated.get<TextTranslate>(), - paint.evaluated.get<TextTranslateAnchor>() - }; -} - - -SymbolPropertyValues SymbolLayer::Impl::iconPropertyValues(const SymbolLayoutProperties::PossiblyEvaluated& layout_) const { - return SymbolPropertyValues { - layout_.get<IconRotationAlignment>(), // icon-pitch-alignment is not yet implemented; inherit the rotation alignment - layout_.get<IconRotationAlignment>(), - layout_.get<IconSize>(), - paint.evaluated.get<IconTranslate>(), - paint.evaluated.get<IconTranslateAnchor>(), - iconSize, - 1.0f, - paint.evaluated.get<IconHaloColor>().constantOr(Color::black()).a > 0 && - paint.evaluated.get<IconHaloWidth>().constantOr(1), - paint.evaluated.get<IconColor>().constantOr(Color::black()).a > 0 - }; -} - -SymbolPropertyValues SymbolLayer::Impl::textPropertyValues(const SymbolLayoutProperties::PossiblyEvaluated& layout_) const { - return SymbolPropertyValues { - layout_.get<TextPitchAlignment>(), - layout_.get<TextRotationAlignment>(), - layout_.get<TextSize>(), - paint.evaluated.get<TextTranslate>(), - paint.evaluated.get<TextTranslateAnchor>(), - textSize, - 24.0f, - paint.evaluated.get<TextHaloColor>().constantOr(Color::black()).a > 0 && - paint.evaluated.get<TextHaloWidth>().constantOr(1), - paint.evaluated.get<TextColor>().constantOr(Color::black()).a > 0 - }; +std::unique_ptr<RenderLayer> SymbolLayer::Impl::createRenderLayer() const { + return std::make_unique<RenderSymbolLayer>(*this); } } // namespace style diff --git a/src/mbgl/style/layers/symbol_layer_impl.hpp b/src/mbgl/style/layers/symbol_layer_impl.hpp index 3d81ff1f69..28079fa731 100644 --- a/src/mbgl/style/layers/symbol_layer_impl.hpp +++ b/src/mbgl/style/layers/symbol_layer_impl.hpp @@ -1,7 +1,5 @@ #pragma once -#include <mbgl/text/glyph.hpp> -#include <mbgl/util/variant.hpp> #include <mbgl/sprite/sprite_atlas.hpp> #include <mbgl/style/layer_impl.hpp> #include <mbgl/style/layers/symbol_layer.hpp> @@ -9,53 +7,7 @@ namespace mbgl { -class SymbolLayout; - namespace style { - - -// {icon,text}-specific paint-property packs for use in the symbol Programs. -// Since each program deals either with icons or text, using a smaller property set -// lets us avoid unnecessarily binding attributes for properties the program wouldn't use. -class IconPaintProperties : public PaintProperties< - IconOpacity, - IconColor, - IconHaloColor, - IconHaloWidth, - IconHaloBlur, - IconTranslate, - IconTranslateAnchor -> {}; - -class TextPaintProperties : public PaintProperties< - TextOpacity, - TextColor, - TextHaloColor, - TextHaloWidth, - TextHaloBlur, - TextTranslate, - TextTranslateAnchor -> {}; - -// Repackaging evaluated values from SymbolLayoutProperties + SymbolPaintProperties -// for genericity over icons vs. text. -class SymbolPropertyValues { -public: - // Layout - AlignmentType pitchAlignment; - AlignmentType rotationAlignment; - PossiblyEvaluatedPropertyValue<float> layoutSize; - - // Paint - std::array<float, 2> translate; - TranslateAnchorType translateAnchor; - float paintSize; - - float sdfScale; // Constant (1.0 or 24.0) - - bool hasHalo; - bool hasFill; -}; class SymbolLayer::Impl : public Layer::Impl { public: @@ -63,24 +15,10 @@ public: std::unique_ptr<Layer> cloneRef(const std::string& id) const override; void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override; - void cascade(const CascadeParameters&) override; - bool evaluate(const PropertyEvaluationParameters&) override; - - std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const Layer*>&) const override; - std::unique_ptr<SymbolLayout> createLayout(const BucketParameters&, const std::vector<const Layer*>&, - const GeometryTileLayer&, GlyphDependencies&, IconDependencyMap&) const; - - IconPaintProperties::Evaluated iconPaintProperties() const; - TextPaintProperties::Evaluated textPaintProperties() const; - - SymbolPropertyValues iconPropertyValues(const SymbolLayoutProperties::PossiblyEvaluated&) const; - SymbolPropertyValues textPropertyValues(const SymbolLayoutProperties::PossiblyEvaluated&) const; + std::unique_ptr<RenderLayer> createRenderLayer() const override; SymbolLayoutProperties layout; - SymbolPaintProperties paint; - - float iconSize = 1.0f; - float textSize = 16.0f; + SymbolPaintProperties::Cascading cascading; SpriteAtlas* spriteAtlas = nullptr; }; diff --git a/src/mbgl/style/paint_property.hpp b/src/mbgl/style/paint_property.hpp index 623acef804..7f7018748c 100644 --- a/src/mbgl/style/paint_property.hpp +++ b/src/mbgl/style/paint_property.hpp @@ -203,62 +203,44 @@ public: class Unevaluated : public Tuple<UnevaluatedTypes> { public: using Tuple<UnevaluatedTypes>::Tuple; - }; - class Cascading : public Tuple<CascadingTypes> { - public: - using Tuple<CascadingTypes>::Tuple; - }; - - template <class P> - auto get(const optional<std::string>& klass) const { - return cascading.template get<P>().get(klass); - } - - template <class P> - void set(const typename P::ValueType& value, const optional<std::string>& klass) { - cascading.template get<P>().set(value, klass); - } + bool hasTransition() const { + bool result = false; + util::ignore({ result |= this->template get<Ps>().hasTransition()... }); + return result; + } - template <class P> - void setTransition(const TransitionOptions& value, const optional<std::string>& klass) { - cascading.template get<P>().setTransition(value, klass); - } - - template <class P> - auto getTransition(const optional<std::string>& klass) const { - return cascading.template get<P>().getTransition(klass); - } + template <class P> + auto evaluate(const PropertyEvaluationParameters& parameters) { + using Evaluator = typename P::EvaluatorType; - void cascade(const CascadeParameters& parameters) { - unevaluated = Unevaluated { - cascading.template get<Ps>().cascade(parameters, - std::move(unevaluated.template get<Ps>()))... - }; - } + return this->template get<P>().evaluate( + Evaluator(parameters, P::defaultValue()), + parameters.now + ); + } - template <class P> - auto evaluate(const PropertyEvaluationParameters& parameters) { - using Evaluator = typename P::EvaluatorType; - return unevaluated.template get<P>() - .evaluate(Evaluator(parameters, P::defaultValue()), parameters.now); - } + Evaluated evaluate(const PropertyEvaluationParameters& parameters) { + return Evaluated { + evaluate<Ps>(parameters)... + }; + } - void evaluate(const PropertyEvaluationParameters& parameters) { - evaluated = Evaluated { - evaluate<Ps>(parameters)... - }; - } + }; - bool hasTransition() const { - bool result = false; - util::ignore({ result |= unevaluated.template get<Ps>().hasTransition()... }); - return result; - } + class Cascading : public Tuple<CascadingTypes> { + public: + using Tuple<CascadingTypes>::Tuple; - Cascading cascading; - Unevaluated unevaluated; - Evaluated evaluated; + Unevaluated cascade(const CascadeParameters& parameters, Unevaluated&& prior) const { + return Unevaluated { + this->template get<Ps>().cascade( + parameters, + std::move(prior.template get<Ps>()) + )... + }; + } + }; }; } // namespace style diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index fc1770e9ee..14efd6a07c 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -24,6 +24,14 @@ #include <mbgl/geometry/line_atlas.hpp> #include <mbgl/renderer/render_item.hpp> #include <mbgl/renderer/render_tile.hpp> +#include <mbgl/renderer/render_background_layer.hpp> +#include <mbgl/renderer/render_circle_layer.hpp> +#include <mbgl/renderer/render_custom_layer.hpp> +#include <mbgl/renderer/render_fill_extrusion_layer.hpp> +#include <mbgl/renderer/render_fill_layer.hpp> +#include <mbgl/renderer/render_line_layer.hpp> +#include <mbgl/renderer/render_raster_layer.hpp> +#include <mbgl/renderer/render_symbol_layer.hpp> #include <mbgl/util/constants.hpp> #include <mbgl/util/exception.hpp> #include <mbgl/util/geometry.hpp> @@ -104,6 +112,7 @@ TransitionOptions Style::getTransitionOptions() const { void Style::setJSON(const std::string& json) { sources.clear(); layers.clear(); + renderLayers.clear(); classes.clear(); transitionOptions = {}; updateBatch = {}; @@ -226,7 +235,9 @@ Layer* Style::addLayer(std::unique_ptr<Layer> layer, optional<std::string> befor layer->baseImpl->setObserver(this); - return layers.emplace(before ? findLayer(*before) : layers.end(), std::move(layer))->get(); + auto added = layers.emplace(before ? findLayer(*before) : layers.end(), std::move(layer))->get(); + renderLayers.emplace(before ? findRenderLayer(*before) : renderLayers.end(), added->baseImpl->createRenderLayer()); + return std::move(added); } std::unique_ptr<Layer> Style::removeLayer(const std::string& id) { @@ -244,9 +255,49 @@ std::unique_ptr<Layer> Style::removeLayer(const std::string& id) { } layers.erase(it); + removeRenderLayer(id); return layer; } +std::vector<const RenderLayer*> Style::getRenderLayers() const { + std::vector<const RenderLayer*> result; + result.reserve(renderLayers.size()); + for (const auto& layer : renderLayers) { + result.push_back(layer.get()); + } + return result; +} + +std::vector<RenderLayer*> Style::getRenderLayers() { + std::vector<RenderLayer*> result; + result.reserve(renderLayers.size()); + for (auto& layer : renderLayers) { + result.push_back(layer.get()); + } + return result; +} + +std::vector<std::unique_ptr<RenderLayer>>::const_iterator Style::findRenderLayer(const std::string& id) const { + return std::find_if(renderLayers.begin(), renderLayers.end(), [&](const auto& layer) { + return layer->baseImpl.id == id; + }); +} + +RenderLayer* Style::getRenderLayer(const std::string& id) const { + auto it = findRenderLayer(id); + return it != renderLayers.end() ? it->get() : nullptr; +} + +void Style::removeRenderLayer(const std::string& id) { + auto it = std::find_if(renderLayers.begin(), renderLayers.end(), [&](const auto& layer) { + return layer->baseImpl.id == id; + }); + + if (it != renderLayers.end()) { + renderLayers.erase(it); + } +} + std::string Style::getName() const { return name; } @@ -304,8 +355,8 @@ void Style::cascade(const TimePoint& timePoint, MapMode mode) { mode == MapMode::Continuous ? transitionOptions : immediateTransition }; - for (const auto& layer : layers) { - layer->baseImpl->cascade(parameters); + for (const auto& layer : renderLayers) { + layer->cascade(parameters); } } @@ -326,17 +377,17 @@ void Style::recalculate(float z, const TimePoint& timePoint, MapMode mode) { }; hasPendingTransitions = false; - for (const auto& layer : layers) { - hasPendingTransitions |= layer->baseImpl->evaluate(parameters); + for (const auto& layer : renderLayers) { + hasPendingTransitions |= layer->evaluate(parameters); // Disable this layer if it doesn't need to be rendered. - const bool needsRendering = layer->baseImpl->needsRendering(zoomHistory.lastZoom); + const bool needsRendering = layer->needsRendering(zoomHistory.lastZoom); if (!needsRendering) { continue; } // If this layer has a source, make sure that it gets loaded. - if (Source* source = getSource(layer->baseImpl->source)) { + if (Source* source = getSource(layer->baseImpl.source)) { source->baseImpl->enabled = true; if (!source->baseImpl->loaded) { source->baseImpl->loadDescription(fileSource); @@ -409,19 +460,19 @@ RenderData Style::getRenderData(MapDebugOptions debugOptions, float angle) const } } - for (const auto& layer : layers) { - if (!layer->baseImpl->needsRendering(zoomHistory.lastZoom)) { + for (const auto& layer : renderLayers) { + if (!layer->needsRendering(zoomHistory.lastZoom)) { continue; } - if (const BackgroundLayer* background = layer->as<BackgroundLayer>()) { + if (const RenderBackgroundLayer* background = layer->as<RenderBackgroundLayer>()) { if (debugOptions & MapDebugOptions::Overdraw) { // We want to skip glClear optimization in overdraw mode. result.order.emplace_back(*layer); continue; } - const BackgroundPaintProperties::Evaluated& paint = background->impl->paint.evaluated; - if (layer.get() == layers[0].get() && paint.get<BackgroundPattern>().from.empty()) { + const BackgroundPaintProperties::Evaluated& paint = background->evaluated; + if (layer.get() == renderLayers[0].get() && paint.get<BackgroundPattern>().from.empty()) { // This is a solid background. We can use glClear(). result.backgroundColor = paint.get<BackgroundColor>() * paint.get<BackgroundOpacity>(); } else { @@ -431,19 +482,19 @@ RenderData Style::getRenderData(MapDebugOptions debugOptions, float angle) const continue; } - if (layer->is<CustomLayer>()) { + if (layer->is<RenderCustomLayer>()) { result.order.emplace_back(*layer); continue; } - Source* source = getSource(layer->baseImpl->source); + Source* source = getSource(layer->baseImpl.source); if (!source) { - Log::Warning(Event::Render, "can't find source for layer '%s'", layer->baseImpl->id.c_str()); + Log::Warning(Event::Render, "can't find source for layer '%s'", layer->baseImpl.id.c_str()); continue; } auto& renderTiles = source->baseImpl->getRenderTiles(); - const bool symbolLayer = layer->is<SymbolLayer>(); + const bool symbolLayer = layer->is<RenderSymbolLayer>(); // Sort symbol tiles in opposite y position, so tiles with overlapping // symbols are drawn on top of each other, with lower symbols being @@ -529,11 +580,11 @@ std::vector<Feature> Style::queryRenderedFeatures(const ScreenLineString& geomet } // Combine all results based on the style layer order. - for (const auto& layer : layers) { - if (!layer->baseImpl->needsRendering(zoomHistory.lastZoom)) { + for (const auto& layer : renderLayers) { + if (!layer->needsRendering(zoomHistory.lastZoom)) { continue; } - auto it = resultsByLayer.find(layer->baseImpl->id); + auto it = resultsByLayer.find(layer->baseImpl.id); if (it != resultsByLayer.end()) { std::move(it->second.begin(), it->second.end(), std::back_inserter(result)); } diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp index 13097fbad8..127430a89f 100644 --- a/src/mbgl/style/style.hpp +++ b/src/mbgl/style/style.hpp @@ -5,6 +5,7 @@ #include <mbgl/style/source_observer.hpp> #include <mbgl/style/layer_observer.hpp> #include <mbgl/style/update_batch.hpp> +#include <mbgl/renderer/render_layer.hpp> #include <mbgl/text/glyph_atlas_observer.hpp> #include <mbgl/sprite/sprite_atlas_observer.hpp> #include <mbgl/map/mode.hpp> @@ -31,6 +32,7 @@ class RenderData; class TransformState; class RenderedQueryOptions; class Scheduler; +class RenderLayer; namespace style { @@ -80,6 +82,11 @@ public: optional<std::string> beforeLayerID = {}); std::unique_ptr<Layer> removeLayer(const std::string& layerID); + // Should be moved to Impl eventually + std::vector<const RenderLayer*> getRenderLayers() const; + std::vector<RenderLayer*> getRenderLayers(); + RenderLayer* getRenderLayer(const std::string& id) const; + std::string getName() const; LatLng getDefaultLatLng() const; double getDefaultZoom() const; @@ -116,6 +123,7 @@ public: private: std::vector<std::unique_ptr<Source>> sources; std::vector<std::unique_ptr<Layer>> layers; + std::vector<std::unique_ptr<RenderLayer>> renderLayers; std::vector<std::string> classes; TransitionOptions transitionOptions; @@ -127,6 +135,7 @@ private: double defaultPitch = 0; std::vector<std::unique_ptr<Layer>>::const_iterator findLayer(const std::string& layerID) const; + std::vector<std::unique_ptr<RenderLayer>>::const_iterator findRenderLayer(const std::string&) const; void reloadLayerSource(Layer&); // GlyphStoreObserver implementation. @@ -161,6 +170,7 @@ private: ZoomHistory zoomHistory; bool hasPendingTransitions = false; + void removeRenderLayer(const std::string& layerID); public: bool loaded = false; }; diff --git a/src/mbgl/tile/geometry_tile.cpp b/src/mbgl/tile/geometry_tile.cpp index d3406e1a59..b47519d95c 100644 --- a/src/mbgl/tile/geometry_tile.cpp +++ b/src/mbgl/tile/geometry_tile.cpp @@ -6,7 +6,9 @@ #include <mbgl/style/layer_impl.hpp> #include <mbgl/style/layers/background_layer.hpp> #include <mbgl/style/layers/custom_layer.hpp> -#include <mbgl/style/layers/symbol_layer.hpp> +#include <mbgl/renderer/render_background_layer.hpp> +#include <mbgl/renderer/render_custom_layer.hpp> +#include <mbgl/renderer/render_symbol_layer.hpp> #include <mbgl/style/style.hpp> #include <mbgl/storage/file_source.hpp> #include <mbgl/geometry/feature_index.hpp> @@ -159,9 +161,9 @@ void GeometryTile::getIcons(IconDependencyMap iconDependencyMap) { } } -Bucket* GeometryTile::getBucket(const Layer& layer) const { - const auto& buckets = layer.is<SymbolLayer>() ? symbolBuckets : nonSymbolBuckets; - const auto it = buckets.find(layer.baseImpl->id); +Bucket* GeometryTile::getBucket(const RenderLayer& layer) const { + const auto& buckets = layer.is<RenderSymbolLayer>() ? symbolBuckets : nonSymbolBuckets; + const auto it = buckets.find(layer.baseImpl.id); if (it == buckets.end()) { return nullptr; } diff --git a/src/mbgl/tile/geometry_tile.hpp b/src/mbgl/tile/geometry_tile.hpp index bfd036f3d5..3913fca812 100644 --- a/src/mbgl/tile/geometry_tile.hpp +++ b/src/mbgl/tile/geometry_tile.hpp @@ -18,10 +18,10 @@ namespace mbgl { class GeometryTileData; class FeatureIndex; class CollisionTile; +class RenderLayer; namespace style { class Style; -class Layer; class UpdateParameters; class SourceQueryOptions; } // namespace style @@ -46,7 +46,7 @@ public: void getGlyphs(GlyphDependencies); void getIcons(IconDependencyMap); - Bucket* getBucket(const style::Layer&) const override; + Bucket* getBucket(const RenderLayer&) const override; void queryRenderedFeatures( std::unordered_map<std::string, std::vector<Feature>>& result, diff --git a/src/mbgl/tile/geometry_tile_worker.cpp b/src/mbgl/tile/geometry_tile_worker.cpp index d9b720d226..b745cccc89 100644 --- a/src/mbgl/tile/geometry_tile_worker.cpp +++ b/src/mbgl/tile/geometry_tile_worker.cpp @@ -4,12 +4,12 @@ #include <mbgl/text/collision_tile.hpp> #include <mbgl/layout/symbol_layout.hpp> #include <mbgl/sprite/sprite_atlas.hpp> -#include <mbgl/style/bucket_parameters.hpp> -#include <mbgl/style/group_by_layout.hpp> +#include <mbgl/renderer/bucket_parameters.hpp> +#include <mbgl/renderer/group_by_layout.hpp> #include <mbgl/style/filter.hpp> #include <mbgl/style/filter_evaluator.hpp> -#include <mbgl/style/layers/symbol_layer.hpp> #include <mbgl/style/layers/symbol_layer_impl.hpp> +#include <mbgl/renderer/render_symbol_layer.hpp> #include <mbgl/renderer/symbol_bucket.hpp> #include <mbgl/util/logging.hpp> #include <mbgl/util/constants.hpp> @@ -252,6 +252,28 @@ void GeometryTileWorker::requestNewIcons(const IconDependencyMap &iconDependenci } } +static std::vector<std::unique_ptr<RenderLayer>> toRenderLayers(const std::vector<std::unique_ptr<style::Layer>>& layers, float zoom) { + std::vector<std::unique_ptr<RenderLayer>> renderLayers; + renderLayers.reserve(layers.size()); + for (auto& layer : layers) { + renderLayers.push_back(layer->baseImpl->createRenderLayer()); + + renderLayers.back()->cascade(style::CascadeParameters { + { ClassID::Default }, + Clock::time_point::max(), + TransitionOptions() + }); + + renderLayers.back()->evaluate(style::PropertyEvaluationParameters { + zoom, + Clock::time_point::max(), + ZoomHistory(), + Duration(0) + }); + } + return renderLayers; +} + void GeometryTileWorker::redoLayout() { if (!data || !layers) { return; @@ -272,7 +294,10 @@ void GeometryTileWorker::redoLayout() { GlyphDependencies glyphDependencies; IconDependencyMap iconDependencyMap; - std::vector<std::vector<const Layer*>> groups = groupByLayout(*layers); + // Create render layers and group by layout + std::vector<std::unique_ptr<RenderLayer>> renderLayers = toRenderLayers(*layers, id.overscaledZ); + std::vector<std::vector<const RenderLayer*>> groups = groupByLayout(renderLayers); + for (auto& group : groups) { if (obsolete) { return; @@ -282,9 +307,9 @@ void GeometryTileWorker::redoLayout() { continue; // Tile has no data. } - const Layer& leader = *group.at(0); + const RenderLayer& leader = *group.at(0); - auto geometryLayer = (*data)->getLayer(leader.baseImpl->sourceLayer); + auto geometryLayer = (*data)->getLayer(leader.baseImpl.sourceLayer); if (!geometryLayer) { continue; } @@ -296,13 +321,13 @@ void GeometryTileWorker::redoLayout() { featureIndex->setBucketLayerIDs(leader.getID(), layerIDs); - if (leader.is<SymbolLayer>()) { + if (leader.is<RenderSymbolLayer>()) { symbolLayoutMap.emplace(leader.getID(), - leader.as<SymbolLayer>()->impl->createLayout(parameters, group, *geometryLayer, glyphDependencies, iconDependencyMap)); + leader.as<RenderSymbolLayer>()->createLayout(parameters, group, *geometryLayer, glyphDependencies, iconDependencyMap)); } else { - const Filter& filter = leader.baseImpl->filter; - const std::string& sourceLayerID = leader.baseImpl->sourceLayer; - std::shared_ptr<Bucket> bucket = leader.baseImpl->createBucket(parameters, group); + const Filter& filter = leader.baseImpl.filter; + const std::string& sourceLayerID = leader.baseImpl.sourceLayer; + std::shared_ptr<Bucket> bucket = leader.createBucket(parameters, group); for (std::size_t i = 0; !obsolete && i < geometryLayer->featureCount(); i++) { std::unique_ptr<GeometryTileFeature> feature = geometryLayer->getFeature(i); diff --git a/src/mbgl/tile/geometry_tile_worker.hpp b/src/mbgl/tile/geometry_tile_worker.hpp index 5ce4260fdf..ab3b9d7403 100644 --- a/src/mbgl/tile/geometry_tile_worker.hpp +++ b/src/mbgl/tile/geometry_tile_worker.hpp @@ -17,6 +17,7 @@ class GeometryTile; class GeometryTileData; class GlyphAtlas; class SymbolLayout; +class RenderLayer; namespace style { class Layer; diff --git a/src/mbgl/tile/raster_tile.cpp b/src/mbgl/tile/raster_tile.cpp index 1e3c772200..65907eb92a 100644 --- a/src/mbgl/tile/raster_tile.cpp +++ b/src/mbgl/tile/raster_tile.cpp @@ -55,7 +55,7 @@ void RasterTile::onError(std::exception_ptr err) { observer->onTileError(*this, err); } -Bucket* RasterTile::getBucket(const style::Layer&) const { +Bucket* RasterTile::getBucket(const RenderLayer&) const { return bucket.get(); } diff --git a/src/mbgl/tile/raster_tile.hpp b/src/mbgl/tile/raster_tile.hpp index cc0dbe71de..47f67a0842 100644 --- a/src/mbgl/tile/raster_tile.hpp +++ b/src/mbgl/tile/raster_tile.hpp @@ -29,7 +29,7 @@ public: optional<Timestamp> expires_); void cancel() override; - Bucket* getBucket(const style::Layer&) const override; + Bucket* getBucket(const RenderLayer&) const override; void onParsed(std::unique_ptr<Bucket> result); void onError(std::exception_ptr); diff --git a/src/mbgl/tile/tile.hpp b/src/mbgl/tile/tile.hpp index b3085071c2..6c2c78967f 100644 --- a/src/mbgl/tile/tile.hpp +++ b/src/mbgl/tile/tile.hpp @@ -22,9 +22,9 @@ class TransformState; class TileObserver; class PlacementConfig; class RenderedQueryOptions; +class RenderLayer; namespace style { -class Layer; class SourceQueryOptions; } // namespace style @@ -47,7 +47,7 @@ public: // Mark this tile as no longer needed and cancel any pending work. virtual void cancel() = 0; - virtual Bucket* getBucket(const style::Layer&) const = 0; + virtual Bucket* getBucket(const RenderLayer&) const = 0; virtual void setPlacementConfig(const PlacementConfig&) {} virtual void redoLayout() {} diff --git a/test/gl/bucket.test.cpp b/test/gl/bucket.test.cpp index 5b66a0987f..e21d82321d 100644 --- a/test/gl/bucket.test.cpp +++ b/test/gl/bucket.test.cpp @@ -4,7 +4,7 @@ #include <mbgl/renderer/fill_bucket.hpp> #include <mbgl/renderer/line_bucket.hpp> #include <mbgl/renderer/symbol_bucket.hpp> -#include <mbgl/style/bucket_parameters.hpp> +#include <mbgl/renderer/bucket_parameters.hpp> #include <mbgl/style/layers/symbol_layer_properties.hpp> #include <mbgl/map/mode.hpp> diff --git a/test/style/group_by_layout.test.cpp b/test/renderer/group_by_layout.test.cpp index 600ba6a0f1..9c8e09e222 100644 --- a/test/style/group_by_layout.test.cpp +++ b/test/renderer/group_by_layout.test.cpp @@ -1,6 +1,7 @@ #include <mbgl/test/util.hpp> -#include <mbgl/style/group_by_layout.hpp> +#include <mbgl/renderer/group_by_layout.hpp> +#include <mbgl/renderer/render_layer.hpp> #include <mbgl/style/layers/background_layer.hpp> #include <mbgl/style/layers/circle_layer.hpp> #include <mbgl/style/layers/line_layer.hpp> @@ -8,11 +9,20 @@ using namespace mbgl; using namespace mbgl::style; +static std::vector<std::unique_ptr<RenderLayer>> toRenderLayers(const std::vector<std::unique_ptr<Layer>>& layers) { + std::vector<std::unique_ptr<RenderLayer>> result; + result.reserve(layers.size()); + for (auto& layer : layers) { + result.push_back(layer->baseImpl->createRenderLayer()); + } + return result; +} + TEST(GroupByLayout, Related) { std::vector<std::unique_ptr<Layer>> layers; layers.push_back(std::make_unique<LineLayer>("a", "source")); layers.push_back(std::make_unique<LineLayer>("b", "source")); - auto result = groupByLayout(layers); + auto result = groupByLayout(toRenderLayers(layers)); ASSERT_EQ(1u, result.size()); ASSERT_EQ(2u, result[0].size()); } @@ -21,7 +31,7 @@ TEST(GroupByLayout, UnrelatedType) { std::vector<std::unique_ptr<Layer>> layers; layers.push_back(std::make_unique<BackgroundLayer>("background")); layers.push_back(std::make_unique<CircleLayer>("circle", "source")); - auto result = groupByLayout(layers); + auto result = groupByLayout(toRenderLayers(layers)); ASSERT_EQ(2u, result.size()); } @@ -30,7 +40,7 @@ TEST(GroupByLayout, UnrelatedFilter) { layers.push_back(std::make_unique<LineLayer>("a", "source")); layers.push_back(std::make_unique<LineLayer>("b", "source")); layers[0]->as<LineLayer>()->setFilter(EqualsFilter()); - auto result = groupByLayout(layers); + auto result = groupByLayout(toRenderLayers(layers)); ASSERT_EQ(2u, result.size()); } @@ -39,6 +49,6 @@ TEST(GroupByLayout, UnrelatedLayout) { layers.push_back(std::make_unique<LineLayer>("a", "source")); layers.push_back(std::make_unique<LineLayer>("b", "source")); layers[0]->as<LineLayer>()->setLineCap(LineCapType::Square); - auto result = groupByLayout(layers); + auto result = groupByLayout(toRenderLayers(layers)); ASSERT_EQ(2u, result.size()); } diff --git a/test/style/conversion/layer.test.cpp b/test/style/conversion/layer.test.cpp index cfe2662fb8..ae8d4058ab 100644 --- a/test/style/conversion/layer.test.cpp +++ b/test/style/conversion/layer.test.cpp @@ -35,13 +35,13 @@ TEST(StyleConversion, LayerTransition) { } })JSON"); - ASSERT_EQ(400ms, *layer->as<BackgroundLayer>()->impl->paint.cascading + ASSERT_EQ(400ms, *layer->as<BackgroundLayer>()->impl->cascading .get<BackgroundColor>().getTransition({}).duration); - ASSERT_EQ(500ms, *layer->as<BackgroundLayer>()->impl->paint.cascading + ASSERT_EQ(500ms, *layer->as<BackgroundLayer>()->impl->cascading .get<BackgroundColor>().getTransition({}).delay); - ASSERT_EQ(100ms, *layer->as<BackgroundLayer>()->impl->paint.cascading + ASSERT_EQ(100ms, *layer->as<BackgroundLayer>()->impl->cascading .get<BackgroundColor>().getTransition({"class"}).duration); - ASSERT_FALSE(bool(layer->as<BackgroundLayer>()->impl->paint.cascading + ASSERT_FALSE(bool(layer->as<BackgroundLayer>()->impl->cascading .get<BackgroundColor>().getTransition({"class"}).delay)); } diff --git a/test/tile/geojson_tile.test.cpp b/test/tile/geojson_tile.test.cpp index e2a026b560..46cbe209b6 100644 --- a/test/tile/geojson_tile.test.cpp +++ b/test/tile/geojson_tile.test.cpp @@ -49,7 +49,7 @@ TEST(GeoJSONTile, Issue7648) { observer.tileChanged = [&] (const Tile&) { // Once present, the bucket should never "disappear", which would cause // flickering. - ASSERT_NE(nullptr, tile.getBucket(*test.style.getLayer("circle"))); + ASSERT_NE(nullptr, tile.getBucket(*test.style.getRenderLayer("circle"))); }; tile.setObserver(&observer); diff --git a/test/tile/vector_tile.test.cpp b/test/tile/vector_tile.test.cpp index fc6e9b3a6d..26c5dac8c0 100644 --- a/test/tile/vector_tile.test.cpp +++ b/test/tile/vector_tile.test.cpp @@ -89,7 +89,7 @@ TEST(VectorTile, Issue7615) { 0 }); - EXPECT_EQ(symbolBucket.get(), tile.getBucket(symbolLayer)); + EXPECT_EQ(symbolBucket.get(), tile.getBucket(*symbolLayer.baseImpl->createRenderLayer())); } TEST(VectorTile, Issue8542) { |