diff options
author | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2018-12-21 14:14:03 +0200 |
---|---|---|
committer | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2019-01-04 11:51:33 +0200 |
commit | c621b8100d8f75a77789371d8c33a7f5dff18651 (patch) | |
tree | c9b1290a8496d28f0f55f91ae79d58da0ed945e6 | |
parent | 4e86bca5abecdaa6dcdc361421fe73655e7e1b69 (diff) | |
download | qtlocation-mapboxgl-c621b8100d8f75a77789371d8c33a7f5dff18651.tar.gz |
[core] Drop LayerType
Drop LayerType and its remaining usages.
The generic code should be layer type agnostic.
24 files changed, 100 insertions, 123 deletions
diff --git a/cmake/core-files.txt b/cmake/core-files.txt index 58a4a5a6e7..32c8b76ad3 100644 --- a/cmake/core-files.txt +++ b/cmake/core-files.txt @@ -401,7 +401,6 @@ include/mbgl/style/conversion_impl.hpp include/mbgl/style/filter.hpp include/mbgl/style/image.hpp include/mbgl/style/layer.hpp -include/mbgl/style/layer_type.hpp include/mbgl/style/light.hpp include/mbgl/style/position.hpp include/mbgl/style/property_expression.hpp diff --git a/include/mbgl/style/layer.hpp b/include/mbgl/style/layer.hpp index bd0905cd6d..c526182033 100644 --- a/include/mbgl/style/layer.hpp +++ b/include/mbgl/style/layer.hpp @@ -3,7 +3,6 @@ #include <mbgl/util/peer.hpp> #include <mbgl/util/immutable.hpp> #include <mbgl/util/optional.hpp> -#include <mbgl/style/layer_type.hpp> #include <mbgl/style/types.hpp> #include <mbgl/style/conversion.hpp> diff --git a/include/mbgl/style/layer_type.hpp b/include/mbgl/style/layer_type.hpp deleted file mode 100644 index 0987ea4d0a..0000000000 --- a/include/mbgl/style/layer_type.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -namespace mbgl { -namespace style { - -enum class LayerType { - Fill, - Line, - Circle, - Symbol, - Raster, - Hillshade, - Background, - Custom, - FillExtrusion, - Heatmap, -}; - -} // namespace style -} // namespace mbgl diff --git a/src/mbgl/layout/layout.hpp b/src/mbgl/layout/layout.hpp index de2d28728f..601c5fb184 100644 --- a/src/mbgl/layout/layout.hpp +++ b/src/mbgl/layout/layout.hpp @@ -1,6 +1,5 @@ #pragma once -#include <mbgl/style/layer_type.hpp> #include <mbgl/renderer/image_atlas.hpp> #include <mbgl/text/glyph_atlas.hpp> #include <memory> diff --git a/src/mbgl/renderer/bucket.hpp b/src/mbgl/renderer/bucket.hpp index 7ccab8672d..6a7944a395 100644 --- a/src/mbgl/renderer/bucket.hpp +++ b/src/mbgl/renderer/bucket.hpp @@ -1,10 +1,9 @@ #pragma once -#include <mbgl/util/noncopyable.hpp> #include <mbgl/tile/geometry_tile_data.hpp> -#include <mbgl/style/layer_type.hpp> #include <mbgl/style/image_impl.hpp> #include <mbgl/renderer/image_atlas.hpp> +#include <mbgl/style/layer_impl.hpp> #include <atomic> namespace mbgl { @@ -17,29 +16,13 @@ class RenderLayer; class PatternDependency; using PatternLayerMap = std::unordered_map<std::string, PatternDependency>; -class Bucket : private util::noncopyable { +class Bucket { public: - Bucket(style::LayerType layerType_) - : layerType(layerType_) { - } + Bucket(const Bucket&) = delete; + Bucket& operator=(const Bucket&) = delete; 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. @@ -64,9 +47,14 @@ public: bool needsUpload() const { return hasData() && !uploaded; } + // Returns true if this bucket fits the given layer; returns false otherwise. + // Implementations of this class check at least that this bucket has + // the same layer type with the given layer, but extra checks are also + // possible. + virtual bool supportsLayer(const style::Layer::Impl&) const = 0; protected: - style::LayerType layerType; + Bucket() = default; std::atomic<bool> uploaded { false }; }; diff --git a/src/mbgl/renderer/buckets/circle_bucket.cpp b/src/mbgl/renderer/buckets/circle_bucket.cpp index 51da3eb892..b2d8d8ee98 100644 --- a/src/mbgl/renderer/buckets/circle_bucket.cpp +++ b/src/mbgl/renderer/buckets/circle_bucket.cpp @@ -11,8 +11,7 @@ namespace mbgl { using namespace style; CircleBucket::CircleBucket(const BucketParameters& parameters, const std::vector<const RenderLayer*>& layers) - : Bucket(LayerType::Circle), - mode(parameters.mode) { + : mode(parameters.mode) { for (const auto& layer : layers) { paintPropertyBinders.emplace( std::piecewise_construct, @@ -23,6 +22,8 @@ CircleBucket::CircleBucket(const BucketParameters& parameters, const std::vector } } +CircleBucket::~CircleBucket() = default; + void CircleBucket::upload(gl::Context& context) { vertexBuffer = context.createVertexBuffer(std::move(vertices)); indexBuffer = context.createIndexBuffer(std::move(triangles)); @@ -38,6 +39,10 @@ bool CircleBucket::hasData() const { return !segments.empty(); } +bool CircleBucket::supportsLayer(const style::Layer::Impl& impl) const { + return style::CircleLayer::Impl::staticTypeInfo() == impl.getTypeInfo(); +} + void CircleBucket::addFeature(const GeometryTileFeature& feature, const GeometryCollection& geometry, const ImagePositions&, diff --git a/src/mbgl/renderer/buckets/circle_bucket.hpp b/src/mbgl/renderer/buckets/circle_bucket.hpp index db61a0c112..dad8b8b377 100644 --- a/src/mbgl/renderer/buckets/circle_bucket.hpp +++ b/src/mbgl/renderer/buckets/circle_bucket.hpp @@ -13,9 +13,10 @@ namespace mbgl { class BucketParameters; -class CircleBucket : public Bucket { +class CircleBucket final : public Bucket { public: CircleBucket(const BucketParameters&, const std::vector<const RenderLayer*>&); + ~CircleBucket() override; void addFeature(const GeometryTileFeature&, const GeometryCollection&, @@ -27,6 +28,7 @@ public: void upload(gl::Context&) override; float getQueryRadius(const RenderLayer&) const override; + bool supportsLayer(const style::Layer::Impl&) const override; gl::VertexVector<CircleLayoutVertex> vertices; gl::IndexVector<gl::Triangles> triangles; @@ -40,9 +42,4 @@ 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 043882f138..517c9b184a 100644 --- a/src/mbgl/renderer/buckets/fill_bucket.cpp +++ b/src/mbgl/renderer/buckets/fill_bucket.cpp @@ -30,8 +30,7 @@ struct GeometryTooLongException : std::exception {}; FillBucket::FillBucket(const FillBucket::PossiblyEvaluatedLayoutProperties, std::map<std::string, FillBucket::PossiblyEvaluatedPaintProperties> layerPaintProperties, const float zoom, - const uint32_t) - : Bucket(LayerType::Fill) { + const uint32_t) { for (const auto& pair : layerPaintProperties) { paintPropertyBinders.emplace( @@ -43,6 +42,8 @@ FillBucket::FillBucket(const FillBucket::PossiblyEvaluatedLayoutProperties, } } +FillBucket::~FillBucket() = default; + void FillBucket::addFeature(const GeometryTileFeature& feature, const GeometryCollection& geometry, const ImagePositions& patternPositions, @@ -136,6 +137,11 @@ bool FillBucket::hasData() const { return !triangleSegments.empty() || !lineSegments.empty(); } +bool FillBucket::supportsLayer(const style::Layer::Impl& impl) const { + return style::FillLayer::Impl::staticTypeInfo() == impl.getTypeInfo(); +} + + float FillBucket::getQueryRadius(const RenderLayer& layer) const { const RenderFillLayer* fillLayer = toRenderFillLayer(&layer); const std::array<float, 2>& translate = fillLayer->evaluated.get<FillTranslate>(); diff --git a/src/mbgl/renderer/buckets/fill_bucket.hpp b/src/mbgl/renderer/buckets/fill_bucket.hpp index 47e273d4d2..2724e5b7d3 100644 --- a/src/mbgl/renderer/buckets/fill_bucket.hpp +++ b/src/mbgl/renderer/buckets/fill_bucket.hpp @@ -15,9 +15,9 @@ namespace mbgl { class BucketParameters; class RenderFillLayer; -class FillBucket : public Bucket { +class FillBucket final : public Bucket { public: - + ~FillBucket() override; // These aliases are used by the PatternLayout template using RenderLayerType = RenderFillLayer; using PossiblyEvaluatedPaintProperties = style::FillPaintProperties::PossiblyEvaluated; @@ -38,6 +38,7 @@ public: void upload(gl::Context&) override; float getQueryRadius(const RenderLayer&) const override; + bool supportsLayer(const style::Layer::Impl&) const override; gl::VertexVector<FillLayoutVertex> vertices; gl::IndexVector<gl::Lines> lines; @@ -52,9 +53,4 @@ 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 177c6e0c23..7b932e6b2b 100644 --- a/src/mbgl/renderer/buckets/fill_extrusion_bucket.cpp +++ b/src/mbgl/renderer/buckets/fill_extrusion_bucket.cpp @@ -37,9 +37,7 @@ struct GeometryTooLongException : std::exception {}; FillExtrusionBucket::FillExtrusionBucket(const FillExtrusionBucket::PossiblyEvaluatedLayoutProperties, std::map<std::string, FillExtrusionBucket::PossiblyEvaluatedPaintProperties> layerPaintProperties, const float zoom, - const uint32_t) - : Bucket(LayerType::FillExtrusion) { - + const uint32_t) { for (const auto& pair : layerPaintProperties) { paintPropertyBinders.emplace( std::piecewise_construct, @@ -50,6 +48,8 @@ FillExtrusionBucket::FillExtrusionBucket(const FillExtrusionBucket::PossiblyEval } } +FillExtrusionBucket::~FillExtrusionBucket() = default; + void FillExtrusionBucket::addFeature(const GeometryTileFeature& feature, const GeometryCollection& geometry, const ImagePositions& patternPositions, @@ -180,6 +180,10 @@ bool FillExtrusionBucket::hasData() const { return !triangleSegments.empty(); } +bool FillExtrusionBucket::supportsLayer(const style::Layer::Impl& impl) const { + return style::FillExtrusionLayer::Impl::staticTypeInfo() == impl.getTypeInfo(); +} + float FillExtrusionBucket::getQueryRadius(const RenderLayer& layer) const { const RenderFillExtrusionLayer* fillExtrusionLayer = toRenderFillExtrusionLayer(&layer); const std::array<float, 2>& translate = fillExtrusionLayer->evaluated.get<FillExtrusionTranslate>(); diff --git a/src/mbgl/renderer/buckets/fill_extrusion_bucket.hpp b/src/mbgl/renderer/buckets/fill_extrusion_bucket.hpp index 362a9f4c99..42344c4b8d 100644 --- a/src/mbgl/renderer/buckets/fill_extrusion_bucket.hpp +++ b/src/mbgl/renderer/buckets/fill_extrusion_bucket.hpp @@ -13,9 +13,9 @@ namespace mbgl { class BucketParameters; class RenderFillExtrusionLayer; -class FillExtrusionBucket : public Bucket { +class FillExtrusionBucket final : public Bucket { public: - + ~FillExtrusionBucket() override; // These aliases are used by the PatternLayout template using RenderLayerType = RenderFillExtrusionLayer; using PossiblyEvaluatedPaintProperties = style::FillExtrusionPaintProperties::PossiblyEvaluated; @@ -33,6 +33,8 @@ public: bool hasData() const override; + bool supportsLayer(const style::Layer::Impl&) const override; + void upload(gl::Context&) override; float getQueryRadius(const RenderLayer&) const override; @@ -47,9 +49,4 @@ 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 ee7db9a1df..28d2efe302 100644 --- a/src/mbgl/renderer/buckets/heatmap_bucket.cpp +++ b/src/mbgl/renderer/buckets/heatmap_bucket.cpp @@ -11,8 +11,7 @@ namespace mbgl { using namespace style; HeatmapBucket::HeatmapBucket(const BucketParameters& parameters, const std::vector<const RenderLayer*>& layers) - : Bucket(LayerType::Heatmap), - mode(parameters.mode) { + : mode(parameters.mode) { for (const auto& layer : layers) { paintPropertyBinders.emplace( std::piecewise_construct, @@ -23,6 +22,8 @@ HeatmapBucket::HeatmapBucket(const BucketParameters& parameters, const std::vect } } +HeatmapBucket::~HeatmapBucket() = default; + void HeatmapBucket::upload(gl::Context& context) { vertexBuffer = context.createVertexBuffer(std::move(vertices)); indexBuffer = context.createIndexBuffer(std::move(triangles)); @@ -38,6 +39,10 @@ bool HeatmapBucket::hasData() const { return !segments.empty(); } +bool HeatmapBucket::supportsLayer(const style::Layer::Impl& impl) const { + return style::HeatmapLayer::Impl::staticTypeInfo() == impl.getTypeInfo(); +} + void HeatmapBucket::addFeature(const GeometryTileFeature& feature, const GeometryCollection& geometry, const ImagePositions&, diff --git a/src/mbgl/renderer/buckets/heatmap_bucket.hpp b/src/mbgl/renderer/buckets/heatmap_bucket.hpp index b2d866d2a2..9bec9208a8 100644 --- a/src/mbgl/renderer/buckets/heatmap_bucket.hpp +++ b/src/mbgl/renderer/buckets/heatmap_bucket.hpp @@ -13,9 +13,10 @@ namespace mbgl { class BucketParameters; -class HeatmapBucket : public Bucket { +class HeatmapBucket final : public Bucket { public: HeatmapBucket(const BucketParameters&, const std::vector<const RenderLayer*>&); + ~HeatmapBucket() override; void addFeature(const GeometryTileFeature&, const GeometryCollection&, @@ -26,6 +27,7 @@ public: void upload(gl::Context&) override; float getQueryRadius(const RenderLayer&) const override; + bool supportsLayer(const style::Layer::Impl&) const override; gl::VertexVector<HeatmapLayoutVertex> vertices; gl::IndexVector<gl::Triangles> triangles; @@ -39,9 +41,4 @@ 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 3ca217a840..8dda9dd376 100644 --- a/src/mbgl/renderer/buckets/hillshade_bucket.cpp +++ b/src/mbgl/renderer/buckets/hillshade_bucket.cpp @@ -9,15 +9,15 @@ namespace mbgl { using namespace style; HillshadeBucket::HillshadeBucket(PremultipliedImage&& image_, Tileset::DEMEncoding encoding) - : Bucket(LayerType::Hillshade), - demdata(image_, encoding) { + : demdata(image_, encoding) { } HillshadeBucket::HillshadeBucket(DEMData&& demdata_) - : Bucket(LayerType::Hillshade), - demdata(std::move(demdata_)) { + : demdata(std::move(demdata_)) { } +HillshadeBucket::~HillshadeBucket() = default; + const DEMData& HillshadeBucket::getDEMData() const { return demdata; } @@ -114,4 +114,9 @@ bool HillshadeBucket::hasData() const { return demdata.getImage()->valid(); } +bool HillshadeBucket::supportsLayer(const style::Layer::Impl& impl) const { + return style::HillshadeLayer::Impl::staticTypeInfo() == impl.getTypeInfo(); +} + + } // namespace mbgl diff --git a/src/mbgl/renderer/buckets/hillshade_bucket.hpp b/src/mbgl/renderer/buckets/hillshade_bucket.hpp index c9e435c661..c5e58198ee 100644 --- a/src/mbgl/renderer/buckets/hillshade_bucket.hpp +++ b/src/mbgl/renderer/buckets/hillshade_bucket.hpp @@ -15,15 +15,16 @@ namespace mbgl { -class HillshadeBucket : public Bucket { +class HillshadeBucket final : public Bucket { public: HillshadeBucket(PremultipliedImage&&, Tileset::DEMEncoding encoding); HillshadeBucket(std::shared_ptr<PremultipliedImage>, Tileset::DEMEncoding encoding); HillshadeBucket(DEMData&&); - + ~HillshadeBucket() override; void upload(gl::Context&) override; bool hasData() const override; + bool supportsLayer(const style::Layer::Impl&) const override; void clear(); void setMask(TileMask&&); @@ -56,9 +57,4 @@ 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 ace6c8bfae..0375c3d089 100644 --- a/src/mbgl/renderer/buckets/line_bucket.cpp +++ b/src/mbgl/renderer/buckets/line_bucket.cpp @@ -14,8 +14,7 @@ LineBucket::LineBucket(const style::LineLayoutProperties::PossiblyEvaluated layo std::map<std::string, RenderLinePaintProperties::PossiblyEvaluated> layerPaintProperties, const float zoom_, const uint32_t overscaling_) - : Bucket(LayerType::Line), - layout(layout_), + : layout(layout_), zoom(zoom_), overscaling(overscaling_) { @@ -29,6 +28,7 @@ LineBucket::LineBucket(const style::LineLayoutProperties::PossiblyEvaluated layo } } +LineBucket::~LineBucket() = default; void LineBucket::addFeature(const GeometryTileFeature& feature, const GeometryCollection& geometryCollection, @@ -523,6 +523,10 @@ bool LineBucket::hasData() const { return !segments.empty(); } +bool LineBucket::supportsLayer(const style::Layer::Impl& impl) const { + return style::LineLayer::Impl::staticTypeInfo() == impl.getTypeInfo(); +} + template <class Property> static float get(const RenderLineLayer& layer, const std::map<std::string, LineProgram::PaintPropertyBinders>& paintPropertyBinders) { auto it = paintPropertyBinders.find(layer.getID()); diff --git a/src/mbgl/renderer/buckets/line_bucket.hpp b/src/mbgl/renderer/buckets/line_bucket.hpp index 6bd37076de..ed742a0e63 100644 --- a/src/mbgl/renderer/buckets/line_bucket.hpp +++ b/src/mbgl/renderer/buckets/line_bucket.hpp @@ -15,7 +15,7 @@ namespace mbgl { class BucketParameters; class RenderLineLayer; -class LineBucket : public Bucket { +class LineBucket final : public Bucket { public: // These aliases are used by the PatternLayout template @@ -27,6 +27,7 @@ public: std::map<std::string, PossiblyEvaluatedPaintProperties> layerPaintProperties, const float zoom, const uint32_t overscaling); + ~LineBucket() override; void addFeature(const GeometryTileFeature&, const GeometryCollection&, @@ -38,6 +39,7 @@ public: void upload(gl::Context&) override; float getQueryRadius(const RenderLayer&) const override; + bool supportsLayer(const style::Layer::Impl&) const override; PossiblyEvaluatedLayoutProperties layout; @@ -79,9 +81,4 @@ 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 45cf351d8e..47d6d0b96f 100644 --- a/src/mbgl/renderer/buckets/raster_bucket.cpp +++ b/src/mbgl/renderer/buckets/raster_bucket.cpp @@ -8,15 +8,15 @@ namespace mbgl { using namespace style; RasterBucket::RasterBucket(PremultipliedImage&& image_) - : Bucket(LayerType::Raster), - image(std::make_shared<PremultipliedImage>(std::move(image_))) { + : image(std::make_shared<PremultipliedImage>(std::move(image_))) { } RasterBucket::RasterBucket(std::shared_ptr<PremultipliedImage> image_) - : Bucket(LayerType::Raster), - image(image_) { + : image(std::move(image_)) { } +RasterBucket::~RasterBucket() = default; + void RasterBucket::upload(gl::Context& context) { if (!hasData()) { return; @@ -109,4 +109,9 @@ bool RasterBucket::hasData() const { return !!image; } +bool RasterBucket::supportsLayer(const style::Layer::Impl& impl) const { + return style::RasterLayer::Impl::staticTypeInfo() == impl.getTypeInfo(); +} + + } // namespace mbgl diff --git a/src/mbgl/renderer/buckets/raster_bucket.hpp b/src/mbgl/renderer/buckets/raster_bucket.hpp index 84b618a83d..e4f6fb04af 100644 --- a/src/mbgl/renderer/buckets/raster_bucket.hpp +++ b/src/mbgl/renderer/buckets/raster_bucket.hpp @@ -12,13 +12,15 @@ namespace mbgl { -class RasterBucket : public Bucket { +class RasterBucket final : public Bucket { public: RasterBucket(PremultipliedImage&&); RasterBucket(std::shared_ptr<PremultipliedImage>); + ~RasterBucket() override; void upload(gl::Context&) override; bool hasData() const override; + bool supportsLayer(const style::Layer::Impl&) const override; void clear(); void setImage(std::shared_ptr<PremultipliedImage>); @@ -38,9 +40,4 @@ 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 a3f652fc6e..93870b287b 100644 --- a/src/mbgl/renderer/buckets/symbol_bucket.cpp +++ b/src/mbgl/renderer/buckets/symbol_bucket.cpp @@ -20,8 +20,7 @@ SymbolBucket::SymbolBucket(style::SymbolLayoutProperties::PossiblyEvaluated layo bool sortFeaturesByY_, const std::string bucketName_, const std::vector<SymbolInstance>&& symbolInstances_) - : Bucket(LayerType::Symbol), - layout(std::move(layout_)), + : layout(std::move(layout_)), sdfIcons(sdfIcons_), iconsNeedLinear(iconsNeedLinear_ || iconSize.isDataDriven() || !iconSize.isZoomConstant()), sortFeaturesByY(sortFeaturesByY_), @@ -41,6 +40,8 @@ SymbolBucket::SymbolBucket(style::SymbolLayoutProperties::PossiblyEvaluated layo } } +SymbolBucket::~SymbolBucket() = default; + void SymbolBucket::upload(gl::Context& context) { if (hasTextData()) { if (!staticUploaded) { @@ -127,6 +128,10 @@ bool SymbolBucket::hasData() const { return hasTextData() || hasIconData() || hasCollisionBoxData(); } +bool SymbolBucket::supportsLayer(const style::Layer::Impl& impl) const { + return style::SymbolLayer::Impl::staticTypeInfo() == impl.getTypeInfo(); +} + bool SymbolBucket::hasTextData() const { return !text.segments.empty(); } diff --git a/src/mbgl/renderer/buckets/symbol_bucket.hpp b/src/mbgl/renderer/buckets/symbol_bucket.hpp index 5addff40b2..ccb2cce513 100644 --- a/src/mbgl/renderer/buckets/symbol_bucket.hpp +++ b/src/mbgl/renderer/buckets/symbol_bucket.hpp @@ -37,7 +37,7 @@ public: size_t vertexStartIndex; }; -class SymbolBucket : public Bucket { +class SymbolBucket final : public Bucket { public: SymbolBucket(style::SymbolLayoutProperties::PossiblyEvaluated, const std::map<std::string, std::pair<style::IconPaintProperties::PossiblyEvaluated, style::TextPaintProperties::PossiblyEvaluated>>&, @@ -49,9 +49,11 @@ public: bool sortFeaturesByY, const std::string bucketLeaderID, const std::vector<SymbolInstance>&&); + ~SymbolBucket() override; void upload(gl::Context&) override; bool hasData() const override; + bool supportsLayer(const style::Layer::Impl&) const override; bool hasTextData() const; bool hasIconData() const; bool hasCollisionBoxData() const; @@ -138,9 +140,4 @@ 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/render_layer.hpp b/src/mbgl/renderer/render_layer.hpp index 4e0e1913b6..485e5551c6 100644 --- a/src/mbgl/renderer/render_layer.hpp +++ b/src/mbgl/renderer/render_layer.hpp @@ -2,7 +2,6 @@ #include <mbgl/layout/layout.hpp> #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 <mbgl/util/mat4.hpp> diff --git a/src/mbgl/tile/geometry_tile.cpp b/src/mbgl/tile/geometry_tile.cpp index c85f9ef713..977744248d 100644 --- a/src/mbgl/tile/geometry_tile.cpp +++ b/src/mbgl/tile/geometry_tile.cpp @@ -200,9 +200,10 @@ Bucket* GeometryTile::getBucket(const Layer::Impl& layer) const { if (it == buckets.end()) { return nullptr; } - - assert(it->second); - return it->second.get(); + Bucket* result = it->second.get(); + assert(result); + // Bucket might be outdated, see issue #12432. + return result->supportsLayer(layer) ? result : nullptr; } float GeometryTile::getQueryPadding(const std::vector<const RenderLayer*>& layers) { diff --git a/src/mbgl/tile/tile.hpp b/src/mbgl/tile/tile.hpp index 70b2aa0371..3bd655a6c8 100644 --- a/src/mbgl/tile/tile.hpp +++ b/src/mbgl/tile/tile.hpp @@ -56,8 +56,7 @@ public: template <class T> T* getBucket(const style::Layer::Impl& layer) const { - Bucket* bucket = getBucket(layer); - return bucket ? bucket->as<T>() : nullptr; + return static_cast<T*>(getBucket(layer)); } virtual void setShowCollisionBoxes(const bool) {} |