summaryrefslogtreecommitdiff
path: root/src/mbgl/renderer/bucket.hpp
blob: 7ccab8672dba2e6cc86748ba2213e2e6c7a12468 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#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 <atomic>

namespace mbgl {

namespace gl {
class Context;
} // namespace gl

class RenderLayer;
class PatternDependency;
using PatternLayerMap = std::unordered_map<std::string, PatternDependency>;

class Bucket : private util::noncopyable {
public:
    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.
    virtual void addFeature(const GeometryTileFeature&,
                            const GeometryCollection&,
                            const ImagePositions&,
                            const PatternLayerMap&) {};

    virtual void populateFeatureBuffers(const ImagePositions&) {};
    virtual void addPatternDependencies(const std::vector<const RenderLayer*>&, ImageDependencies&) {};

    // As long as this bucket has a Prepare render pass, this function is getting called. Typically,
    // this only happens once when the bucket is being rendered for the first time.
    virtual void upload(gl::Context&) = 0;

    virtual bool hasData() const = 0;

    virtual float getQueryRadius(const RenderLayer&) const {
        return 0;
    };

    bool needsUpload() const {
        return hasData() && !uploaded;
    }

protected:
    style::LayerType layerType;
    std::atomic<bool> uploaded { false };
};

} // namespace mbgl