diff options
60 files changed, 543 insertions, 523 deletions
diff --git a/cmake/core-files.cmake b/cmake/core-files.cmake index cd28c1de0b..07a11e9a9f 100644 --- a/cmake/core-files.cmake +++ b/cmake/core-files.cmake @@ -54,6 +54,7 @@ set(MBGL_CORE_FILES # gl include/mbgl/gl/gl.hpp + src/mbgl/gl/attribute.cpp src/mbgl/gl/attribute.hpp src/mbgl/gl/color_mode.cpp src/mbgl/gl/color_mode.hpp @@ -181,16 +182,16 @@ set(MBGL_CORE_FILES src/mbgl/renderer/symbol_bucket.hpp # shader + src/mbgl/shader/attributes.hpp + src/mbgl/shader/circle_attributes.hpp src/mbgl/shader/circle_shader.cpp src/mbgl/shader/circle_shader.hpp src/mbgl/shader/circle_uniforms.hpp - src/mbgl/shader/circle_vertex.cpp - src/mbgl/shader/circle_vertex.hpp + src/mbgl/shader/collision_box_attributes.hpp src/mbgl/shader/collision_box_shader.cpp src/mbgl/shader/collision_box_shader.hpp src/mbgl/shader/collision_box_uniforms.hpp - src/mbgl/shader/collision_box_vertex.cpp - src/mbgl/shader/collision_box_vertex.hpp + src/mbgl/shader/fill_attributes.hpp src/mbgl/shader/fill_outline_pattern_shader.cpp src/mbgl/shader/fill_outline_pattern_shader.hpp src/mbgl/shader/fill_outline_shader.cpp @@ -201,8 +202,7 @@ set(MBGL_CORE_FILES src/mbgl/shader/fill_shader.hpp src/mbgl/shader/fill_uniforms.cpp src/mbgl/shader/fill_uniforms.hpp - src/mbgl/shader/fill_vertex.cpp - src/mbgl/shader/fill_vertex.hpp + src/mbgl/shader/line_attributes.hpp src/mbgl/shader/line_pattern_shader.cpp src/mbgl/shader/line_pattern_shader.hpp src/mbgl/shader/line_sdf_shader.cpp @@ -211,22 +211,18 @@ set(MBGL_CORE_FILES src/mbgl/shader/line_shader.hpp src/mbgl/shader/line_uniforms.cpp src/mbgl/shader/line_uniforms.hpp - src/mbgl/shader/line_vertex.cpp - src/mbgl/shader/line_vertex.hpp + src/mbgl/shader/raster_attributes.hpp src/mbgl/shader/raster_shader.cpp src/mbgl/shader/raster_shader.hpp src/mbgl/shader/raster_uniforms.hpp - src/mbgl/shader/raster_vertex.cpp - src/mbgl/shader/raster_vertex.hpp src/mbgl/shader/shaders.hpp + src/mbgl/shader/symbol_attributes.hpp src/mbgl/shader/symbol_icon_shader.cpp src/mbgl/shader/symbol_icon_shader.hpp src/mbgl/shader/symbol_sdf_shader.cpp src/mbgl/shader/symbol_sdf_shader.hpp src/mbgl/shader/symbol_uniforms.cpp src/mbgl/shader/symbol_uniforms.hpp - src/mbgl/shader/symbol_vertex.cpp - src/mbgl/shader/symbol_vertex.hpp src/mbgl/shader/uniforms.hpp # sprite diff --git a/src/mbgl/gl/attribute.cpp b/src/mbgl/gl/attribute.cpp new file mode 100644 index 0000000000..81ab6ac2a5 --- /dev/null +++ b/src/mbgl/gl/attribute.cpp @@ -0,0 +1,24 @@ +#include <mbgl/gl/attribute.hpp> +#include <mbgl/gl/gl.hpp> + +namespace mbgl { +namespace gl { + +void bindAttribute(AttributeLocation location, + std::size_t count, + DataType type, + std::size_t vertexSize, + std::size_t vertexOffset, + std::size_t attributeOffset) { + MBGL_CHECK_ERROR(glEnableVertexAttribArray(location)); + MBGL_CHECK_ERROR(glVertexAttribPointer( + location, + static_cast<GLint>(count), + static_cast<GLenum>(type), + GL_FALSE, + static_cast<GLsizei>(vertexSize), + reinterpret_cast<GLvoid*>(attributeOffset + (vertexSize * vertexOffset)))); +} + +} // namespace gl +} // namespace mbgl diff --git a/src/mbgl/gl/attribute.hpp b/src/mbgl/gl/attribute.hpp index f270a250bb..e6ef5c7f89 100644 --- a/src/mbgl/gl/attribute.hpp +++ b/src/mbgl/gl/attribute.hpp @@ -4,43 +4,173 @@ #include <mbgl/gl/shader.hpp> #include <cstddef> +#include <functional> +#include <tuple> +#include <utility> namespace mbgl { namespace gl { -template <typename T, std::size_t N> +template <class Tag, class T, std::size_t N> class Attribute { public: - Attribute(const char* name, const Shader& shader) - : location(shader.getAttributeLocation(name)) {} + using Type = T[N]; - AttributeLocation location; + class State { + public: + State(const char* name, const Shader& shader) + : location(shader.getAttributeLocation(name)) {} + + AttributeLocation location; + static constexpr std::size_t count = N; + static constexpr DataType type = DataTypeOf<T>::value; + }; }; -class AttributeBinding { +#define MBGL_DEFINE_ATTRIBUTE(type_, n_, name_) \ + struct name_ : ::mbgl::gl::Attribute<name_, type_, n_> { static constexpr auto name = #name_; } + +namespace detail { + +// Attribute binding requires member offsets. The only standard way to +// obtain an offset is the offsetof macro. The offsetof macro has defined +// behavior only for standard layout types. That rules out std::tuple and +// any other solution that relies on chained inheritance. Manually implemented +// variadic specialization looks like the only solution. Fortunately, we +// only use a maximum of five attributes. + +template <class... As> +class Vertex; + +template <class A1> +class Vertex<A1> { public: - template <class Vertex, class T, std::size_t N, std::size_t O> - AttributeBinding(const T (Vertex::*)[N], const Attribute<T, N>& attribute, std::integral_constant<std::size_t, O>) - : location(attribute.location), - type(DataTypeOf<T>::value), - count(N), - offset(O) { - static_assert(O % 4 == 0, "vertex attribute must be optimally aligned"); - static_assert(1 <= N && N <= 4, "count must be 1, 2, 3, or 4"); - } + typename A1::Type a1; + + using VertexType = Vertex<A1>; + static const std::size_t attributeOffsets[1]; +}; + +template <class A1, class A2> +class Vertex<A1, A2> { +public: + typename A1::Type a1; + typename A2::Type a2; + + using VertexType = Vertex<A1, A2>; + static const std::size_t attributeOffsets[2]; +}; + +template <class A1, class A2, class A3> +class Vertex<A1, A2, A3> { +public: + typename A1::Type a1; + typename A2::Type a2; + typename A3::Type a3; + + using VertexType = Vertex<A1, A2, A3>; + static const std::size_t attributeOffsets[3]; +}; + +template <class A1, class A2, class A3, class A4> +class Vertex<A1, A2, A3, A4> { +public: + typename A1::Type a1; + typename A2::Type a2; + typename A3::Type a3; + typename A4::Type a4; + + using VertexType = Vertex<A1, A2, A3, A4>; + static const std::size_t attributeOffsets[4]; +}; + +template <class A1, class A2, class A3, class A4, class A5> +class Vertex<A1, A2, A3, A4, A5> { +public: + typename A1::Type a1; + typename A2::Type a2; + typename A3::Type a3; + typename A4::Type a4; + typename A5::Type a5; + + using VertexType = Vertex<A1, A2, A3, A4, A5>; + static const std::size_t attributeOffsets[5]; +}; + +template <class A1> +const std::size_t Vertex<A1>::attributeOffsets[1] = { + offsetof(VertexType, a1) +}; + +template <class A1, class A2> +const std::size_t Vertex<A1, A2>::attributeOffsets[2] = { + offsetof(VertexType, a1), + offsetof(VertexType, a2) +}; + +template <class A1, class A2, class A3> +const std::size_t Vertex<A1, A2, A3>::attributeOffsets[3] = { + offsetof(VertexType, a1), + offsetof(VertexType, a2), + offsetof(VertexType, a3) +}; + +template <class A1, class A2, class A3, class A4> +const std::size_t Vertex<A1, A2, A3, A4>::attributeOffsets[4] = { + offsetof(VertexType, a1), + offsetof(VertexType, a2), + offsetof(VertexType, a3), + offsetof(VertexType, a4) +}; - AttributeLocation location; - DataType type; - uint8_t count; - std::size_t offset; +template <class A1, class A2, class A3, class A4, class A5> +const std::size_t Vertex<A1, A2, A3, A4, A5>::attributeOffsets[5] = { + offsetof(VertexType, a1), + offsetof(VertexType, a2), + offsetof(VertexType, a3), + offsetof(VertexType, a4), + offsetof(VertexType, a5) }; -#define MBGL_MAKE_ATTRIBUTE_BINDING(Vertex, shader, name) \ - ::mbgl::gl::AttributeBinding(&Vertex::name, \ - shader.name, \ - std::integral_constant<std::size_t, offsetof(Vertex, name)>()) +} // namespace detail -template <class Shader, class Vertex> struct AttributeBindings; +void bindAttribute(AttributeLocation location, + std::size_t count, + DataType type, + std::size_t vertexSize, + std::size_t vertexOffset, + std::size_t attributeOffset); + +template <class... As> +class Attributes { +public: + using State = std::tuple<typename As::State...>; + using Vertex = detail::Vertex<As...>; + + static State state(const Shader& shader) { + return State { { As::name, shader }... }; + } + + static std::function<void (std::size_t)> binder(const State& state) { + return binder(state, std::index_sequence_for<As...>()); + } + +private: + template <std::size_t... Is> + static std::function<void (std::size_t)> binder(const State& state, std::index_sequence<Is...>) { + return [&state] (std::size_t vertexOffset) { + noop((bindAttribute(std::get<Is>(state).location, + std::get<Is>(state).count, + std::get<Is>(state).type, + sizeof(Vertex), + vertexOffset, + Vertex::attributeOffsets[Is]), 0)...); + }; + } + + // This exists only to provide a varags context for unpacking the assignments in `binder`. + template <int...> static void noop(int...) {} +}; } // namespace gl } // namespace mbgl diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp index c63819bc03..f23dfe3dbe 100644 --- a/src/mbgl/gl/context.cpp +++ b/src/mbgl/gl/context.cpp @@ -486,17 +486,7 @@ void Context::draw(const Drawable& drawable) { if (needAttributeBindings()) { vertexBuffer = drawable.vertexBuffer; elementBuffer = drawable.indexBuffer; - - for (const auto& binding : drawable.attributeBindings) { - MBGL_CHECK_ERROR(glEnableVertexAttribArray(binding.location)); - MBGL_CHECK_ERROR(glVertexAttribPointer( - binding.location, - binding.count, - static_cast<GLenum>(binding.type), - GL_FALSE, - static_cast<GLsizei>(drawable.vertexSize), - reinterpret_cast<GLvoid*>(binding.offset + (drawable.vertexSize * segment.vertexOffset)))); - } + drawable.bindAttributes(segment.vertexOffset); } if (drawable.indexBuffer) { diff --git a/src/mbgl/gl/drawable.hpp b/src/mbgl/gl/drawable.hpp index 4f2f11e2f1..be6b27bb83 100644 --- a/src/mbgl/gl/drawable.hpp +++ b/src/mbgl/gl/drawable.hpp @@ -100,10 +100,10 @@ public: primitiveSize(subject.primitiveSize), segments(subject.segments), bindUniforms(Shader::UniformsType::binder(shader.uniformsState, std::move(uniformValues))), - attributeBindings(AttributeBindings<Shader, typename Subject::VertexType>()(shader)) + bindAttributes(Shader::AttributesType::binder(shader.attributesState)) { static_assert(std::is_standard_layout<typename Subject::VertexType>::value, "vertex type must use standard layout"); - static_assert(std::is_same<typename Shader::VertexType, typename Subject::VertexType>::value, "vertex type mismatch"); + static_assert(std::is_same<typename Shader::AttributesType::Vertex, typename Subject::VertexType>::value, "vertex type mismatch"); } DrawMode drawMode; @@ -117,7 +117,7 @@ public: std::size_t primitiveSize; const std::vector<Segment>& segments; std::function<void ()> bindUniforms; - std::vector<AttributeBinding> attributeBindings; + std::function<void (std::size_t)> bindAttributes; }; } // namespace gl diff --git a/src/mbgl/layout/symbol_layout.cpp b/src/mbgl/layout/symbol_layout.cpp index f1886e807e..3fa58e016f 100644 --- a/src/mbgl/layout/symbol_layout.cpp +++ b/src/mbgl/layout/symbol_layout.cpp @@ -462,14 +462,14 @@ void SymbolLayout::addSymbols(Buffer &buffer, const SymbolQuads &symbols, float uint8_t glyphAngle = std::round((symbol.glyphAngle / (M_PI * 2)) * 256); // coordinates (2 triangles) - buffer.vertices.emplace_back(anchorPoint.x, anchorPoint.y, tl.x, tl.y, tex.x, tex.y, minZoom, - maxZoom, placementZoom, glyphAngle); - buffer.vertices.emplace_back(anchorPoint.x, anchorPoint.y, tr.x, tr.y, tex.x + tex.w, tex.y, - minZoom, maxZoom, placementZoom, glyphAngle); - buffer.vertices.emplace_back(anchorPoint.x, anchorPoint.y, bl.x, bl.y, tex.x, tex.y + tex.h, - minZoom, maxZoom, placementZoom, glyphAngle); - buffer.vertices.emplace_back(anchorPoint.x, anchorPoint.y, br.x, br.y, tex.x + tex.w, tex.y + tex.h, - minZoom, maxZoom, placementZoom, glyphAngle); + buffer.vertices.emplace_back(SymbolAttributes::vertex(anchorPoint, tl, tex.x, tex.y, + minZoom, maxZoom, placementZoom, glyphAngle)); + buffer.vertices.emplace_back(SymbolAttributes::vertex(anchorPoint, tr, tex.x + tex.w, tex.y, + minZoom, maxZoom, placementZoom, glyphAngle)); + buffer.vertices.emplace_back(SymbolAttributes::vertex(anchorPoint, bl, tex.x, tex.y + tex.h, + minZoom, maxZoom, placementZoom, glyphAngle)); + buffer.vertices.emplace_back(SymbolAttributes::vertex(anchorPoint, br, tex.x + tex.w, tex.y + tex.h, + minZoom, maxZoom, placementZoom, glyphAngle)); // add the two triangles, referencing the four coordinates we just inserted. buffer.triangles.emplace_back(index + 0, index + 1, index + 2); @@ -507,14 +507,14 @@ void SymbolLayout::addToDebugBuffers(CollisionTile& collisionTile, SymbolBucket& const float maxZoom = util::clamp(zoom + util::log2(box.maxScale), util::MIN_ZOOM_F, util::MAX_ZOOM_F); const float placementZoom = util::clamp(zoom + util::log2(box.placementScale), util::MIN_ZOOM_F, util::MAX_ZOOM_F); - collisionBox.vertices.emplace_back(anchor.x, anchor.y, tl.x, tl.y, maxZoom, placementZoom); - collisionBox.vertices.emplace_back(anchor.x, anchor.y, tr.x, tr.y, maxZoom, placementZoom); - collisionBox.vertices.emplace_back(anchor.x, anchor.y, tr.x, tr.y, maxZoom, placementZoom); - collisionBox.vertices.emplace_back(anchor.x, anchor.y, br.x, br.y, maxZoom, placementZoom); - collisionBox.vertices.emplace_back(anchor.x, anchor.y, br.x, br.y, maxZoom, placementZoom); - collisionBox.vertices.emplace_back(anchor.x, anchor.y, bl.x, bl.y, maxZoom, placementZoom); - collisionBox.vertices.emplace_back(anchor.x, anchor.y, bl.x, bl.y, maxZoom, placementZoom); - collisionBox.vertices.emplace_back(anchor.x, anchor.y, tl.x, tl.y, maxZoom, placementZoom); + collisionBox.vertices.emplace_back(CollisionBoxAttributes::vertex(anchor, tl, maxZoom, placementZoom)); + collisionBox.vertices.emplace_back(CollisionBoxAttributes::vertex(anchor, tr, maxZoom, placementZoom)); + collisionBox.vertices.emplace_back(CollisionBoxAttributes::vertex(anchor, tr, maxZoom, placementZoom)); + collisionBox.vertices.emplace_back(CollisionBoxAttributes::vertex(anchor, br, maxZoom, placementZoom)); + collisionBox.vertices.emplace_back(CollisionBoxAttributes::vertex(anchor, br, maxZoom, placementZoom)); + collisionBox.vertices.emplace_back(CollisionBoxAttributes::vertex(anchor, bl, maxZoom, placementZoom)); + collisionBox.vertices.emplace_back(CollisionBoxAttributes::vertex(anchor, bl, maxZoom, placementZoom)); + collisionBox.vertices.emplace_back(CollisionBoxAttributes::vertex(anchor, tl, maxZoom, placementZoom)); } }; populateCollisionBox(symbolInstance.textCollisionFeature); diff --git a/src/mbgl/renderer/circle_bucket.cpp b/src/mbgl/renderer/circle_bucket.cpp index 3e98d725bb..1137a3f5dc 100644 --- a/src/mbgl/renderer/circle_bucket.cpp +++ b/src/mbgl/renderer/circle_bucket.cpp @@ -34,9 +34,9 @@ void CircleBucket::addGeometry(const GeometryCollection& geometryCollection) { constexpr const uint16_t vertexLength = 4; for (auto& circle : geometryCollection) { - for(auto & geometry : circle) { - auto x = geometry.x; - auto y = geometry.y; + for(auto& point : circle) { + auto x = point.x; + auto y = point.y; // Do not include points that are outside the tile boundaries. // Include all points in Still mode. You need to include points from @@ -58,10 +58,10 @@ void CircleBucket::addGeometry(const GeometryCollection& geometryCollection) { // │ 1 2 │ // └─────────┘ // - vertices.emplace_back(x, y, -1, -1); // 1 - vertices.emplace_back(x, y, 1, -1); // 2 - vertices.emplace_back(x, y, 1, 1); // 3 - vertices.emplace_back(x, y, -1, 1); // 4 + vertices.emplace_back(CircleAttributes::vertex(point, -1, -1)); // 1 + vertices.emplace_back(CircleAttributes::vertex(point, 1, -1)); // 2 + vertices.emplace_back(CircleAttributes::vertex(point, 1, 1)); // 3 + vertices.emplace_back(CircleAttributes::vertex(point, -1, 1)); // 4 auto& segment = segments.back(); assert(segment.vertexLength <= std::numeric_limits<uint16_t>::max()); diff --git a/src/mbgl/renderer/circle_bucket.hpp b/src/mbgl/renderer/circle_bucket.hpp index a682d423d6..b0ae47f523 100644 --- a/src/mbgl/renderer/circle_bucket.hpp +++ b/src/mbgl/renderer/circle_bucket.hpp @@ -6,7 +6,7 @@ #include <mbgl/gl/vertex_buffer.hpp> #include <mbgl/gl/index_buffer.hpp> #include <mbgl/gl/segment.hpp> -#include <mbgl/shader/circle_vertex.hpp> +#include <mbgl/shader/circle_attributes.hpp> namespace mbgl { diff --git a/src/mbgl/renderer/debug_bucket.cpp b/src/mbgl/renderer/debug_bucket.cpp index 14b3976169..d2d4465ab6 100644 --- a/src/mbgl/renderer/debug_bucket.cpp +++ b/src/mbgl/renderer/debug_bucket.cpp @@ -1,7 +1,7 @@ #include <mbgl/renderer/debug_bucket.hpp> #include <mbgl/renderer/painter.hpp> #include <mbgl/shader/fill_shader.hpp> -#include <mbgl/shader/fill_vertex.hpp> +#include <mbgl/shader/fill_attributes.hpp> #include <mbgl/geometry/debug_font_data.hpp> #include <mbgl/util/string.hpp> @@ -37,8 +37,8 @@ std::vector<FillVertex> buildTextVertices(const OverscaledTileID& id, }; if (prev) { - textPoints.emplace_back(prev->x, prev->y); - textPoints.emplace_back(p.x, p.y); + textPoints.emplace_back(FillAttributes::vertex(*prev)); + textPoints.emplace_back(FillAttributes::vertex(p)); } prev = p; diff --git a/src/mbgl/renderer/debug_bucket.hpp b/src/mbgl/renderer/debug_bucket.hpp index cdffdd8d7a..beb57fa51a 100644 --- a/src/mbgl/renderer/debug_bucket.hpp +++ b/src/mbgl/renderer/debug_bucket.hpp @@ -6,7 +6,7 @@ #include <mbgl/util/optional.hpp> #include <mbgl/util/noncopyable.hpp> #include <mbgl/gl/vertex_buffer.hpp> -#include <mbgl/shader/fill_vertex.hpp> +#include <mbgl/shader/fill_attributes.hpp> namespace mbgl { diff --git a/src/mbgl/renderer/fill_bucket.cpp b/src/mbgl/renderer/fill_bucket.cpp index 9a6f31cbfc..97ba5c5f9e 100644 --- a/src/mbgl/renderer/fill_bucket.cpp +++ b/src/mbgl/renderer/fill_bucket.cpp @@ -58,11 +58,11 @@ void FillBucket::addGeometry(const GeometryCollection& geometry) { assert(lineSegment.vertexLength <= std::numeric_limits<uint16_t>::max()); uint16_t lineIndex = lineSegment.vertexLength; - vertices.emplace_back(ring[0].x, ring[0].y); + vertices.emplace_back(FillAttributes::vertex(ring[0])); lines.emplace_back(lineIndex + nVertices - 1, lineIndex); for (uint32_t i = 1; i < nVertices; i++) { - vertices.emplace_back(ring[i].x, ring[i].y); + vertices.emplace_back(FillAttributes::vertex(ring[i])); lines.emplace_back(lineIndex + i - 1, lineIndex + i); } diff --git a/src/mbgl/renderer/fill_bucket.hpp b/src/mbgl/renderer/fill_bucket.hpp index 715b8e2745..c7f07b51e7 100644 --- a/src/mbgl/renderer/fill_bucket.hpp +++ b/src/mbgl/renderer/fill_bucket.hpp @@ -5,7 +5,7 @@ #include <mbgl/gl/vertex_buffer.hpp> #include <mbgl/gl/index_buffer.hpp> #include <mbgl/gl/segment.hpp> -#include <mbgl/shader/fill_vertex.hpp> +#include <mbgl/shader/fill_attributes.hpp> #include <vector> diff --git a/src/mbgl/renderer/line_bucket.cpp b/src/mbgl/renderer/line_bucket.cpp index 9856684c58..1db075652c 100644 --- a/src/mbgl/renderer/line_bucket.cpp +++ b/src/mbgl/renderer/line_bucket.cpp @@ -372,12 +372,10 @@ void LineBucket::addCurrentVertex(const GeometryCoordinate& currentCoordinate, bool round, std::size_t startVertex, std::vector<TriangleElement>& triangleStore) { - int8_t tx = round ? 1 : 0; - Point<double> extrude = normal; if (endLeft) extrude = extrude - (util::perp(normal) * endLeft); - vertices.emplace_back(currentCoordinate.x, currentCoordinate.y, extrude.x, extrude.y, tx, 0, endLeft, distance * LINE_DISTANCE_SCALE); + vertices.emplace_back(LineAttributes::vertex(currentCoordinate, extrude, { round, false }, endLeft, distance * LINE_DISTANCE_SCALE)); e3 = vertices.size() - 1 - startVertex; if (e1 >= 0 && e2 >= 0) { triangleStore.emplace_back(e1, e2, e3); @@ -388,7 +386,7 @@ void LineBucket::addCurrentVertex(const GeometryCoordinate& currentCoordinate, extrude = normal * -1.0; if (endRight) extrude = extrude - (util::perp(normal) * endRight); - vertices.emplace_back(currentCoordinate.x, currentCoordinate.y, extrude.x, extrude.y, tx, 1, -endRight, distance * LINE_DISTANCE_SCALE); + vertices.emplace_back(LineAttributes::vertex(currentCoordinate, extrude, { round, true }, -endRight, distance * LINE_DISTANCE_SCALE)); e3 = vertices.size() - 1 - startVertex; if (e1 >= 0 && e2 >= 0) { triangleStore.emplace_back(e1, e2, e3); @@ -412,10 +410,8 @@ void LineBucket::addPieSliceVertex(const GeometryCoordinate& currentVertex, bool lineTurnsLeft, std::size_t startVertex, std::vector<TriangleElement>& triangleStore) { - int8_t ty = lineTurnsLeft; - Point<double> flippedExtrude = extrude * (lineTurnsLeft ? -1.0 : 1.0); - vertices.emplace_back(currentVertex.x, currentVertex.y, flippedExtrude.x, flippedExtrude.y, 0, ty, 0, distance * LINE_DISTANCE_SCALE); + vertices.emplace_back(LineAttributes::vertex(currentVertex, flippedExtrude, { false, lineTurnsLeft }, 0, distance * LINE_DISTANCE_SCALE)); e3 = vertices.size() - 1 - startVertex; if (e1 >= 0 && e2 >= 0) { triangleStore.emplace_back(e1, e2, e3); diff --git a/src/mbgl/renderer/line_bucket.hpp b/src/mbgl/renderer/line_bucket.hpp index 7b4c5f1b57..1123ddadb6 100644 --- a/src/mbgl/renderer/line_bucket.hpp +++ b/src/mbgl/renderer/line_bucket.hpp @@ -5,7 +5,7 @@ #include <mbgl/gl/vertex_buffer.hpp> #include <mbgl/gl/index_buffer.hpp> #include <mbgl/gl/segment.hpp> -#include <mbgl/shader/line_vertex.hpp> +#include <mbgl/shader/line_attributes.hpp> #include <mbgl/style/layers/line_layer_properties.hpp> #include <vector> diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index 7ab7b741ea..6777871516 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -45,25 +45,25 @@ Painter::Painter(gl::Context& context_, const TransformState& state_) : context(context_), state(state_), tileTriangleVertexBuffer(context.createVertexBuffer(std::vector<FillVertex> {{ - { 0, 0 }, - { util::EXTENT, 0 }, - { 0, util::EXTENT }, - { util::EXTENT, 0 }, - { 0, util::EXTENT }, - { util::EXTENT, util::EXTENT } + FillAttributes::vertex({ 0, 0 }), + FillAttributes::vertex({ util::EXTENT, 0 }), + FillAttributes::vertex({ 0, util::EXTENT }), + FillAttributes::vertex({ util::EXTENT, 0 }), + FillAttributes::vertex({ 0, util::EXTENT }), + FillAttributes::vertex({ util::EXTENT, util::EXTENT }) }})), tileLineStripVertexBuffer(context.createVertexBuffer(std::vector<FillVertex> {{ - { 0, 0 }, - { util::EXTENT, 0 }, - { util::EXTENT, util::EXTENT }, - { 0, util::EXTENT }, - { 0, 0 } + FillAttributes::vertex({ 0, 0 }), + FillAttributes::vertex({ util::EXTENT, 0 }), + FillAttributes::vertex({ util::EXTENT, util::EXTENT }), + FillAttributes::vertex({ 0, util::EXTENT }), + FillAttributes::vertex({ 0, 0 }) }})), rasterVertexBuffer(context.createVertexBuffer(std::vector<RasterVertex> {{ - { 0, 0, 0, 0 }, - { util::EXTENT, 0, 32767, 0 }, - { 0, util::EXTENT, 0, 32767 }, - { util::EXTENT, util::EXTENT, 32767, 32767 } + RasterAttributes::vertex({ 0, 0 }, { 0, 0 }), + RasterAttributes::vertex({ util::EXTENT, 0 }, { 32767, 0 }), + RasterAttributes::vertex({ 0, util::EXTENT }, { 0, 32767 }), + RasterAttributes::vertex({ util::EXTENT, util::EXTENT }, { 32767, 32767 }) }})) { #ifndef NDEBUG gl::debugging::enable(); diff --git a/src/mbgl/renderer/painter.hpp b/src/mbgl/renderer/painter.hpp index ea60f79801..d7154397f3 100644 --- a/src/mbgl/renderer/painter.hpp +++ b/src/mbgl/renderer/painter.hpp @@ -9,8 +9,8 @@ #include <mbgl/renderer/bucket.hpp> #include <mbgl/gl/context.hpp> -#include <mbgl/shader/fill_vertex.hpp> -#include <mbgl/shader/raster_vertex.hpp> +#include <mbgl/shader/fill_attributes.hpp> +#include <mbgl/shader/raster_attributes.hpp> #include <mbgl/style/style.hpp> diff --git a/src/mbgl/renderer/symbol_bucket.hpp b/src/mbgl/renderer/symbol_bucket.hpp index a905e25363..993d3b85d8 100644 --- a/src/mbgl/renderer/symbol_bucket.hpp +++ b/src/mbgl/renderer/symbol_bucket.hpp @@ -5,8 +5,8 @@ #include <mbgl/gl/vertex_buffer.hpp> #include <mbgl/gl/index_buffer.hpp> #include <mbgl/gl/segment.hpp> -#include <mbgl/shader/symbol_vertex.hpp> -#include <mbgl/shader/collision_box_vertex.hpp> +#include <mbgl/shader/symbol_attributes.hpp> +#include <mbgl/shader/collision_box_attributes.hpp> #include <mbgl/text/glyph_range.hpp> #include <mbgl/style/layers/symbol_layer_properties.hpp> diff --git a/src/mbgl/shader/attributes.hpp b/src/mbgl/shader/attributes.hpp new file mode 100644 index 0000000000..38bbe89377 --- /dev/null +++ b/src/mbgl/shader/attributes.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include <mbgl/gl/attribute.hpp> + +#include <cstdint> + +namespace mbgl { +namespace attributes { + +// Attributes common to several shaders. + +MBGL_DEFINE_ATTRIBUTE(int16_t, 2, a_pos); +MBGL_DEFINE_ATTRIBUTE(int16_t, 2, a_offset); +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<a_data<N>, uint8_t, N> { + static constexpr auto name = "a_data"; +}; + +} // namespace attributes +} // namespace mbgl diff --git a/src/mbgl/shader/circle_attributes.hpp b/src/mbgl/shader/circle_attributes.hpp new file mode 100644 index 0000000000..92f8ff1e5c --- /dev/null +++ b/src/mbgl/shader/circle_attributes.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include <mbgl/shader/attributes.hpp> +#include <mbgl/util/geometry.hpp> + +namespace mbgl { + +struct CircleAttributes : gl::Attributes< + attributes::a_pos> +{ + /* + * @param {number} x vertex position + * @param {number} y vertex position + * @param {number} ex extrude normal + * @param {number} ey extrude normal + */ + static Vertex vertex(Point<int16_t> p, float ex, float ey) { + return Vertex { + { + static_cast<int16_t>((p.x * 2) + ((ex + 1) / 2)), + static_cast<int16_t>((p.y * 2) + ((ey + 1) / 2)) + } + }; + } +}; + +using CircleVertex = CircleAttributes::Vertex; +static_assert(sizeof(CircleVertex) == 4, "expected CircleVertex size"); + +} // namespace mbgl diff --git a/src/mbgl/shader/circle_shader.cpp b/src/mbgl/shader/circle_shader.cpp index c43c435e1b..f873d834f0 100644 --- a/src/mbgl/shader/circle_shader.cpp +++ b/src/mbgl/shader/circle_shader.cpp @@ -1,7 +1,6 @@ #include <mbgl/shader/circle_shader.hpp> #include <mbgl/shader/circle.vertex.hpp> #include <mbgl/shader/circle.fragment.hpp> -#include <mbgl/shader/circle_vertex.hpp> namespace mbgl { @@ -10,6 +9,7 @@ CircleShader::CircleShader(gl::Context& context, Defines defines) shaders::circle::vertex, shaders::circle::fragment, context, defines), + attributesState(CircleAttributes::state(*this)), uniformsState(CircleUniforms::state(*this)) { } diff --git a/src/mbgl/shader/circle_shader.hpp b/src/mbgl/shader/circle_shader.hpp index 1c67fd02f3..35d052bf9b 100644 --- a/src/mbgl/shader/circle_shader.hpp +++ b/src/mbgl/shader/circle_shader.hpp @@ -1,22 +1,19 @@ #pragma once #include <mbgl/gl/shader.hpp> -#include <mbgl/gl/attribute.hpp> +#include <mbgl/shader/circle_attributes.hpp> #include <mbgl/shader/circle_uniforms.hpp> namespace mbgl { -class CircleVertex; - class CircleShader : public gl::Shader { public: CircleShader(gl::Context&, Defines defines = None); - using VertexType = CircleVertex; + using AttributesType = CircleAttributes; using UniformsType = CircleUniforms; - gl::Attribute<int16_t, 2> a_pos = {"a_pos", *this}; - + typename CircleAttributes::State attributesState; typename CircleUniforms::State uniformsState; }; diff --git a/src/mbgl/shader/circle_vertex.cpp b/src/mbgl/shader/circle_vertex.cpp deleted file mode 100644 index 8beb88e650..0000000000 --- a/src/mbgl/shader/circle_vertex.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include <mbgl/shader/circle_vertex.hpp> - -namespace mbgl { - -static_assert(sizeof(CircleVertex) == 4, "expected CircleVertex size"); - -} // namespace mbgl diff --git a/src/mbgl/shader/circle_vertex.hpp b/src/mbgl/shader/circle_vertex.hpp deleted file mode 100644 index 62e6e2da5b..0000000000 --- a/src/mbgl/shader/circle_vertex.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include <mbgl/gl/attribute.hpp> - -#include <vector> -#include <cstdint> - -namespace mbgl { - -class CircleVertex { -public: - /* - * @param {number} x vertex position - * @param {number} y vertex position - * @param {number} ex extrude normal - * @param {number} ey extrude normal - */ - CircleVertex(int16_t x, int16_t y, float ex, float ey) - : a_pos { - static_cast<int16_t>((x * 2) + ((ex + 1) / 2)), - static_cast<int16_t>((y * 2) + ((ey + 1) / 2)) - } {} - - const int16_t a_pos[2]; -}; - -namespace gl { - -template <class Shader> -struct AttributeBindings<Shader, CircleVertex> { - std::vector<AttributeBinding> operator()(const Shader& shader) { - return {{ - MBGL_MAKE_ATTRIBUTE_BINDING(CircleVertex, shader, a_pos) - }}; - }; -}; - -} // namespace gl -} // namespace mbgl diff --git a/src/mbgl/shader/collision_box_attributes.hpp b/src/mbgl/shader/collision_box_attributes.hpp new file mode 100644 index 0000000000..c3131d6c27 --- /dev/null +++ b/src/mbgl/shader/collision_box_attributes.hpp @@ -0,0 +1,36 @@ +#pragma once + +#include <mbgl/shader/attributes.hpp> +#include <mbgl/util/geometry.hpp> + +#include <cmath> + +namespace mbgl { + +struct CollisionBoxAttributes : gl::Attributes< + attributes::a_pos, + attributes::a_extrude, + attributes::a_data<2>> +{ + static Vertex vertex(Point<float> a, Point<float> o, float maxzoom, float placementZoom) { + return Vertex { + { + static_cast<int16_t>(a.x), + static_cast<int16_t>(a.y) + }, + { + static_cast<int16_t>(::round(o.x)), + static_cast<int16_t>(::round(o.y)) + }, + { + static_cast<uint8_t>(maxzoom * 10), + static_cast<uint8_t>(placementZoom * 10) + } + }; + } +}; + +using CollisionBoxVertex = CollisionBoxAttributes::Vertex; +static_assert(sizeof(CollisionBoxVertex) == 10, "expected CollisionBoxVertex size"); + +} // namespace mbgl diff --git a/src/mbgl/shader/collision_box_shader.cpp b/src/mbgl/shader/collision_box_shader.cpp index f12327102a..61f6113234 100644 --- a/src/mbgl/shader/collision_box_shader.cpp +++ b/src/mbgl/shader/collision_box_shader.cpp @@ -1,7 +1,6 @@ #include <mbgl/shader/collision_box_shader.hpp> #include <mbgl/shader/collision_box.vertex.hpp> #include <mbgl/shader/collision_box.fragment.hpp> -#include <mbgl/shader/collision_box_vertex.hpp> namespace mbgl { @@ -10,6 +9,7 @@ CollisionBoxShader::CollisionBoxShader(gl::Context& context) shaders::collision_box::vertex, shaders::collision_box::fragment, context), + attributesState(CollisionBoxAttributes::state(*this)), uniformsState(CollisionBoxUniforms::state(*this)) { } diff --git a/src/mbgl/shader/collision_box_shader.hpp b/src/mbgl/shader/collision_box_shader.hpp index 337de77150..8995507eee 100644 --- a/src/mbgl/shader/collision_box_shader.hpp +++ b/src/mbgl/shader/collision_box_shader.hpp @@ -1,24 +1,19 @@ #pragma once #include <mbgl/gl/shader.hpp> -#include <mbgl/gl/attribute.hpp> #include <mbgl/shader/collision_box_uniforms.hpp> +#include <mbgl/shader/collision_box_attributes.hpp> namespace mbgl { -class CollisionBoxVertex; - class CollisionBoxShader : public gl::Shader { public: CollisionBoxShader(gl::Context&); - using VertexType = CollisionBoxVertex; + using AttributesType = CollisionBoxAttributes; using UniformsType = CollisionBoxUniforms; - gl::Attribute<int16_t, 2> a_pos = {"a_pos", *this}; - gl::Attribute<int16_t, 2> a_extrude = {"a_extrude", *this}; - gl::Attribute<uint8_t, 2> a_data = {"a_data", *this}; - + typename CollisionBoxAttributes::State attributesState; typename CollisionBoxUniforms::State uniformsState; }; diff --git a/src/mbgl/shader/collision_box_vertex.cpp b/src/mbgl/shader/collision_box_vertex.cpp deleted file mode 100644 index 397fbfe6a3..0000000000 --- a/src/mbgl/shader/collision_box_vertex.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include <mbgl/shader/collision_box_vertex.hpp> - -namespace mbgl { - -static_assert(sizeof(CollisionBoxVertex) == 10, "expected CollisionBoxVertex size"); - -} // namespace mbgl diff --git a/src/mbgl/shader/collision_box_vertex.hpp b/src/mbgl/shader/collision_box_vertex.hpp deleted file mode 100644 index 563b6403bf..0000000000 --- a/src/mbgl/shader/collision_box_vertex.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once - -#include <mbgl/gl/attribute.hpp> - -#include <vector> -#include <cstdint> -#include <cmath> - -namespace mbgl { - -class CollisionBoxVertex { -public: - CollisionBoxVertex(int16_t x, int16_t y, float ox, float oy, float maxzoom, float placementZoom) - : a_pos { x, y }, - a_extrude { - static_cast<int16_t>(::round(ox)), - static_cast<int16_t>(::round(oy)) - }, - a_data { - static_cast<uint8_t>(maxzoom * 10), - static_cast<uint8_t>(placementZoom * 10) - } {} - - const int16_t a_pos[2]; - const int16_t a_extrude[2]; - const uint8_t a_data[2]; -}; - -namespace gl { - -template <class Shader> -struct AttributeBindings<Shader, CollisionBoxVertex> { - std::vector<AttributeBinding> operator()(const Shader& shader) { - return {{ - MBGL_MAKE_ATTRIBUTE_BINDING(CollisionBoxVertex, shader, a_pos), - MBGL_MAKE_ATTRIBUTE_BINDING(CollisionBoxVertex, shader, a_extrude), - MBGL_MAKE_ATTRIBUTE_BINDING(CollisionBoxVertex, shader, a_data) - }}; - }; -}; - -} // namespace gl -} // namespace mbgl diff --git a/src/mbgl/shader/fill_attributes.hpp b/src/mbgl/shader/fill_attributes.hpp new file mode 100644 index 0000000000..83e4df3543 --- /dev/null +++ b/src/mbgl/shader/fill_attributes.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include <mbgl/shader/attributes.hpp> +#include <mbgl/util/geometry.hpp> + +namespace mbgl { + +struct FillAttributes : gl::Attributes< + attributes::a_pos> { + + static Vertex vertex(Point<int16_t> p) { + return Vertex { + { + p.x, + p.y + } + }; + } +}; + +using FillVertex = FillAttributes::Vertex; +static_assert(sizeof(FillVertex) == 4, "expected FillVertex size"); + +} // namespace mbgl diff --git a/src/mbgl/shader/fill_outline_pattern_shader.cpp b/src/mbgl/shader/fill_outline_pattern_shader.cpp index 7b9cf81c6d..723366f6d0 100644 --- a/src/mbgl/shader/fill_outline_pattern_shader.cpp +++ b/src/mbgl/shader/fill_outline_pattern_shader.cpp @@ -1,7 +1,6 @@ #include <mbgl/shader/fill_outline_pattern_shader.hpp> #include <mbgl/shader/fill_outline_pattern.vertex.hpp> #include <mbgl/shader/fill_outline_pattern.fragment.hpp> -#include <mbgl/shader/fill_vertex.hpp> namespace mbgl { @@ -10,6 +9,7 @@ FillOutlinePatternShader::FillOutlinePatternShader(gl::Context& context, Defines shaders::fill_outline_pattern::vertex, shaders::fill_outline_pattern::fragment, context, defines), + attributesState(FillAttributes::state(*this)), uniformsState(FillPatternUniforms::state(*this)) { } diff --git a/src/mbgl/shader/fill_outline_pattern_shader.hpp b/src/mbgl/shader/fill_outline_pattern_shader.hpp index c76b93c355..a33aa532fe 100644 --- a/src/mbgl/shader/fill_outline_pattern_shader.hpp +++ b/src/mbgl/shader/fill_outline_pattern_shader.hpp @@ -1,22 +1,19 @@ #pragma once #include <mbgl/gl/shader.hpp> -#include <mbgl/gl/attribute.hpp> #include <mbgl/shader/fill_uniforms.hpp> +#include <mbgl/shader/fill_attributes.hpp> namespace mbgl { -class FillVertex; - class FillOutlinePatternShader : public gl::Shader { public: FillOutlinePatternShader(gl::Context&, Defines defines = None); - using VertexType = FillVertex; + using AttributesType = FillAttributes; using UniformsType = FillPatternUniforms; - gl::Attribute<int16_t, 2> a_pos = {"a_pos", *this}; - + typename FillAttributes::State attributesState; typename FillPatternUniforms::State uniformsState; }; diff --git a/src/mbgl/shader/fill_outline_shader.cpp b/src/mbgl/shader/fill_outline_shader.cpp index f3d8ac5f5b..909b652e7f 100644 --- a/src/mbgl/shader/fill_outline_shader.cpp +++ b/src/mbgl/shader/fill_outline_shader.cpp @@ -1,7 +1,6 @@ #include <mbgl/shader/fill_outline_shader.hpp> #include <mbgl/shader/fill_outline.vertex.hpp> #include <mbgl/shader/fill_outline.fragment.hpp> -#include <mbgl/shader/fill_vertex.hpp> namespace mbgl { @@ -10,6 +9,7 @@ FillOutlineShader::FillOutlineShader(gl::Context& context, Defines defines) shaders::fill_outline::vertex, shaders::fill_outline::fragment, context, defines), + attributesState(FillAttributes::state(*this)), uniformsState(FillColorUniforms::state(*this)) { } diff --git a/src/mbgl/shader/fill_outline_shader.hpp b/src/mbgl/shader/fill_outline_shader.hpp index 4194f7c8c0..e68861641f 100644 --- a/src/mbgl/shader/fill_outline_shader.hpp +++ b/src/mbgl/shader/fill_outline_shader.hpp @@ -1,22 +1,19 @@ #pragma once #include <mbgl/gl/shader.hpp> -#include <mbgl/gl/attribute.hpp> #include <mbgl/shader/fill_uniforms.hpp> +#include <mbgl/shader/fill_attributes.hpp> namespace mbgl { -class FillVertex; - class FillOutlineShader : public gl::Shader { public: FillOutlineShader(gl::Context&, Defines defines = None); - using VertexType = FillVertex; + using AttributesType = FillAttributes; using UniformsType = FillColorUniforms; - gl::Attribute<int16_t, 2> a_pos = {"a_pos", *this}; - + typename FillAttributes::State attributesState; typename FillColorUniforms::State uniformsState; }; diff --git a/src/mbgl/shader/fill_pattern_shader.cpp b/src/mbgl/shader/fill_pattern_shader.cpp index b3cd2c595c..60f9d74c1a 100644 --- a/src/mbgl/shader/fill_pattern_shader.cpp +++ b/src/mbgl/shader/fill_pattern_shader.cpp @@ -1,7 +1,6 @@ #include <mbgl/shader/fill_pattern_shader.hpp> #include <mbgl/shader/fill_pattern.vertex.hpp> #include <mbgl/shader/fill_pattern.fragment.hpp> -#include <mbgl/shader/fill_vertex.hpp> namespace mbgl { @@ -10,6 +9,7 @@ FillPatternShader::FillPatternShader(gl::Context& context, Defines defines) shaders::fill_pattern::vertex, shaders::fill_pattern::fragment, context, defines), + attributesState(FillAttributes::state(*this)), uniformsState(FillPatternUniforms::state(*this)) { } diff --git a/src/mbgl/shader/fill_pattern_shader.hpp b/src/mbgl/shader/fill_pattern_shader.hpp index 92a16ee45a..1ea378b822 100644 --- a/src/mbgl/shader/fill_pattern_shader.hpp +++ b/src/mbgl/shader/fill_pattern_shader.hpp @@ -1,22 +1,19 @@ #pragma once #include <mbgl/gl/shader.hpp> -#include <mbgl/gl/attribute.hpp> #include <mbgl/shader/fill_uniforms.hpp> +#include <mbgl/shader/fill_attributes.hpp> namespace mbgl { -class FillVertex; - class FillPatternShader : public gl::Shader { public: FillPatternShader(gl::Context&, Defines defines = None); - using VertexType = FillVertex; + using AttributesType = FillAttributes; using UniformsType = FillPatternUniforms; - gl::Attribute<int16_t, 2> a_pos = {"a_pos", *this}; - + typename FillAttributes::State attributesState; typename FillPatternUniforms::State uniformsState; }; diff --git a/src/mbgl/shader/fill_shader.cpp b/src/mbgl/shader/fill_shader.cpp index 59028d7384..457ecbb0ba 100644 --- a/src/mbgl/shader/fill_shader.cpp +++ b/src/mbgl/shader/fill_shader.cpp @@ -1,7 +1,6 @@ #include <mbgl/shader/fill_shader.hpp> #include <mbgl/shader/fill.vertex.hpp> #include <mbgl/shader/fill.fragment.hpp> -#include <mbgl/shader/fill_vertex.hpp> namespace mbgl { @@ -10,6 +9,7 @@ FillShader::FillShader(gl::Context& context, Defines defines) shaders::fill::vertex, shaders::fill::fragment, context, defines), + attributesState(FillAttributes::state(*this)), uniformsState(FillColorUniforms::state(*this)) { } diff --git a/src/mbgl/shader/fill_shader.hpp b/src/mbgl/shader/fill_shader.hpp index a7f3b8e2f9..4b8b4ed4f9 100644 --- a/src/mbgl/shader/fill_shader.hpp +++ b/src/mbgl/shader/fill_shader.hpp @@ -1,22 +1,19 @@ #pragma once #include <mbgl/gl/shader.hpp> -#include <mbgl/gl/attribute.hpp> #include <mbgl/shader/fill_uniforms.hpp> +#include <mbgl/shader/fill_attributes.hpp> namespace mbgl { -class FillVertex; - class FillShader : public gl::Shader { public: FillShader(gl::Context&, Defines defines = None); - using VertexType = FillVertex; + using AttributesType = FillAttributes; using UniformsType = FillColorUniforms; - gl::Attribute<int16_t, 2> a_pos = {"a_pos", *this}; - + typename FillAttributes::State attributesState; typename FillColorUniforms::State uniformsState; }; diff --git a/src/mbgl/shader/fill_vertex.cpp b/src/mbgl/shader/fill_vertex.cpp deleted file mode 100644 index c39a0b96b1..0000000000 --- a/src/mbgl/shader/fill_vertex.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include <mbgl/shader/fill_vertex.hpp> - -namespace mbgl { - -static_assert(sizeof(FillVertex) == 4, "expected FillVertex size"); - -} // namespace mbgl diff --git a/src/mbgl/shader/fill_vertex.hpp b/src/mbgl/shader/fill_vertex.hpp deleted file mode 100644 index 86b83d28e5..0000000000 --- a/src/mbgl/shader/fill_vertex.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -#include <mbgl/gl/attribute.hpp> - -#include <vector> -#include <cstdint> - -namespace mbgl { - -class FillVertex { -public: - FillVertex(int16_t x, int16_t y) - : a_pos { x, y } {} - - const int16_t a_pos[2]; -}; - -namespace gl { - -template <class Shader> -struct AttributeBindings<Shader, FillVertex> { - std::vector<AttributeBinding> operator()(const Shader& shader) { - return {{ - MBGL_MAKE_ATTRIBUTE_BINDING(FillVertex, shader, a_pos) - }}; - }; -}; - -} // namespace gl -} // namespace mbgl diff --git a/src/mbgl/shader/line_attributes.hpp b/src/mbgl/shader/line_attributes.hpp new file mode 100644 index 0000000000..1f7dc85201 --- /dev/null +++ b/src/mbgl/shader/line_attributes.hpp @@ -0,0 +1,60 @@ +#pragma once + +#include <mbgl/shader/attributes.hpp> +#include <mbgl/util/geometry.hpp> + +#include <cmath> + +namespace mbgl { + +struct LineAttributes : gl::Attributes< + attributes::a_pos, + attributes::a_data<4>> { + + /* + * @param p vertex position + * @param e extrude normal + * @param t texture normal + * @param dir direction of the line cap (-1/0/1) + */ + static Vertex vertex(Point<int16_t> p, Point<double> e, Point<bool> t, int8_t dir, int32_t linesofar = 0) { + return Vertex { + { + static_cast<int16_t>((p.x * 2) | t.x), + static_cast<int16_t>((p.y * 2) | t.y) + }, + { + // add 128 to store an byte in an unsigned byte + static_cast<uint8_t>(::round(extrudeScale * e.x) + 128), + static_cast<uint8_t>(::round(extrudeScale * e.y) + 128), + + // Encode the -1/0/1 direction value into the first two bits of .z of a_data. + // Combine it with the lower 6 bits of `linesofar` (shifted by 2 bites to make + // room for the direction value). The upper 8 bits of `linesofar` are placed in + // the `w` component. `linesofar` is scaled down by `LINE_DISTANCE_SCALE` so that + // we can store longer distances while sacrificing precision. + + // Encode the -1/0/1 direction value into .zw coordinates of a_data, which is normally covered + // by linesofar, so we need to merge them. + // The z component's first bit, as well as the sign bit is reserved for the direction, + // so we need to shift the linesofar. + static_cast<uint8_t>(((dir == 0 ? 0 : (dir < 0 ? -1 : 1 )) + 1) | ((linesofar & 0x3F) << 2)), + static_cast<uint8_t>(linesofar >> 6) + } + }; + } + + /* + * Scale the extrusion vector so that the normal length is this value. + * Contains the "texture" normals (-1..1). This is distinct from the extrude + * normals for line joins, because the x-value remains 0 for the texture + * normal array, while the extrude normal actually moves the vertex to create + * the acute/bevelled line join. + */ + static const int8_t extrudeScale = 63; +}; + +using LineVertex = LineAttributes::Vertex; +static_assert(sizeof(LineVertex) == 8, "expected LineVertex size"); + +} // namespace mbgl diff --git a/src/mbgl/shader/line_pattern_shader.cpp b/src/mbgl/shader/line_pattern_shader.cpp index 134e619b22..6085e033c6 100644 --- a/src/mbgl/shader/line_pattern_shader.cpp +++ b/src/mbgl/shader/line_pattern_shader.cpp @@ -1,7 +1,6 @@ #include <mbgl/shader/line_pattern_shader.hpp> #include <mbgl/shader/line_pattern.vertex.hpp> #include <mbgl/shader/line_pattern.fragment.hpp> -#include <mbgl/shader/line_vertex.hpp> namespace mbgl { @@ -10,6 +9,7 @@ LinePatternShader::LinePatternShader(gl::Context& context, Defines defines) shaders::line_pattern::vertex, shaders::line_pattern::fragment, context, defines), + attributesState(LineAttributes::state(*this)), uniformsState(LinePatternUniforms::state(*this)) { } diff --git a/src/mbgl/shader/line_pattern_shader.hpp b/src/mbgl/shader/line_pattern_shader.hpp index 57fb7b6d61..d1013ce4f0 100644 --- a/src/mbgl/shader/line_pattern_shader.hpp +++ b/src/mbgl/shader/line_pattern_shader.hpp @@ -1,23 +1,19 @@ #pragma once #include <mbgl/gl/shader.hpp> -#include <mbgl/gl/attribute.hpp> #include <mbgl/shader/line_uniforms.hpp> +#include <mbgl/shader/line_attributes.hpp> namespace mbgl { -class LineVertex; - class LinePatternShader : public gl::Shader { public: LinePatternShader(gl::Context&, Defines defines = None); - using VertexType = LineVertex; + using AttributesType = LineAttributes; using UniformsType = LinePatternUniforms; - gl::Attribute<int16_t, 2> a_pos = { "a_pos", *this }; - gl::Attribute<uint8_t, 4> a_data = { "a_data", *this }; - + typename LineAttributes::State attributesState; typename LinePatternUniforms::State uniformsState; }; diff --git a/src/mbgl/shader/line_sdf_shader.cpp b/src/mbgl/shader/line_sdf_shader.cpp index d290c16676..ee36c3309f 100644 --- a/src/mbgl/shader/line_sdf_shader.cpp +++ b/src/mbgl/shader/line_sdf_shader.cpp @@ -1,7 +1,6 @@ #include <mbgl/shader/line_sdf_shader.hpp> #include <mbgl/shader/line_sdf.vertex.hpp> #include <mbgl/shader/line_sdf.fragment.hpp> -#include <mbgl/shader/line_vertex.hpp> namespace mbgl { @@ -10,6 +9,7 @@ LineSDFShader::LineSDFShader(gl::Context& context, Defines defines) shaders::line_sdf::vertex, shaders::line_sdf::fragment, context, defines), + attributesState(LineAttributes::state(*this)), uniformsState(LineSDFUniforms::state(*this)) { } diff --git a/src/mbgl/shader/line_sdf_shader.hpp b/src/mbgl/shader/line_sdf_shader.hpp index b6cced7ae7..4f793f5609 100644 --- a/src/mbgl/shader/line_sdf_shader.hpp +++ b/src/mbgl/shader/line_sdf_shader.hpp @@ -1,23 +1,19 @@ #pragma once #include <mbgl/gl/shader.hpp> -#include <mbgl/gl/attribute.hpp> #include <mbgl/shader/line_uniforms.hpp> +#include <mbgl/shader/line_attributes.hpp> namespace mbgl { -class LineVertex; - class LineSDFShader : public gl::Shader { public: LineSDFShader(gl::Context&, Defines defines = None); - using VertexType = LineVertex; + using AttributesType = LineAttributes; using UniformsType = LineSDFUniforms; - gl::Attribute<int16_t, 2> a_pos = { "a_pos", *this }; - gl::Attribute<uint8_t, 4> a_data = { "a_data", *this }; - + typename LineAttributes::State attributesState; typename LineSDFUniforms::State uniformsState; }; diff --git a/src/mbgl/shader/line_shader.cpp b/src/mbgl/shader/line_shader.cpp index 07227070be..4bb44de16d 100644 --- a/src/mbgl/shader/line_shader.cpp +++ b/src/mbgl/shader/line_shader.cpp @@ -1,7 +1,6 @@ #include <mbgl/shader/line_shader.hpp> #include <mbgl/shader/line.vertex.hpp> #include <mbgl/shader/line.fragment.hpp> -#include <mbgl/shader/line_vertex.hpp> namespace mbgl { @@ -10,6 +9,7 @@ LineShader::LineShader(gl::Context& context, Defines defines) shaders::line::vertex, shaders::line::fragment, context, defines), + attributesState(LineAttributes::state(*this)), uniformsState(LineColorUniforms::state(*this)) { } diff --git a/src/mbgl/shader/line_shader.hpp b/src/mbgl/shader/line_shader.hpp index eafaf15bef..91ae41e95a 100644 --- a/src/mbgl/shader/line_shader.hpp +++ b/src/mbgl/shader/line_shader.hpp @@ -1,23 +1,19 @@ #pragma once #include <mbgl/gl/shader.hpp> -#include <mbgl/gl/attribute.hpp> #include <mbgl/shader/line_uniforms.hpp> +#include <mbgl/shader/line_attributes.hpp> namespace mbgl { -class LineVertex; - class LineShader : public gl::Shader { public: LineShader(gl::Context&, Defines defines = None); - using VertexType = LineVertex; + using AttributesType = LineAttributes; using UniformsType = LineColorUniforms; - gl::Attribute<int16_t, 2> a_pos = { "a_pos", *this }; - gl::Attribute<uint8_t, 4> a_data = { "a_data", *this }; - + typename LineAttributes::State attributesState; typename LineColorUniforms::State uniformsState; }; diff --git a/src/mbgl/shader/line_vertex.cpp b/src/mbgl/shader/line_vertex.cpp deleted file mode 100644 index ad466310d8..0000000000 --- a/src/mbgl/shader/line_vertex.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include <mbgl/shader/line_vertex.hpp> - -namespace mbgl { - -static_assert(sizeof(LineVertex) == 8, "expected LineVertex size"); - -} // namespace mbgl diff --git a/src/mbgl/shader/line_vertex.hpp b/src/mbgl/shader/line_vertex.hpp deleted file mode 100644 index 6d299c5197..0000000000 --- a/src/mbgl/shader/line_vertex.hpp +++ /dev/null @@ -1,72 +0,0 @@ -#pragma once - -#include <mbgl/gl/attribute.hpp> - -#include <vector> -#include <cstdint> -#include <cmath> - -namespace mbgl { - -class LineVertex { -public: - /* - * @param {number} x vertex position - * @param {number} y vertex position - * @param {number} ex extrude normal - * @param {number} ey extrude normal - * @param {number} tx texture normal - * @param {number} ty texture normal - * @param {number} dir direction of the line cap (-1/0/1) - */ - LineVertex(int16_t x, int16_t y, float ex, float ey, bool tx, bool ty, int8_t dir, int32_t linesofar = 0) - : a_pos { - static_cast<int16_t>((x * 2) | tx), - static_cast<int16_t>((y * 2) | ty) - }, - a_data { - // add 128 to store an byte in an unsigned byte - static_cast<uint8_t>(::round(extrudeScale * ex) + 128), - static_cast<uint8_t>(::round(extrudeScale * ey) + 128), - - // Encode the -1/0/1 direction value into the first two bits of .z of a_data. - // Combine it with the lower 6 bits of `linesofar` (shifted by 2 bites to make - // room for the direction value). The upper 8 bits of `linesofar` are placed in - // the `w` component. `linesofar` is scaled down by `LINE_DISTANCE_SCALE` so that - // we can store longer distances while sacrificing precision. - - // Encode the -1/0/1 direction value into .zw coordinates of a_data, which is normally covered - // by linesofar, so we need to merge them. - // The z component's first bit, as well as the sign bit is reserved for the direction, - // so we need to shift the linesofar. - static_cast<uint8_t>(((dir == 0 ? 0 : (dir < 0 ? -1 : 1 )) + 1) | ((linesofar & 0x3F) << 2)), - static_cast<uint8_t>(linesofar >> 6) - } {} - - const int16_t a_pos[2]; - const uint8_t a_data[4]; - - /* - * Scale the extrusion vector so that the normal length is this value. - * Contains the "texture" normals (-1..1). This is distinct from the extrude - * normals for line joins, because the x-value remains 0 for the texture - * normal array, while the extrude normal actually moves the vertex to create - * the acute/bevelled line join. - */ - static const int8_t extrudeScale = 63; -}; - -namespace gl { - -template <class Shader> -struct AttributeBindings<Shader, LineVertex> { - std::vector<AttributeBinding> operator()(const Shader& shader) { - return {{ - MBGL_MAKE_ATTRIBUTE_BINDING(LineVertex, shader, a_pos), - MBGL_MAKE_ATTRIBUTE_BINDING(LineVertex, shader, a_data) - }}; - }; -}; - -} // namespace gl -} // namespace mbgl diff --git a/src/mbgl/shader/raster_attributes.hpp b/src/mbgl/shader/raster_attributes.hpp new file mode 100644 index 0000000000..88f0125754 --- /dev/null +++ b/src/mbgl/shader/raster_attributes.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include <mbgl/shader/attributes.hpp> +#include <mbgl/util/geometry.hpp> + +namespace mbgl { + +struct RasterAttributes : gl::Attributes< + attributes::a_pos, + attributes::a_texture_pos> +{ + static Vertex vertex(Point<int16_t> p, Point<uint16_t> t) { + return Vertex { + { + p.x, + p.y + }, + { + t.x, + t.y + } + }; + } +}; + +using RasterVertex = RasterAttributes::Vertex; +static_assert(sizeof(RasterVertex) == 8, "expected RasterVertex size"); + +} // namespace mbgl diff --git a/src/mbgl/shader/raster_shader.cpp b/src/mbgl/shader/raster_shader.cpp index 17d6b246a1..4f1d873044 100644 --- a/src/mbgl/shader/raster_shader.cpp +++ b/src/mbgl/shader/raster_shader.cpp @@ -1,7 +1,6 @@ #include <mbgl/shader/raster_shader.hpp> #include <mbgl/shader/raster.vertex.hpp> #include <mbgl/shader/raster.fragment.hpp> -#include <mbgl/shader/raster_vertex.hpp> namespace mbgl { @@ -10,6 +9,7 @@ RasterShader::RasterShader(gl::Context& context, Defines defines) shaders::raster::vertex, shaders::raster::fragment, context, defines), + attributesState(RasterAttributes::state(*this)), uniformsState(RasterUniforms::state(*this)) { } diff --git a/src/mbgl/shader/raster_shader.hpp b/src/mbgl/shader/raster_shader.hpp index 977556a097..6d85175d77 100644 --- a/src/mbgl/shader/raster_shader.hpp +++ b/src/mbgl/shader/raster_shader.hpp @@ -1,23 +1,19 @@ #pragma once #include <mbgl/gl/shader.hpp> -#include <mbgl/gl/attribute.hpp> #include <mbgl/shader/raster_uniforms.hpp> +#include <mbgl/shader/raster_attributes.hpp> namespace mbgl { -class RasterVertex; - class RasterShader : public gl::Shader { public: RasterShader(gl::Context&, Defines defines = None); - using VertexType = RasterVertex; + using AttributesType = RasterAttributes; using UniformsType = RasterUniforms; - gl::Attribute<int16_t, 2> a_pos = { "a_pos", *this }; - gl::Attribute<uint16_t, 2> a_texture_pos = { "a_texture_pos", *this }; - + typename RasterAttributes::State attributesState; typename RasterUniforms::State uniformsState; }; diff --git a/src/mbgl/shader/raster_vertex.cpp b/src/mbgl/shader/raster_vertex.cpp deleted file mode 100644 index fc9b1f11c2..0000000000 --- a/src/mbgl/shader/raster_vertex.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include <mbgl/shader/raster_vertex.hpp> - -namespace mbgl { - -static_assert(sizeof(RasterVertex) == 8, "expected RasterVertex size"); - -} // namespace mbgl diff --git a/src/mbgl/shader/raster_vertex.hpp b/src/mbgl/shader/raster_vertex.hpp deleted file mode 100644 index 889405d6cd..0000000000 --- a/src/mbgl/shader/raster_vertex.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include <mbgl/gl/attribute.hpp> - -#include <vector> -#include <cstdint> - -namespace mbgl { - -class RasterVertex { -public: - RasterVertex(int16_t x, int16_t y, uint16_t tx, uint16_t ty) - : a_pos { - x, - y - }, - a_texture_pos { - tx, - ty - } {} - - const int16_t a_pos[2]; - const uint16_t a_texture_pos[2]; -}; - -namespace gl { - -template <class Shader> -struct AttributeBindings<Shader, RasterVertex> { - std::vector<AttributeBinding> operator()(const Shader& shader) { - return {{ - MBGL_MAKE_ATTRIBUTE_BINDING(RasterVertex, shader, a_pos), - MBGL_MAKE_ATTRIBUTE_BINDING(RasterVertex, shader, a_texture_pos) - }}; - }; -}; - -} // namespace gl -} // namespace mbgl diff --git a/src/mbgl/shader/symbol_attributes.hpp b/src/mbgl/shader/symbol_attributes.hpp new file mode 100644 index 0000000000..32f252e49a --- /dev/null +++ b/src/mbgl/shader/symbol_attributes.hpp @@ -0,0 +1,50 @@ +#pragma once + +#include <mbgl/shader/attributes.hpp> +#include <mbgl/util/geometry.hpp> + +#include <cmath> + +namespace mbgl { + +struct SymbolAttributes : gl::Attributes< + attributes::a_pos, + attributes::a_offset, + attributes::a_texture_pos, + attributes::a_data<4>> +{ + static Vertex vertex(Point<float> a, + Point<float> o, + uint16_t tx, + uint16_t ty, + float minzoom, + float maxzoom, + float labelminzoom, + uint8_t labelangle) { + return Vertex { + { + static_cast<int16_t>(a.x), + static_cast<int16_t>(a.y) + }, + { + static_cast<int16_t>(::round(o.x * 64)), // use 1/64 pixels for placement + static_cast<int16_t>(::round(o.y * 64)) + }, + { + static_cast<uint16_t>(tx / 4), + static_cast<uint16_t>(ty / 4) + }, + { + static_cast<uint8_t>(labelminzoom * 10), // 1/10 zoom levels: z16 == 160 + static_cast<uint8_t>(labelangle), + static_cast<uint8_t>(minzoom * 10), + static_cast<uint8_t>(::fmin(maxzoom, 25) * 10) + } + }; + } +}; + +using SymbolVertex = SymbolAttributes::Vertex; +static_assert(sizeof(SymbolVertex) == 16, "expected SymbolVertex size"); + +} // namespace mbgl diff --git a/src/mbgl/shader/symbol_icon_shader.cpp b/src/mbgl/shader/symbol_icon_shader.cpp index 66fce84d83..c6677eb38e 100644 --- a/src/mbgl/shader/symbol_icon_shader.cpp +++ b/src/mbgl/shader/symbol_icon_shader.cpp @@ -1,7 +1,6 @@ #include <mbgl/shader/symbol_icon_shader.hpp> #include <mbgl/shader/symbol_icon.vertex.hpp> #include <mbgl/shader/symbol_icon.fragment.hpp> -#include <mbgl/shader/symbol_vertex.hpp> namespace mbgl { @@ -10,6 +9,7 @@ SymbolIconShader::SymbolIconShader(gl::Context& context, Defines defines) shaders::symbol_icon::vertex, shaders::symbol_icon::fragment, context, defines), + attributesState(SymbolAttributes::state(*this)), uniformsState(SymbolIconUniforms::state(*this)) { } diff --git a/src/mbgl/shader/symbol_icon_shader.hpp b/src/mbgl/shader/symbol_icon_shader.hpp index 95b669e8f7..b04ae76d75 100644 --- a/src/mbgl/shader/symbol_icon_shader.hpp +++ b/src/mbgl/shader/symbol_icon_shader.hpp @@ -1,25 +1,19 @@ #pragma once #include <mbgl/gl/shader.hpp> -#include <mbgl/gl/attribute.hpp> #include <mbgl/shader/symbol_uniforms.hpp> +#include <mbgl/shader/symbol_attributes.hpp> namespace mbgl { -class SymbolVertex; - class SymbolIconShader : public gl::Shader { public: SymbolIconShader(gl::Context&, Defines defines = None); - using VertexType = SymbolVertex; + using AttributesType = SymbolAttributes; using UniformsType = SymbolIconUniforms; - gl::Attribute<int16_t, 2> a_pos = { "a_pos", *this }; - gl::Attribute<int16_t, 2> a_offset = { "a_offset", *this }; - gl::Attribute<uint16_t, 2> a_texture_pos = { "a_texture_pos", *this }; - gl::Attribute<uint8_t, 4> a_data = { "a_data", *this }; - + typename SymbolAttributes::State attributesState; typename SymbolIconUniforms::State uniformsState; }; diff --git a/src/mbgl/shader/symbol_sdf_shader.cpp b/src/mbgl/shader/symbol_sdf_shader.cpp index b8dffbab11..aeb45e1099 100644 --- a/src/mbgl/shader/symbol_sdf_shader.cpp +++ b/src/mbgl/shader/symbol_sdf_shader.cpp @@ -1,7 +1,6 @@ #include <mbgl/shader/symbol_sdf_shader.hpp> #include <mbgl/shader/symbol_sdf.vertex.hpp> #include <mbgl/shader/symbol_sdf.fragment.hpp> -#include <mbgl/shader/symbol_vertex.hpp> namespace mbgl { @@ -10,6 +9,7 @@ SymbolSDFShader::SymbolSDFShader(gl::Context& context, Defines defines) shaders::symbol_sdf::vertex, shaders::symbol_sdf::fragment, context, defines), + attributesState(SymbolAttributes::state(*this)), uniformsState(SymbolSDFUniforms::state(*this)) { } diff --git a/src/mbgl/shader/symbol_sdf_shader.hpp b/src/mbgl/shader/symbol_sdf_shader.hpp index b7c12811c0..5ebfca5a43 100644 --- a/src/mbgl/shader/symbol_sdf_shader.hpp +++ b/src/mbgl/shader/symbol_sdf_shader.hpp @@ -1,25 +1,19 @@ #pragma once #include <mbgl/gl/shader.hpp> -#include <mbgl/gl/attribute.hpp> #include <mbgl/shader/symbol_uniforms.hpp> +#include <mbgl/shader/symbol_attributes.hpp> namespace mbgl { -class SymbolVertex; - class SymbolSDFShader : public gl::Shader { public: SymbolSDFShader(gl::Context&, Defines defines = None); - using VertexType = SymbolVertex; + using AttributesType = SymbolAttributes; using UniformsType = SymbolSDFUniforms; - gl::Attribute<int16_t, 2> a_pos = { "a_pos", *this }; - gl::Attribute<int16_t, 2> a_offset = { "a_offset", *this }; - gl::Attribute<uint16_t, 2> a_texture_pos = { "a_texture_pos", *this }; - gl::Attribute<uint8_t, 4> a_data = { "a_data", *this }; - + typename SymbolAttributes::State attributesState; typename SymbolSDFUniforms::State uniformsState; }; diff --git a/src/mbgl/shader/symbol_vertex.cpp b/src/mbgl/shader/symbol_vertex.cpp deleted file mode 100644 index e29226527f..0000000000 --- a/src/mbgl/shader/symbol_vertex.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include <mbgl/shader/symbol_vertex.hpp> -#include <mbgl/gl/shader.hpp> - -namespace mbgl { - -static_assert(sizeof(SymbolVertex) == 16, "expected SymbolVertex size"); - -} // namespace mbgl diff --git a/src/mbgl/shader/symbol_vertex.hpp b/src/mbgl/shader/symbol_vertex.hpp deleted file mode 100644 index 4bb6c82a60..0000000000 --- a/src/mbgl/shader/symbol_vertex.hpp +++ /dev/null @@ -1,54 +0,0 @@ -#pragma once - -#include <mbgl/gl/attribute.hpp> - -#include <vector> -#include <cstdint> -#include <cmath> - -namespace mbgl { - -class SymbolVertex { -public: - SymbolVertex(int16_t x, int16_t y, float ox, float oy, uint16_t tx, uint16_t ty, float minzoom, float maxzoom, float labelminzoom, uint8_t labelangle) - : a_pos { - x, - y - }, - a_offset { - static_cast<int16_t>(::round(ox * 64)), // use 1/64 pixels for placement - static_cast<int16_t>(::round(oy * 64)) - }, - a_texture_pos { - static_cast<uint16_t>(tx / 4), - static_cast<uint16_t>(ty / 4) - }, - a_data { - static_cast<uint8_t>(labelminzoom * 10), // 1/10 zoom levels: z16 == 160 - static_cast<uint8_t>(labelangle), - static_cast<uint8_t>(minzoom * 10), - static_cast<uint8_t>(::fmin(maxzoom, 25) * 10) - } {} - - const int16_t a_pos[2]; - const int16_t a_offset[2]; - const uint16_t a_texture_pos[2]; - const uint8_t a_data[4]; -}; - -namespace gl { - -template <class Shader> -struct AttributeBindings<Shader, SymbolVertex> { - std::vector<AttributeBinding> operator()(const Shader& shader) { - return {{ - MBGL_MAKE_ATTRIBUTE_BINDING(SymbolVertex, shader, a_pos), - MBGL_MAKE_ATTRIBUTE_BINDING(SymbolVertex, shader, a_offset), - MBGL_MAKE_ATTRIBUTE_BINDING(SymbolVertex, shader, a_texture_pos), - MBGL_MAKE_ATTRIBUTE_BINDING(SymbolVertex, shader, a_data) - }}; - }; -}; - -} // namespace gl -} // namespace mbgl |