summaryrefslogtreecommitdiff
path: root/src/mbgl/programs/attributes.hpp
blob: bb90f2c13cd1be03cbf26ca8b81c18caaa8643e3 (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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#pragma once

#include <mbgl/gl/attribute.hpp>
#include <mbgl/gl/uniform.hpp>
#include <mbgl/gl/normalization.hpp>

#include <cstdint>

namespace mbgl {
namespace attributes {

// Layout attributes

MBGL_DEFINE_ATTRIBUTE(int16_t, 2, a_pos);
MBGL_DEFINE_ATTRIBUTE(int16_t, 2, a_extrude);
MBGL_DEFINE_ATTRIBUTE(uint16_t, 2, a_texture_pos);

template <std::size_t N>
struct a_data : gl::Attribute<uint8_t, N> {
    static auto name() { return "a_data"; }
};

template <std::size_t N>
struct a_offset : gl::Attribute<int16_t, N> {
    static auto name() { return "a_offset"; }
};

// Paint attributes

template <class Attr>
struct Min : Attr {
    static auto name() {
        static const std::string name = Attr::name() + std::string("_min");
        return name.c_str();
    }
};

template <class Attr>
struct Max : Attr {
    static auto name() {
        static const std::string name = Attr::name() + std::string("_max");
        return name.c_str();
    }
};

template <class Attr>
struct InterpolationUniform : gl::UniformScalar<InterpolationUniform<Attr>, float> {
    static auto name() {
        static const std::string name = Attr::name() + std::string("_t");
        return name.c_str();
    }
};

struct a_color : gl::Attribute<gl::Normalized<uint8_t>, 4> {
    static auto name() { return "a_color"; }

    static Value value(const Color& color) {
        return {{
            gl::Normalized<uint8_t>(color.r),
            gl::Normalized<uint8_t>(color.g),
            gl::Normalized<uint8_t>(color.b),
            gl::Normalized<uint8_t>(color.a)
        }};
    }
};

// used in the symbol sdf shader
struct a_fill_color : gl::Attribute<gl::Normalized<uint8_t>, 4> {
    static auto name() { return "a_fill_color"; }
    
    static Value value(const Color& color) {
        return {{
            gl::Normalized<uint8_t>(color.r),
            gl::Normalized<uint8_t>(color.g),
            gl::Normalized<uint8_t>(color.b),
            gl::Normalized<uint8_t>(color.a)
        }};
    }
};

// used in the symbol sdf shader
struct a_halo_color : gl::Attribute<gl::Normalized<uint8_t>, 4> {
    static auto name() { return "a_halo_color"; }
    
    static Value value(const Color& color) {
        return {{
            gl::Normalized<uint8_t>(color.r),
            gl::Normalized<uint8_t>(color.g),
            gl::Normalized<uint8_t>(color.b),
            gl::Normalized<uint8_t>(color.a)
        }};
    }
};

struct a_stroke_color : gl::Attribute<gl::Normalized<uint8_t>, 4> {
    static auto name() { return "a_stroke_color"; }

    static Value value(const Color& color) {
        return {{
            gl::Normalized<uint8_t>(color.r),
            gl::Normalized<uint8_t>(color.g),
            gl::Normalized<uint8_t>(color.b),
            gl::Normalized<uint8_t>(color.a)
        }};
    }
};

struct a_outline_color : gl::Attribute<gl::Normalized<uint8_t>, 4> {
    static auto name() { return "a_outline_color"; }

    static Value value(const Color& color) {
        return {{
            gl::Normalized<uint8_t>(color.r),
            gl::Normalized<uint8_t>(color.g),
            gl::Normalized<uint8_t>(color.b),
            gl::Normalized<uint8_t>(color.a)
        }};
    }
};

struct a_opacity : gl::Attribute<gl::Normalized<uint8_t>, 1> {
    static auto name() { return "a_opacity"; }

    static Value value(float opacity) {
        return {{ gl::Normalized<uint8_t>(opacity) }};
    }
};

struct a_stroke_opacity : gl::Attribute<gl::Normalized<uint8_t>, 1> {
    static auto name() { return "a_stroke_opacity"; }

    static Value value(float opacity) {
        return {{ gl::Normalized<uint8_t>(opacity) }};
    }
};

struct a_blur : gl::Attribute<float, 1> {
    static auto name() { return "a_blur"; }

    static Value value(float blur) {
        return {{ blur }};
    }
};

struct a_radius : gl::Attribute<float, 1> {
    static auto name() { return "a_radius"; }

    static Value value(float radius) {
        return {{ radius }};
    }
};

struct a_width : gl::Attribute<float, 1> {
    static auto name() { return "a_width"; }

    static Value value(float width) {
        return {{ width }};
    }
};

struct a_height : gl::Attribute<float, 1> {
    static auto name() { return "a_height"; }

    static Value value(float width) {
        return {{ width }};
    }
};

struct a_base : gl::Attribute<float, 1> {
    static auto name() { return "a_base"; }

    static Value value(float width) {
        return {{ width }};
    }
};

struct a_gap_width : gl::Attribute<float, 1> {
    static auto name() { return "a_gapwidth"; }

    static Value value(float width) {
        return {{ width }};
    }
};

struct a_stroke_width : gl::Attribute<float, 1> {
    static auto name() { return "a_stroke_width"; }

    static Value value(float width) {
        return {{ width }};
    }
};

template <>
struct a_offset<1> : gl::Attribute<float, 1> {
    static auto name() { return "a_offset"; }

    static Value value(float offset) {
        return {{ offset }};
    }
};

struct a_halo_width : gl::Attribute<float, 1> {
    static auto name() { return "a_halo_width"; }
    
    static Value value(float width) {
        return {{ width }};
    }
};

struct a_halo_blur : gl::Attribute<float, 1> {
    static auto name() { return "a_halo_blur"; }
    
    static Value value(float blur) {
        return {{ blur }};
    }
};



} // namespace attributes
} // namespace mbgl