1 #pragma once
2
3 #include <mbgl/gl/attribute.hpp>
4 #include <mbgl/gl/uniform.hpp>
5
6 #include <cstdint>
7
8 namespace mbgl {
9 namespace attributes {
10
11 /*
12 * Pack a pair of values, interpreted as uint8's, into a single float.
13 * Used to conserve vertex attributes. Values are unpacked in the vertex
14 * shader using the `unpack_float()` function, defined in _prelude.vertex.glsl.
15 */
16 template <typename T>
packUint8Pair(T a,T b)17 inline uint16_t packUint8Pair(T a, T b) {
18 return static_cast<uint16_t>(a) * 256 + static_cast<uint16_t>(b);
19 }
20
21 // Layout attributes
22
23 MBGL_DEFINE_ATTRIBUTE(int16_t, 2, a_pos);
24 MBGL_DEFINE_ATTRIBUTE(int16_t, 2, a_extrude);
25 MBGL_DEFINE_ATTRIBUTE(int16_t, 4, a_pos_offset);
26 MBGL_DEFINE_ATTRIBUTE(int16_t, 4, a_pos_normal);
27 MBGL_DEFINE_ATTRIBUTE(float, 3, a_projected_pos);
28 MBGL_DEFINE_ATTRIBUTE(int16_t, 2, a_label_pos);
29 MBGL_DEFINE_ATTRIBUTE(int16_t, 2, a_anchor_pos);
30 MBGL_DEFINE_ATTRIBUTE(uint16_t, 2, a_texture_pos);
31 MBGL_DEFINE_ATTRIBUTE(int16_t, 4, a_normal_ed);
32 MBGL_DEFINE_ATTRIBUTE(uint8_t, 1, a_fade_opacity);
33 MBGL_DEFINE_ATTRIBUTE(uint8_t, 2, a_placed);
34
35 template <typename T, std::size_t N>
36 struct a_data {
namembgl::attributes::a_data37 static auto name() { return "a_data"; }
38 using Type = gl::Attribute<T, N>;
39 };
40
41 struct a_size {
namembgl::attributes::a_size42 static auto name() { return "a_size"; }
43 using Type = gl::Attribute<uint16_t, 3>;
44 };
45
46 template <std::size_t N>
47 struct a_offset {
namembgl::attributes::a_offset48 static auto name() { return "a_offset"; }
49 using Type = gl::Attribute<int16_t, N>;
50 };
51
52 // Paint attributes
53
54 struct a_color {
namembgl::attributes::a_color55 static auto name() { return "a_color"; }
56 using Type = gl::Attribute<float, 2>;
57 };
58
59 struct a_fill_color {
namembgl::attributes::a_fill_color60 static auto name() { return "a_fill_color"; }
61 using Type = gl::Attribute<float, 2>;
62 };
63
64 struct a_halo_color {
namembgl::attributes::a_halo_color65 static auto name() { return "a_halo_color"; }
66 using Type = gl::Attribute<float, 2>;
67 };
68
69 struct a_stroke_color {
namembgl::attributes::a_stroke_color70 static auto name() { return "a_stroke_color"; }
71 using Type = gl::Attribute<float, 2>;
72 };
73
74 struct a_outline_color {
namembgl::attributes::a_outline_color75 static auto name() { return "a_outline_color"; }
76 using Type = gl::Attribute<float, 2>;
77 };
78
79 struct a_opacity {
namembgl::attributes::a_opacity80 static auto name() { return "a_opacity"; }
81 using Type = gl::Attribute<float, 1>;
82 };
83
84 struct a_stroke_opacity {
namembgl::attributes::a_stroke_opacity85 static auto name() { return "a_stroke_opacity"; }
86 using Type = gl::Attribute<float, 1>;
87 };
88
89 struct a_blur {
namembgl::attributes::a_blur90 static auto name() { return "a_blur"; }
91 using Type = gl::Attribute<float, 1>;
92 };
93
94 struct a_radius {
namembgl::attributes::a_radius95 static auto name() { return "a_radius"; }
96 using Type = gl::Attribute<float, 1>;
97 };
98
99 struct a_width {
namembgl::attributes::a_width100 static auto name() { return "a_width"; }
101 using Type = gl::Attribute<float, 1>;
102 };
103
104 struct a_floorwidth {
namembgl::attributes::a_floorwidth105 static auto name() { return "a_floorwidth"; }
106 using Type = gl::Attribute<float, 1>;
107 };
108
109 struct a_height {
namembgl::attributes::a_height110 static auto name() { return "a_height"; }
111 using Type = gl::Attribute<float, 1>;
112 };
113
114 struct a_base {
namembgl::attributes::a_base115 static auto name() { return "a_base"; }
116 using Type = gl::Attribute<float, 1>;
117 };
118
119 struct a_gapwidth {
namembgl::attributes::a_gapwidth120 static auto name() { return "a_gapwidth"; }
121 using Type = gl::Attribute<float, 1>;
122 };
123
124 struct a_stroke_width {
namembgl::attributes::a_stroke_width125 static auto name() { return "a_stroke_width"; }
126 using Type = gl::Attribute<float, 1>;
127 };
128
129 template <>
130 struct a_offset<1> {
namembgl::attributes::a_offset131 static auto name() { return "a_offset"; }
132 using Type = gl::Attribute<float, 1>;
133 };
134
135 struct a_halo_width {
namembgl::attributes::a_halo_width136 static auto name() { return "a_halo_width"; }
137 using Type = gl::Attribute<float, 1>;
138 };
139
140 struct a_halo_blur {
namembgl::attributes::a_halo_blur141 static auto name() { return "a_halo_blur"; }
142 using Type = gl::Attribute<float, 1>;
143 };
144
145 struct a_weight {
namembgl::attributes::a_weight146 static auto name() { return "a_weight"; }
147 using Type = gl::Attribute<float, 1>;
148 };
149
150 } // namespace attributes
151
152 struct PositionOnlyLayoutAttributes : gl::Attributes<
153 attributes::a_pos>
154 {};
155
156 } // namespace mbgl
157