summaryrefslogtreecommitdiff
path: root/src/mbgl/style/layers/layer_properties.hpp.ejs
blob: c1b404bd6dc0596baa9f98eac2ca0dbe0c1f7366 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<%
  const type = locals.type;
  const layoutProperties = locals.layoutProperties;
  const paintProperties = locals.paintProperties;
-%>
// This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`.

#pragma once

#include <mbgl/style/types.hpp>
#include <mbgl/style/layout_property.hpp>
#include <mbgl/style/paint_property.hpp>
#include <mbgl/style/properties.hpp>
#include <mbgl/programs/attributes.hpp>
#include <mbgl/programs/uniforms.hpp>

namespace mbgl {
namespace style {

<% for (const property of layoutProperties) { -%>
struct <%- camelize(property.name) %> : <%- layoutPropertyType(property, type) %> {
    static constexpr const char * key = "<%- property.name %>";
    static <%- evaluatedType(property) %> defaultValue() { return <%- defaultValue(property) %>; }
};

<% } -%>
<% for (const property of paintProperties) { -%>
<%   if (property['property-type'] === 'color-ramp') { -%>
struct <%- camelize(property.name) %> : ColorRampProperty {
};
<%   } else { -%>
struct <%- camelize(property.name) %> : <%- paintPropertyType(property, type) %> {
    static <%- evaluatedType(property) %> defaultValue() { return <%- defaultValue(property) %>; }
};
<%   } -%>

<% } -%>
<% if (layoutProperties.length) { -%>
class <%- camelize(type) %>LayoutProperties {
public:
    class Evaluated {
    public:
<% for (const property of layoutProperties) { -%>
        <%- evaluatedType(property) %> <%- camelizeWithLeadingLowercase(property.name) %>;
<% } -%>
    };

    class PossiblyEvaluated {
    public:
<% for (const property of layoutProperties) { -%>
        <%- possiblyEvaluatedType(property) %> <%- camelizeWithLeadingLowercase(property.name) %>;
<% } -%>

        Evaluated evaluate(float z, const GeometryTileFeature& feature) const;
    };

    class Unevaluated {
    public:
<% for (const property of layoutProperties) { -%>
        <%- propertyValueType(property) %> <%- camelizeWithLeadingLowercase(property.name) %>;
<% } -%>

        PossiblyEvaluated evaluate(const PropertyEvaluationParameters&) const;

        friend bool operator==(const Unevaluated&, const Unevaluated&);
        friend inline bool operator!=(const Unevaluated& lhs, const Unevaluated& rhs) { return !(lhs == rhs); }
    };
};

<% } -%>
class <%- camelize(type) %>PaintProperties {
public:
<% if (type !== "symbol" && type !== "background" && type !== "raster" && type !== "hillshade") { -%>
    class PossiblyEvaluated;

    class Binders {
    public:
<% for (const property of paintProperties.filter(isDataDriven)) { -%>
        std::unique_ptr<PaintPropertyBinder<<%- evaluatedType(property) %>, typename <%- attributeType(property, type) %>::Type>> <%- camelizeWithLeadingLowercase(property.name) %>;
<% } -%>

        void populateVertexVectors(const GeometryTileFeature&, std::size_t length);
        void upload(gl::Context&);

        using Attributes = gl::Attributes<
            <%- paintProperties.filter(isDataDriven).map(property => `ZoomInterpolatedAttribute<${attributeType(property, type)}>`).join(',\n            ') %>
        >;

        using Uniforms = gl::Uniforms<
            <%- paintProperties.filter(isDataDriven).map(property => `InterpolationUniform<${attributeType(property, type)}>`)
            .concat(paintProperties.filter(isDataDriven).map(property => uniformType(property, type))).join(',\n            ') %>
        >;

        using AttributeBindings = typename Attributes::Bindings;
        using UniformValues = typename Uniforms::Values;

        AttributeBindings attributeBindings(const PossiblyEvaluated&) const;
        UniformValues uniformValues(float z, const PossiblyEvaluated&) const;
    };
<% } -%>

    class PossiblyEvaluated {
    public:
<% for (const property of paintProperties) { -%>
        <%- possiblyEvaluatedType(property) %> <%- camelizeWithLeadingLowercase(property.name) %>;
<% } -%>
<% if (type !== "symbol" && type !== "background" && type !== "raster" && type !== "hillshade") { -%>

        Binders createBinders(float z) const;

        std::bitset<8> constants() const;
        std::vector<std::string> defines() const;
<% } -%>
    };

    class Unevaluated {
    public:
<% for (const property of paintProperties) { -%>
        style::Transitioning<<%- propertyValueType(property) %>> <%- camelizeWithLeadingLowercase(property.name) %>;
<% } -%>

        bool hasTransition() const;
        PossiblyEvaluated evaluate(const PropertyEvaluationParameters&) const;
    };

    class Transitionable {
    public:
<% for (const property of paintProperties) { -%>
        style::Transitionable<<%- propertyValueType(property) %>> <%- camelizeWithLeadingLowercase(property.name) %>;
<% } -%>

        Unevaluated transitioned(const TransitionParameters&, Unevaluated&& prior) const;
        Unevaluated untransitioned() const;

        bool hasDataDrivenPropertyDifference(const Transitionable& other) const;
    };
};

<% if (type === "symbol") { -%>
// {icon,text}-specific paint-property packs for use in the symbol Programs.
// Since each program deals either with icons or text, using a smaller property set
// lets us avoid unnecessarily binding attributes for properties the program wouldn't use.

<% for (const subtype of ['icon', 'text']) {
    const properties = paintProperties.filter(({name}) => name.startsWith(`${subtype}-`));
%>
class <%- camelize(subtype) %>PaintProperties {
public:
    class PossiblyEvaluated;

    class Binders {
    public:
<% for (const property of properties.filter(isDataDriven)) { -%>
        std::unique_ptr<PaintPropertyBinder<<%- evaluatedType(property) %>, typename <%- attributeType(property, type) %>::Type>> <%- camelizeWithLeadingLowercase(property.name) %>;
<% } -%>

        void populateVertexVectors(const GeometryTileFeature&, std::size_t length);
        void upload(gl::Context&);

        using Attributes = gl::Attributes<
            <%- properties.filter(isDataDriven).map(property => `ZoomInterpolatedAttribute<${attributeType(property, type)}>`).join(',\n            ') %>
        >;

        using Uniforms = gl::Uniforms<
            <%- properties.filter(isDataDriven).map(property => `InterpolationUniform<${attributeType(property, type)}>`).join(',\n            ') %>,
            <%- properties.filter(isDataDriven).map(property => uniformType(property, type)).join(',\n            ') %>
        >;

        using AttributeBindings = typename Attributes::Bindings;
        using UniformValues = typename Uniforms::Values;

        AttributeBindings attributeBindings(const PossiblyEvaluated&) const;
        UniformValues uniformValues(float z, const PossiblyEvaluated&) const;
    };

    class PossiblyEvaluated {
    public:
<% for (const property of properties) { -%>
        <%- possiblyEvaluatedType(property) %> <%- camelizeWithLeadingLowercase(property.name) %>;
<% } -%>

        Binders createBinders(float z) const;

        std::bitset<8> constants() const;
        std::vector<std::string> defines() const;
    };
};

<% } -%>
<% } -%>

} // namespace style
} // namespace mbgl