1 #pragma once
2 
3 #include <mbgl/util/noncopyable.hpp>
4 #include <mbgl/tile/geometry_tile_data.hpp>
5 #include <mbgl/style/layer_type.hpp>
6 
7 #include <atomic>
8 
9 namespace mbgl {
10 
11 namespace gl {
12 class Context;
13 } // namespace gl
14 
15 class RenderLayer;
16 
17 class Bucket : private util::noncopyable {
18 public:
Bucket(style::LayerType layerType_)19     Bucket(style::LayerType layerType_)
20         : layerType(layerType_) {
21     }
22 
23     virtual ~Bucket() = default;
24 
25     // Check whether this bucket is of the given subtype.
26     template <class T>
27     bool is() const;
28 
29     // Dynamically cast this bucket to the given subtype.
30     template <class T>
as()31     T* as() {
32         return is<T>() ? reinterpret_cast<T*>(this) : nullptr;
33     }
34 
35     template <class T>
as() const36     const T* as() const {
37         return is<T>() ? reinterpret_cast<const T*>(this) : nullptr;
38     }
39 
40     // Feature geometries are also used to populate the feature index.
41     // Obtaining these is a costly operation, so we do it only once, and
42     // pass-by-const-ref the geometries as a second parameter.
addFeature(const GeometryTileFeature &,const GeometryCollection &)43     virtual void addFeature(const GeometryTileFeature&,
44                             const GeometryCollection&) {};
45 
46     // As long as this bucket has a Prepare render pass, this function is getting called. Typically,
47     // this only happens once when the bucket is being rendered for the first time.
48     virtual void upload(gl::Context&) = 0;
49 
50     virtual bool hasData() const = 0;
51 
getQueryRadius(const RenderLayer &) const52     virtual float getQueryRadius(const RenderLayer&) const {
53         return 0;
54     };
55 
needsUpload() const56     bool needsUpload() const {
57         return hasData() && !uploaded;
58     }
59 
60 protected:
61     style::LayerType layerType;
62     std::atomic<bool> uploaded { false };
63 };
64 
65 } // namespace mbgl
66