summaryrefslogtreecommitdiff
path: root/src/mbgl/style/style_layer.hpp
blob: 764906576f85f1bccfe92da99fadd18c15a21042 (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
74
75
76
77
78
#ifndef MBGL_STYLE_STYLE_LAYER
#define MBGL_STYLE_STYLE_LAYER

#include <mbgl/style/types.hpp>
#include <mbgl/style/filter_expression.hpp>
#include <mbgl/renderer/render_pass.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/rapidjson.hpp>

#include <memory>
#include <string>
#include <limits>

namespace mbgl {

class StyleCascadeParameters;
class StyleCalculationParameters;
class StyleBucketParameters;
class Bucket;

class StyleLayer {
public:
    virtual ~StyleLayer() = default;

    // Check whether this layer is of the given subtype.
    template <class T> bool is() const { return dynamic_cast<const T*>(this); }

    // Dynamically cast this layer to the given subtype.
    template <class T>       T* as()       { return dynamic_cast<      T*>(this); }
    template <class T> const T* as() const { return dynamic_cast<const T*>(this); }

    // Create a copy of this layer.
    virtual std::unique_ptr<StyleLayer> clone() const = 0;

    virtual void parseLayout(const JSValue& value) = 0;
    virtual void parsePaints(const JSValue& value) = 0;

    // If the layer has a ref, the ref. Otherwise, the id.
    const std::string& bucketName() const;

    // Partially evaluate paint properties based on a set of classes.
    virtual void cascade(const StyleCascadeParameters&) = 0;

    // Fully evaluate cascaded paint properties based on a zoom level.
    // Returns true if any paint properties have active transitions.
    virtual bool recalculate(const StyleCalculationParameters&) = 0;

    virtual std::unique_ptr<Bucket> createBucket(StyleBucketParameters&) const = 0;

    // Checks whether this layer needs to be rendered in the given render pass.
    bool hasRenderPass(RenderPass) const;

    // Checks whether this layer can be rendered.
    bool needsRendering() const;

public:
    std::string id;
    std::string ref;
    std::string source;
    std::string sourceLayer;
    FilterExpression filter;
    float minZoom = -std::numeric_limits<float>::infinity();
    float maxZoom = std::numeric_limits<float>::infinity();
    VisibilityType visibility = VisibilityType::Visible;

protected:
    StyleLayer() = default;
    StyleLayer(const StyleLayer&) = default;
    StyleLayer& operator=(const StyleLayer&) = delete;

    // Stores what render passes this layer is currently enabled for. This depends on the
    // evaluated StyleProperties object and is updated accordingly.
    RenderPass passes = RenderPass::None;
};

} // namespace mbgl

#endif