Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Drop LayerType
Browse files Browse the repository at this point in the history
Drop LayerType and its remaining usages.
The generic code should be layer type agnostic.
  • Loading branch information
pozdnyakov committed Jan 4, 2019
1 parent 4e86bca commit c621b81
Show file tree
Hide file tree
Showing 24 changed files with 100 additions and 123 deletions.
1 change: 0 additions & 1 deletion cmake/core-files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion include/mbgl/style/layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
20 changes: 0 additions & 20 deletions include/mbgl/style/layer_type.hpp

This file was deleted.

1 change: 0 additions & 1 deletion src/mbgl/layout/layout.hpp
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
32 changes: 10 additions & 22 deletions src/mbgl/renderer/bucket.hpp
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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.
Expand All @@ -64,9 +47,14 @@ class Bucket : private util::noncopyable {
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 };
};

Expand Down
9 changes: 7 additions & 2 deletions src/mbgl/renderer/buckets/circle_bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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));
Expand All @@ -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&,
Expand Down
9 changes: 3 additions & 6 deletions src/mbgl/renderer/buckets/circle_bucket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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&,
Expand All @@ -27,6 +28,7 @@ class CircleBucket : public Bucket {
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;
Expand All @@ -40,9 +42,4 @@ class CircleBucket : public Bucket {
const MapMode mode;
};

template <>
inline bool Bucket::is<CircleBucket>() const {
return layerType == style::LayerType::Circle;
}

} // namespace mbgl
10 changes: 8 additions & 2 deletions src/mbgl/renderer/buckets/fill_bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -43,6 +42,8 @@ FillBucket::FillBucket(const FillBucket::PossiblyEvaluatedLayoutProperties,
}
}

FillBucket::~FillBucket() = default;

void FillBucket::addFeature(const GeometryTileFeature& feature,
const GeometryCollection& geometry,
const ImagePositions& patternPositions,
Expand Down Expand Up @@ -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>();
Expand Down
10 changes: 3 additions & 7 deletions src/mbgl/renderer/buckets/fill_bucket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,6 +38,7 @@ class FillBucket : public Bucket {
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;
Expand All @@ -52,9 +53,4 @@ class FillBucket : public Bucket {
std::map<std::string, FillProgram::PaintPropertyBinders> paintPropertyBinders;
};

template <>
inline bool Bucket::is<FillBucket>() const {
return layerType == style::LayerType::Fill;
}

} // namespace mbgl
10 changes: 7 additions & 3 deletions src/mbgl/renderer/buckets/fill_extrusion_bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -50,6 +48,8 @@ FillExtrusionBucket::FillExtrusionBucket(const FillExtrusionBucket::PossiblyEval
}
}

FillExtrusionBucket::~FillExtrusionBucket() = default;

void FillExtrusionBucket::addFeature(const GeometryTileFeature& feature,
const GeometryCollection& geometry,
const ImagePositions& patternPositions,
Expand Down Expand Up @@ -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>();
Expand Down
11 changes: 4 additions & 7 deletions src/mbgl/renderer/buckets/fill_extrusion_bucket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,6 +33,8 @@ class FillExtrusionBucket : public Bucket {

bool hasData() const override;

bool supportsLayer(const style::Layer::Impl&) const override;

void upload(gl::Context&) override;

float getQueryRadius(const RenderLayer&) const override;
Expand All @@ -47,9 +49,4 @@ class FillExtrusionBucket : public Bucket {
std::unordered_map<std::string, FillExtrusionProgram::PaintPropertyBinders> paintPropertyBinders;
};

template <>
inline bool Bucket::is<FillExtrusionBucket>() const {
return layerType == style::LayerType::FillExtrusion;
}

} // namespace mbgl
9 changes: 7 additions & 2 deletions src/mbgl/renderer/buckets/heatmap_bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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));
Expand All @@ -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&,
Expand Down
9 changes: 3 additions & 6 deletions src/mbgl/renderer/buckets/heatmap_bucket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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&,
Expand All @@ -26,6 +27,7 @@ class HeatmapBucket : public Bucket {
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;
Expand All @@ -39,9 +41,4 @@ class HeatmapBucket : public Bucket {
const MapMode mode;
};

template <>
inline bool Bucket::is<HeatmapBucket>() const {
return layerType == style::LayerType::Heatmap;
}

} // namespace mbgl
13 changes: 9 additions & 4 deletions src/mbgl/renderer/buckets/hillshade_bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Loading

0 comments on commit c621b81

Please sign in to comment.