diff options
28 files changed, 104 insertions, 26 deletions
diff --git a/src/mbgl/renderer/bucket.hpp b/src/mbgl/renderer/bucket.hpp index 9af511a03e..f48593ae49 100644 --- a/src/mbgl/renderer/bucket.hpp +++ b/src/mbgl/renderer/bucket.hpp @@ -2,6 +2,7 @@ #include <mbgl/util/noncopyable.hpp> #include <mbgl/tile/geometry_tile_data.hpp> +#include <mbgl/style/layer_type.hpp> #include <atomic> @@ -15,9 +16,27 @@ class RenderLayer; class Bucket : private util::noncopyable { public: - Bucket() = default; + Bucket(style::LayerType layerType_) + : layerType(layerType_) { + } + virtual ~Bucket() = default; + // Check whether this bucket is of the given subtype. + template <class T> + bool is() const; + + // Dynamically cast this bucket 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; + } + // Feature geometries are also used to populate the feature index. // Obtaining these is a costly operation, so we do it only once, and // pass-by-const-ref the geometries as a second parameter. @@ -39,6 +58,7 @@ public: } protected: + style::LayerType layerType; std::atomic<bool> uploaded { false }; }; diff --git a/src/mbgl/renderer/buckets/circle_bucket.cpp b/src/mbgl/renderer/buckets/circle_bucket.cpp index c442b661de..d07c1f8dbe 100644 --- a/src/mbgl/renderer/buckets/circle_bucket.cpp +++ b/src/mbgl/renderer/buckets/circle_bucket.cpp @@ -11,7 +11,8 @@ namespace mbgl { using namespace style; CircleBucket::CircleBucket(const BucketParameters& parameters, const std::vector<const RenderLayer*>& layers) - : mode(parameters.mode) { + : Bucket(LayerType::Circle), + mode(parameters.mode) { for (const auto& layer : layers) { paintPropertyBinders.emplace( std::piecewise_construct, diff --git a/src/mbgl/renderer/buckets/circle_bucket.hpp b/src/mbgl/renderer/buckets/circle_bucket.hpp index 78b6351bcb..3c5f96fb15 100644 --- a/src/mbgl/renderer/buckets/circle_bucket.hpp +++ b/src/mbgl/renderer/buckets/circle_bucket.hpp @@ -37,4 +37,9 @@ public: const MapMode mode; }; +template <> +inline bool Bucket::is<CircleBucket>() const { + return layerType == style::LayerType::Circle; +} + } // namespace mbgl diff --git a/src/mbgl/renderer/buckets/fill_bucket.cpp b/src/mbgl/renderer/buckets/fill_bucket.cpp index 110db887a1..14be98c3af 100644 --- a/src/mbgl/renderer/buckets/fill_bucket.cpp +++ b/src/mbgl/renderer/buckets/fill_bucket.cpp @@ -27,7 +27,8 @@ using namespace style; struct GeometryTooLongException : std::exception {}; -FillBucket::FillBucket(const BucketParameters& parameters, const std::vector<const RenderLayer*>& layers) { +FillBucket::FillBucket(const BucketParameters& parameters, const std::vector<const RenderLayer*>& layers) + : Bucket(LayerType::Fill) { for (const auto& layer : layers) { paintPropertyBinders.emplace( std::piecewise_construct, diff --git a/src/mbgl/renderer/buckets/fill_bucket.hpp b/src/mbgl/renderer/buckets/fill_bucket.hpp index a50e1971f5..20b65da39c 100644 --- a/src/mbgl/renderer/buckets/fill_bucket.hpp +++ b/src/mbgl/renderer/buckets/fill_bucket.hpp @@ -39,4 +39,9 @@ public: std::map<std::string, FillProgram::PaintPropertyBinders> paintPropertyBinders; }; +template <> +inline bool Bucket::is<FillBucket>() const { + return layerType == style::LayerType::Fill; +} + } // namespace mbgl diff --git a/src/mbgl/renderer/buckets/fill_extrusion_bucket.cpp b/src/mbgl/renderer/buckets/fill_extrusion_bucket.cpp index 4fcc761280..c6dba38db1 100644 --- a/src/mbgl/renderer/buckets/fill_extrusion_bucket.cpp +++ b/src/mbgl/renderer/buckets/fill_extrusion_bucket.cpp @@ -34,7 +34,8 @@ using namespace style; struct GeometryTooLongException : std::exception {}; -FillExtrusionBucket::FillExtrusionBucket(const BucketParameters& parameters, const std::vector<const RenderLayer*>& layers) { +FillExtrusionBucket::FillExtrusionBucket(const BucketParameters& parameters, const std::vector<const RenderLayer*>& layers) + : Bucket(LayerType::FillExtrusion) { for (const auto& layer : layers) { paintPropertyBinders.emplace(std::piecewise_construct, std::forward_as_tuple(layer->getID()), diff --git a/src/mbgl/renderer/buckets/fill_extrusion_bucket.hpp b/src/mbgl/renderer/buckets/fill_extrusion_bucket.hpp index d57265ab16..ed98e01292 100644 --- a/src/mbgl/renderer/buckets/fill_extrusion_bucket.hpp +++ b/src/mbgl/renderer/buckets/fill_extrusion_bucket.hpp @@ -34,4 +34,9 @@ public: std::unordered_map<std::string, FillExtrusionProgram::PaintPropertyBinders> paintPropertyBinders; }; +template <> +inline bool Bucket::is<FillExtrusionBucket>() const { + return layerType == style::LayerType::FillExtrusion; +} + } // namespace mbgl diff --git a/src/mbgl/renderer/buckets/heatmap_bucket.cpp b/src/mbgl/renderer/buckets/heatmap_bucket.cpp index a185e04ad2..eff0c60280 100644 --- a/src/mbgl/renderer/buckets/heatmap_bucket.cpp +++ b/src/mbgl/renderer/buckets/heatmap_bucket.cpp @@ -11,7 +11,8 @@ namespace mbgl { using namespace style; HeatmapBucket::HeatmapBucket(const BucketParameters& parameters, const std::vector<const RenderLayer*>& layers) - : mode(parameters.mode) { + : Bucket(LayerType::Heatmap), + mode(parameters.mode) { for (const auto& layer : layers) { paintPropertyBinders.emplace( std::piecewise_construct, diff --git a/src/mbgl/renderer/buckets/heatmap_bucket.hpp b/src/mbgl/renderer/buckets/heatmap_bucket.hpp index 3b9f1edb81..86b6f10296 100644 --- a/src/mbgl/renderer/buckets/heatmap_bucket.hpp +++ b/src/mbgl/renderer/buckets/heatmap_bucket.hpp @@ -37,4 +37,9 @@ public: const MapMode mode; }; +template <> +inline bool Bucket::is<HeatmapBucket>() const { + return layerType == style::LayerType::Heatmap; +} + } // namespace mbgl diff --git a/src/mbgl/renderer/buckets/hillshade_bucket.cpp b/src/mbgl/renderer/buckets/hillshade_bucket.cpp index 00b9536894..3ca217a840 100644 --- a/src/mbgl/renderer/buckets/hillshade_bucket.cpp +++ b/src/mbgl/renderer/buckets/hillshade_bucket.cpp @@ -8,10 +8,14 @@ namespace mbgl { using namespace style; -HillshadeBucket::HillshadeBucket(PremultipliedImage&& image_, Tileset::DEMEncoding encoding): demdata(image_, encoding) { +HillshadeBucket::HillshadeBucket(PremultipliedImage&& image_, Tileset::DEMEncoding encoding) + : Bucket(LayerType::Hillshade), + demdata(image_, encoding) { } -HillshadeBucket::HillshadeBucket(DEMData&& demdata_) : demdata(std::move(demdata_)) { +HillshadeBucket::HillshadeBucket(DEMData&& demdata_) + : Bucket(LayerType::Hillshade), + demdata(std::move(demdata_)) { } const DEMData& HillshadeBucket::getDEMData() const { diff --git a/src/mbgl/renderer/buckets/hillshade_bucket.hpp b/src/mbgl/renderer/buckets/hillshade_bucket.hpp index 5335f7ceda..c9e435c661 100644 --- a/src/mbgl/renderer/buckets/hillshade_bucket.hpp +++ b/src/mbgl/renderer/buckets/hillshade_bucket.hpp @@ -56,4 +56,9 @@ private: bool prepared = false; }; +template <> +inline bool Bucket::is<HillshadeBucket>() const { + return layerType == style::LayerType::Hillshade; +} + } // namespace mbgl diff --git a/src/mbgl/renderer/buckets/line_bucket.cpp b/src/mbgl/renderer/buckets/line_bucket.cpp index a96518df38..a10551a7d2 100644 --- a/src/mbgl/renderer/buckets/line_bucket.cpp +++ b/src/mbgl/renderer/buckets/line_bucket.cpp @@ -14,7 +14,8 @@ using namespace style; LineBucket::LineBucket(const BucketParameters& parameters, const std::vector<const RenderLayer*>& layers, const style::LineLayoutProperties::Unevaluated& layout_) - : layout(layout_.evaluate(PropertyEvaluationParameters(parameters.tileID.overscaledZ))), + : Bucket(LayerType::Line), + layout(layout_.evaluate(PropertyEvaluationParameters(parameters.tileID.overscaledZ))), overscaling(parameters.tileID.overscaleFactor()), zoom(parameters.tileID.overscaledZ) { for (const auto& layer : layers) { diff --git a/src/mbgl/renderer/buckets/line_bucket.hpp b/src/mbgl/renderer/buckets/line_bucket.hpp index 4fb77c377e..8fe7184941 100644 --- a/src/mbgl/renderer/buckets/line_bucket.hpp +++ b/src/mbgl/renderer/buckets/line_bucket.hpp @@ -64,4 +64,9 @@ private: float getLineWidth(const RenderLineLayer& layer) const; }; +template <> +inline bool Bucket::is<LineBucket>() const { + return layerType == style::LayerType::Line; +} + } // namespace mbgl diff --git a/src/mbgl/renderer/buckets/raster_bucket.cpp b/src/mbgl/renderer/buckets/raster_bucket.cpp index a66dd42d74..45cf351d8e 100644 --- a/src/mbgl/renderer/buckets/raster_bucket.cpp +++ b/src/mbgl/renderer/buckets/raster_bucket.cpp @@ -7,12 +7,14 @@ namespace mbgl { using namespace style; -RasterBucket::RasterBucket(PremultipliedImage&& image_) { - image = std::make_shared<PremultipliedImage>(std::move(image_)); +RasterBucket::RasterBucket(PremultipliedImage&& image_) + : Bucket(LayerType::Raster), + image(std::make_shared<PremultipliedImage>(std::move(image_))) { } -RasterBucket::RasterBucket(std::shared_ptr<PremultipliedImage> image_): image(image_) { - +RasterBucket::RasterBucket(std::shared_ptr<PremultipliedImage> image_) + : Bucket(LayerType::Raster), + image(image_) { } void RasterBucket::upload(gl::Context& context) { diff --git a/src/mbgl/renderer/buckets/raster_bucket.hpp b/src/mbgl/renderer/buckets/raster_bucket.hpp index 3800eadec8..84b618a83d 100644 --- a/src/mbgl/renderer/buckets/raster_bucket.hpp +++ b/src/mbgl/renderer/buckets/raster_bucket.hpp @@ -38,4 +38,9 @@ public: optional<gl::IndexBuffer<gl::Triangles>> indexBuffer; }; +template <> +inline bool Bucket::is<RasterBucket>() const { + return layerType == style::LayerType::Raster; +} + } // namespace mbgl diff --git a/src/mbgl/renderer/buckets/symbol_bucket.cpp b/src/mbgl/renderer/buckets/symbol_bucket.cpp index 51fcd2437c..0a1530ae74 100644 --- a/src/mbgl/renderer/buckets/symbol_bucket.cpp +++ b/src/mbgl/renderer/buckets/symbol_bucket.cpp @@ -20,7 +20,8 @@ SymbolBucket::SymbolBucket(style::SymbolLayoutProperties::PossiblyEvaluated layo bool sortFeaturesByY_, const std::string bucketName_, const std::vector<SymbolInstance>&& symbolInstances_) - : layout(std::move(layout_)), + : Bucket(LayerType::Symbol), + layout(std::move(layout_)), sdfIcons(sdfIcons_), iconsNeedLinear(iconsNeedLinear_ || iconSize.isDataDriven() || !iconSize.isZoomConstant()), sortFeaturesByY(sortFeaturesByY_), diff --git a/src/mbgl/renderer/buckets/symbol_bucket.hpp b/src/mbgl/renderer/buckets/symbol_bucket.hpp index e4aaf5ba30..4f01cf4e1c 100644 --- a/src/mbgl/renderer/buckets/symbol_bucket.hpp +++ b/src/mbgl/renderer/buckets/symbol_bucket.hpp @@ -138,4 +138,9 @@ public: std::shared_ptr<std::vector<size_t>> featureSortOrder; }; +template <> +inline bool Bucket::is<SymbolBucket>() const { + return layerType == style::LayerType::Symbol; +} + } // namespace mbgl diff --git a/src/mbgl/renderer/layers/render_circle_layer.cpp b/src/mbgl/renderer/layers/render_circle_layer.cpp index b1b4d22561..ce63ada770 100644 --- a/src/mbgl/renderer/layers/render_circle_layer.cpp +++ b/src/mbgl/renderer/layers/render_circle_layer.cpp @@ -56,7 +56,7 @@ void RenderCircleLayer::render(PaintParameters& parameters, RenderSource*) { const bool pitchWithMap = evaluated.get<CirclePitchAlignment>() == AlignmentType::Map; for (const RenderTile& tile : renderTiles) { - auto bucket_ = dynamic_cast<CircleBucket*>(tile.tile.getBucket(*baseImpl)); + auto bucket_ = tile.tile.getBucket<CircleBucket>(*baseImpl); if (!bucket_) { continue; } diff --git a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp index d37f6f528b..2f720284fc 100644 --- a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp +++ b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp @@ -100,7 +100,7 @@ void RenderFillExtrusionLayer::render(PaintParameters& parameters, RenderSource* if (evaluated.get<FillExtrusionPattern>().from.empty()) { for (const RenderTile& tile : renderTiles) { - auto bucket_ = dynamic_cast<FillExtrusionBucket*>(tile.tile.getBucket(*baseImpl)); + auto bucket_ = tile.tile.getBucket<FillExtrusionBucket>(*baseImpl); if (!bucket_) { continue; } @@ -131,7 +131,7 @@ void RenderFillExtrusionLayer::render(PaintParameters& parameters, RenderSource* parameters.imageManager.bind(parameters.context, 0); for (const RenderTile& tile : renderTiles) { - auto bucket_ = dynamic_cast<FillExtrusionBucket*>(tile.tile.getBucket(*baseImpl)); + auto bucket_ = tile.tile.getBucket<FillExtrusionBucket>(*baseImpl); if (!bucket_) { continue; } diff --git a/src/mbgl/renderer/layers/render_fill_layer.cpp b/src/mbgl/renderer/layers/render_fill_layer.cpp index cce4399262..f03eb66c88 100644 --- a/src/mbgl/renderer/layers/render_fill_layer.cpp +++ b/src/mbgl/renderer/layers/render_fill_layer.cpp @@ -61,7 +61,7 @@ bool RenderFillLayer::hasTransition() const { void RenderFillLayer::render(PaintParameters& parameters, RenderSource*) { if (evaluated.get<FillPattern>().from.empty()) { for (const RenderTile& tile : renderTiles) { - auto bucket_ = dynamic_cast<FillBucket*>(tile.tile.getBucket(*baseImpl)); + auto bucket_ = tile.tile.getBucket<FillBucket>(*baseImpl); if (!bucket_) { continue; } @@ -149,7 +149,7 @@ void RenderFillLayer::render(PaintParameters& parameters, RenderSource*) { parameters.imageManager.bind(parameters.context, 0); for (const RenderTile& tile : renderTiles) { - auto bucket_ = dynamic_cast<FillBucket*>(tile.tile.getBucket(*baseImpl)); + auto bucket_ = tile.tile.getBucket<FillBucket>(*baseImpl); if (!bucket_) { continue; } diff --git a/src/mbgl/renderer/layers/render_heatmap_layer.cpp b/src/mbgl/renderer/layers/render_heatmap_layer.cpp index d2c6f6d970..c9ca477cbb 100644 --- a/src/mbgl/renderer/layers/render_heatmap_layer.cpp +++ b/src/mbgl/renderer/layers/render_heatmap_layer.cpp @@ -83,7 +83,7 @@ void RenderHeatmapLayer::render(PaintParameters& parameters, RenderSource*) { parameters.context.clear(Color{ 0.0f, 0.0f, 0.0f, 1.0f }, {}, {}); for (const RenderTile& tile : renderTiles) { - auto bucket_ = dynamic_cast<HeatmapBucket*>(tile.tile.getBucket(*baseImpl)); + auto bucket_ = tile.tile.getBucket<HeatmapBucket>(*baseImpl); if (!bucket_) { continue; } diff --git a/src/mbgl/renderer/layers/render_hillshade_layer.cpp b/src/mbgl/renderer/layers/render_hillshade_layer.cpp index 0edc8737c1..25eef98fcf 100644 --- a/src/mbgl/renderer/layers/render_hillshade_layer.cpp +++ b/src/mbgl/renderer/layers/render_hillshade_layer.cpp @@ -114,7 +114,7 @@ void RenderHillshadeLayer::render(PaintParameters& parameters, RenderSource* src matrix::translate(mat, mat, 0, -util::EXTENT, 0); for (const RenderTile& tile : renderTiles) { - auto bucket_ = dynamic_cast<HillshadeBucket*>(tile.tile.getBucket(*baseImpl)); + auto bucket_ = tile.tile.getBucket<HillshadeBucket>(*baseImpl); if (!bucket_) { continue; } diff --git a/src/mbgl/renderer/layers/render_line_layer.cpp b/src/mbgl/renderer/layers/render_line_layer.cpp index ea51705792..4b6ea35e67 100644 --- a/src/mbgl/renderer/layers/render_line_layer.cpp +++ b/src/mbgl/renderer/layers/render_line_layer.cpp @@ -58,7 +58,7 @@ void RenderLineLayer::render(PaintParameters& parameters, RenderSource*) { } for (const RenderTile& tile : renderTiles) { - auto bucket_ = dynamic_cast<LineBucket*>(tile.tile.getBucket(*baseImpl)); + auto bucket_ = tile.tile.getBucket<LineBucket>(*baseImpl); if (!bucket_) { continue; } diff --git a/src/mbgl/renderer/layers/render_raster_layer.cpp b/src/mbgl/renderer/layers/render_raster_layer.cpp index 13f2f5e38c..e2524697b5 100644 --- a/src/mbgl/renderer/layers/render_raster_layer.cpp +++ b/src/mbgl/renderer/layers/render_raster_layer.cpp @@ -142,7 +142,7 @@ void RenderRasterLayer::render(PaintParameters& parameters, RenderSource* source } } else { for (const RenderTile& tile : renderTiles) { - auto bucket_ = dynamic_cast<RasterBucket*>(tile.tile.getBucket(*baseImpl)); + auto bucket_ = tile.tile.getBucket<RasterBucket>(*baseImpl); if (!bucket_) { continue; } diff --git a/src/mbgl/renderer/layers/render_symbol_layer.cpp b/src/mbgl/renderer/layers/render_symbol_layer.cpp index d397ffd724..63fcb6cfd5 100644 --- a/src/mbgl/renderer/layers/render_symbol_layer.cpp +++ b/src/mbgl/renderer/layers/render_symbol_layer.cpp @@ -75,7 +75,7 @@ void RenderSymbolLayer::render(PaintParameters& parameters, RenderSource*) { } for (const RenderTile& tile : renderTiles) { - auto bucket_ = dynamic_cast<SymbolBucket*>(tile.tile.getBucket(*baseImpl)); + auto bucket_ = tile.tile.getBucket<SymbolBucket>(*baseImpl); if (!bucket_) { continue; } diff --git a/src/mbgl/text/cross_tile_symbol_index.cpp b/src/mbgl/text/cross_tile_symbol_index.cpp index 58dcda46f5..98b9af1f94 100644 --- a/src/mbgl/text/cross_tile_symbol_index.cpp +++ b/src/mbgl/text/cross_tile_symbol_index.cpp @@ -178,7 +178,7 @@ bool CrossTileSymbolIndex::addLayer(RenderSymbolLayer& symbolLayer, float lng) { continue; } - auto bucket = dynamic_cast<SymbolBucket*>(renderTile.tile.getBucket(*symbolLayer.baseImpl)); + auto bucket = renderTile.tile.getBucket<SymbolBucket>(*symbolLayer.baseImpl); if (!bucket) { continue; } diff --git a/src/mbgl/text/placement.cpp b/src/mbgl/text/placement.cpp index 96c1873e33..16dd94b374 100644 --- a/src/mbgl/text/placement.cpp +++ b/src/mbgl/text/placement.cpp @@ -51,7 +51,7 @@ void Placement::placeLayer(RenderSymbolLayer& symbolLayer, const mat4& projMatri assert(dynamic_cast<GeometryTile*>(&renderTile.tile)); GeometryTile& geometryTile = static_cast<GeometryTile&>(renderTile.tile); - auto bucket = dynamic_cast<SymbolBucket*>(geometryTile.getBucket(*symbolLayer.baseImpl)); + auto bucket = renderTile.tile.getBucket<SymbolBucket>(*symbolLayer.baseImpl); if (!bucket) { continue; } @@ -232,7 +232,7 @@ void Placement::updateLayerOpacities(RenderSymbolLayer& symbolLayer) { continue; } - auto bucket = dynamic_cast<SymbolBucket*>(renderTile.tile.getBucket(*symbolLayer.baseImpl)); + auto bucket = renderTile.tile.getBucket<SymbolBucket>(*symbolLayer.baseImpl); if (!bucket) { continue; } diff --git a/src/mbgl/tile/tile.hpp b/src/mbgl/tile/tile.hpp index 2182ec722f..5cf74abff5 100644 --- a/src/mbgl/tile/tile.hpp +++ b/src/mbgl/tile/tile.hpp @@ -48,6 +48,12 @@ public: virtual void upload(gl::Context&) = 0; virtual Bucket* getBucket(const style::Layer::Impl&) const = 0; + template <class T> + T* getBucket(const style::Layer::Impl& layer) const { + Bucket* bucket = getBucket(layer); + return bucket ? bucket->as<T>() : nullptr; + } + virtual void setShowCollisionBoxes(const bool) {} virtual void setLayers(const std::vector<Immutable<style::Layer::Impl>>&) {} virtual void setMask(TileMask&&) {} |