From 95deab32ceadd2bca3912d866e76c6b0f1b931f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Thu, 28 Feb 2019 14:28:58 +0100 Subject: [core] extract attribute structs and gl::Vertex to separate namespace --- src/core-files.json | 1 + src/mbgl/gfx/attribute.hpp | 148 ++++++++++++++++ src/mbgl/gl/attribute.cpp | 11 ++ src/mbgl/gl/attribute.hpp | 195 +++------------------ src/mbgl/gl/uniform.hpp | 10 +- src/mbgl/layout/symbol_projection.cpp | 8 +- src/mbgl/layout/symbol_projection.hpp | 2 +- src/mbgl/programs/attributes.hpp | 157 +++-------------- src/mbgl/programs/circle_program.hpp | 2 +- src/mbgl/programs/collision_box_program.hpp | 34 ++-- src/mbgl/programs/debug_program.hpp | 2 +- src/mbgl/programs/extrusion_texture_program.hpp | 2 +- src/mbgl/programs/fill_extrusion_program.hpp | 2 +- src/mbgl/programs/heatmap_program.hpp | 2 +- src/mbgl/programs/heatmap_texture_program.hpp | 2 +- src/mbgl/programs/hillshade_prepare_program.hpp | 2 +- src/mbgl/programs/hillshade_program.hpp | 2 +- src/mbgl/programs/line_program.hpp | 2 +- src/mbgl/programs/program.hpp | 33 ++-- src/mbgl/programs/raster_program.hpp | 2 +- src/mbgl/programs/symbol_program.hpp | 60 +++---- src/mbgl/renderer/buckets/circle_bucket.cpp | 2 +- src/mbgl/renderer/buckets/circle_bucket.hpp | 2 +- src/mbgl/renderer/buckets/fill_bucket.hpp | 2 +- .../renderer/buckets/fill_extrusion_bucket.hpp | 2 +- src/mbgl/renderer/buckets/heatmap_bucket.hpp | 2 +- src/mbgl/renderer/buckets/line_bucket.cpp | 2 +- src/mbgl/renderer/buckets/line_bucket.hpp | 2 +- src/mbgl/renderer/buckets/symbol_bucket.hpp | 28 +-- .../renderer/layers/render_background_layer.cpp | 3 +- src/mbgl/renderer/layers/render_custom_layer.cpp | 1 + .../layers/render_fill_extrusion_layer.cpp | 3 +- src/mbgl/renderer/layers/render_heatmap_layer.cpp | 2 +- src/mbgl/renderer/layers/render_heatmap_layer.hpp | 1 + .../renderer/layers/render_hillshade_layer.cpp | 4 +- src/mbgl/renderer/layers/render_line_layer.hpp | 1 + src/mbgl/renderer/layers/render_raster_layer.cpp | 2 +- src/mbgl/renderer/layers/render_symbol_layer.cpp | 4 +- src/mbgl/renderer/paint_parameters.hpp | 4 + src/mbgl/renderer/paint_property_binder.hpp | 66 ++++--- src/mbgl/renderer/render_layer.cpp | 1 + src/mbgl/renderer/render_static_data.cpp | 12 +- src/mbgl/renderer/render_static_data.hpp | 2 +- src/mbgl/renderer/render_tile.cpp | 2 +- src/mbgl/renderer/renderer_impl.cpp | 2 +- src/mbgl/renderer/sources/render_image_source.cpp | 2 +- src/mbgl/style/layers/line_layer_properties.hpp | 2 +- src/mbgl/style/paint_property.hpp | 8 +- src/mbgl/style/properties.hpp | 3 +- src/mbgl/util/offscreen_texture.hpp | 2 + test/gl/bucket.test.cpp | 4 +- 51 files changed, 393 insertions(+), 459 deletions(-) create mode 100644 src/mbgl/gfx/attribute.hpp diff --git a/src/core-files.json b/src/core-files.json index 590cd3c620..8efb9062de 100644 --- a/src/core-files.json +++ b/src/core-files.json @@ -498,6 +498,7 @@ "mbgl/geometry/dem_data.hpp": "src/mbgl/geometry/dem_data.hpp", "mbgl/geometry/feature_index.hpp": "src/mbgl/geometry/feature_index.hpp", "mbgl/geometry/line_atlas.hpp": "src/mbgl/geometry/line_atlas.hpp", + "mbgl/gfx/attribute.hpp": "src/mbgl/gfx/attribute.hpp", "mbgl/gfx/uniform.hpp": "src/mbgl/gfx/uniform.hpp", "mbgl/gl/attribute.hpp": "src/mbgl/gl/attribute.hpp", "mbgl/gl/color_mode.hpp": "src/mbgl/gl/color_mode.hpp", diff --git a/src/mbgl/gfx/attribute.hpp b/src/mbgl/gfx/attribute.hpp new file mode 100644 index 0000000000..66bbf1ec5e --- /dev/null +++ b/src/mbgl/gfx/attribute.hpp @@ -0,0 +1,148 @@ +#pragma once + +#include +#include + +#include +#include + +#define MBGL_DEFINE_ATTRIBUTE(type_, n_, name_) \ + struct name_ { \ + using Type = ::mbgl::gfx::AttributeType; \ + static auto name() { \ + return #name_; \ + } \ + } + +namespace mbgl { +namespace gfx { + +template +class AttributeType { +public: + using ValueType = T; + static constexpr size_t Dimensions = N; + using Value = std::array; +}; + +// 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. + +namespace detail { + +template +class Vertex; + +template <> +class Vertex<> { +public: + using VertexType = Vertex<>; +}; + +template +class Vertex { +public: + A1 a1; + + using VertexType = Vertex; + static const std::size_t attributeOffsets[1]; +}; + +template +class Vertex { +public: + A1 a1; + A2 a2; + + using VertexType = Vertex; + static const std::size_t attributeOffsets[2]; +}; + +template +class Vertex { +public: + A1 a1; + A2 a2; + A3 a3; + + using VertexType = Vertex; + static const std::size_t attributeOffsets[3]; +}; + +template +class Vertex { +public: + A1 a1; + A2 a2; + A3 a3; + A4 a4; + + using VertexType = Vertex; + static const std::size_t attributeOffsets[4]; +}; + +template +class Vertex { +public: + A1 a1; + A2 a2; + A3 a3; + A4 a4; + A5 a5; + + using VertexType = Vertex; + static const std::size_t attributeOffsets[5]; +}; + +template +const std::size_t Vertex::attributeOffsets[1] = { + offsetof(VertexType, a1) +}; + +template +const std::size_t Vertex::attributeOffsets[2] = { + offsetof(VertexType, a1), + offsetof(VertexType, a2) +}; + +template +const std::size_t Vertex::attributeOffsets[3] = { + offsetof(VertexType, a1), + offsetof(VertexType, a2), + offsetof(VertexType, a3) +}; + +template +const std::size_t Vertex::attributeOffsets[4] = { + offsetof(VertexType, a1), + offsetof(VertexType, a2), + offsetof(VertexType, a3), + offsetof(VertexType, a4) +}; + +template +const std::size_t Vertex::attributeOffsets[5] = { + offsetof(VertexType, a1), + offsetof(VertexType, a2), + offsetof(VertexType, a3), + offsetof(VertexType, a4), + offsetof(VertexType, a5) +}; + +template +class Vertex> { +public: + using VertexType = Vertex; +}; + +} // namespace detail + +template +using Vertex = typename detail::Vertex::VertexType; + +} // namespace gfx +} // namespace mbgl diff --git a/src/mbgl/gl/attribute.cpp b/src/mbgl/gl/attribute.cpp index 4983a8c204..1b43ad2b64 100644 --- a/src/mbgl/gl/attribute.cpp +++ b/src/mbgl/gl/attribute.cpp @@ -7,6 +7,17 @@ namespace gl { using namespace platform; +optional offsetAttributeBinding(const optional& binding, std::size_t vertexOffset) { + assert(vertexOffset <= std::numeric_limits::max()); + if (binding) { + AttributeBinding result = *binding; + result.vertexOffset = static_cast(vertexOffset); + return result; + } else { + return binding; + } +} + void bindAttributeLocation(Context& context, ProgramID id, AttributeLocation location, const char* name) { // We're using sequentially numberered attribute locations starting with 0. Therefore we can use // the location as a proxy for the number of attributes. diff --git a/src/mbgl/gl/attribute.hpp b/src/mbgl/gl/attribute.hpp index a1c35f3746..95a9942381 100644 --- a/src/mbgl/gl/attribute.hpp +++ b/src/mbgl/gl/attribute.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -45,176 +46,41 @@ public: using AttributeBindingArray = std::vector>; -/* - gl::Attribute manages the binding of a vertex buffer to a GL program attribute. - - T is the underlying primitive type (exposed as Attribute::ValueType) - - N is the number of components in the attribute declared in the shader (exposed as Attribute::Dimensions) -*/ -template -class Attribute { -public: - using ValueType = T; - static constexpr size_t Dimensions = N; - using Value = std::array; - /* Create a binding for this attribute. The `attributeSize` parameter may be used to override the number of components available in the buffer for each vertex. Thus, a buffer with only one float for each vertex can be bound to a `vec2` attribute */ - template - static AttributeBinding binding(const VertexBuffer& buffer, - std::size_t attributeIndex, - std::size_t attributeSize = N) { - static_assert(std::is_standard_layout::value, "vertex type must use standard layout"); - assert(attributeSize >= 1); - assert(attributeSize <= 4); - assert(Vertex::attributeOffsets[attributeIndex] <= std::numeric_limits::max()); - static_assert(sizeof(Vertex) <= std::numeric_limits::max(), "vertex too large"); - return AttributeBinding { - DataTypeOf::value, - static_cast(attributeSize), - static_cast(Vertex::attributeOffsets[attributeIndex]), - buffer.buffer, - static_cast(sizeof(Vertex)), - 0, - }; - } - - static optional offsetBinding(const optional& binding, std::size_t vertexOffset) { - assert(vertexOffset <= std::numeric_limits::max()); - if (binding) { - AttributeBinding result = *binding; - result.vertexOffset = static_cast(vertexOffset); - return result; - } else { - return binding; - } - } -}; - -#define MBGL_DEFINE_ATTRIBUTE(type_, n_, name_) \ - struct name_ { \ - static auto name() { return #name_; } \ - using Type = ::mbgl::gl::Attribute; \ - } - -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 Vertex; - -template <> -class Vertex<> { -public: - using VertexType = Vertex<>; -}; - -template -class Vertex { -public: - typename A1::Value a1; - - using VertexType = Vertex; - static const std::size_t attributeOffsets[1]; -}; - -template -class Vertex { -public: - typename A1::Value a1; - typename A2::Value a2; - - using VertexType = Vertex; - static const std::size_t attributeOffsets[2]; -}; - -template -class Vertex { -public: - typename A1::Value a1; - typename A2::Value a2; - typename A3::Value a3; - - using VertexType = Vertex; - static const std::size_t attributeOffsets[3]; -}; - -template -class Vertex { -public: - typename A1::Value a1; - typename A2::Value a2; - typename A3::Value a3; - typename A4::Value a4; - - using VertexType = Vertex; - static const std::size_t attributeOffsets[4]; -}; - -template -class Vertex { -public: - typename A1::Value a1; - typename A2::Value a2; - typename A3::Value a3; - typename A4::Value a4; - typename A5::Value a5; - - using VertexType = Vertex; - static const std::size_t attributeOffsets[5]; -}; - -template -const std::size_t Vertex::attributeOffsets[1] = { - offsetof(VertexType, a1) -}; - -template -const std::size_t Vertex::attributeOffsets[2] = { - offsetof(VertexType, a1), - offsetof(VertexType, a2) -}; - -template -const std::size_t Vertex::attributeOffsets[3] = { - offsetof(VertexType, a1), - offsetof(VertexType, a2), - offsetof(VertexType, a3) -}; - -template -const std::size_t Vertex::attributeOffsets[4] = { - offsetof(VertexType, a1), - offsetof(VertexType, a2), - offsetof(VertexType, a3), - offsetof(VertexType, a4) -}; - -template -const std::size_t Vertex::attributeOffsets[5] = { - offsetof(VertexType, a1), - offsetof(VertexType, a2), - offsetof(VertexType, a3), - offsetof(VertexType, a4), - offsetof(VertexType, a5) -}; - -} // namespace detail +template +AttributeBinding attributeBinding(const VertexBuffer& buffer, + std::size_t attributeIndex, + std::size_t attributeSize = AttributeType::Dimensions) { + static_assert(std::is_standard_layout::value, "vertex type must use standard layout"); + assert(attributeSize >= 1); + assert(attributeSize <= 4); + assert(Vertex::attributeOffsets[attributeIndex] <= std::numeric_limits::max()); + static_assert(sizeof(Vertex) <= std::numeric_limits::max(), "vertex too large"); + return AttributeBinding { + DataTypeOf::value, + static_cast(attributeSize), + static_cast(Vertex::attributeOffsets[attributeIndex]), + buffer.buffer, + static_cast(sizeof(Vertex)), + 0, + }; +} + +optional offsetAttributeBinding(const optional& binding, std::size_t vertexOffset); class Context; void bindAttributeLocation(Context&, ProgramID, AttributeLocation, const char * name); std::set getActiveAttributes(ProgramID); +template +class Attributes; + template -class Attributes final { +class Attributes> final { public: using Types = TypeList; using Locations = IndexedTuple< @@ -225,8 +91,6 @@ public: TypeList>...>>; using NamedLocations = std::vector>; - using Vertex = detail::Vertex; - static Locations bindLocations(Context& context, const ProgramID& id) { std::set activeAttributes = getActiveAttributes(id); @@ -262,12 +126,12 @@ public: return result; } - static Bindings bindings(const VertexBuffer& buffer) { - return Bindings { As::Type::binding(buffer, TypeIndex::value)... }; + static Bindings bindings(const VertexBuffer>& buffer) { + return Bindings { attributeBinding(buffer, TypeIndex::value)... }; } static Bindings offsetBindings(const Bindings& bindings, std::size_t vertexOffset) { - return Bindings { As::Type::offsetBinding(bindings.template get(), vertexOffset)... }; + return Bindings { offsetAttributeBinding(bindings.template get(), vertexOffset)... }; } static AttributeBindingArray toBindingArray(const Locations& locations, const Bindings& bindings) { @@ -293,8 +157,5 @@ public: } }; -template -using ConcatenateAttributes = typename TypeListConcat::template ExpandInto; - } // namespace gl } // namespace mbgl diff --git a/src/mbgl/gl/uniform.hpp b/src/mbgl/gl/uniform.hpp index 62e201ee4b..c5aa2d6c39 100644 --- a/src/mbgl/gl/uniform.hpp +++ b/src/mbgl/gl/uniform.hpp @@ -51,8 +51,11 @@ public: UniformLocation uniformLocation(ProgramID, const char * name); +template +class Uniforms; + template -class Uniforms final { +class Uniforms> final { public: using Types = TypeList; using State = IndexedTuple, TypeList...>>; @@ -77,7 +80,7 @@ public: template static State loadNamedLocations(const Program& program) { - return State(typename Us::State(program.uniformLocation(Us::name()))...); + return State(UniformState(program.uniformLocation(Us::name()))...); } static NamedLocations getNamedLocations(const State& state) { @@ -89,8 +92,5 @@ public: } }; -template -using ConcatenateUniforms = typename TypeListConcat::template ExpandInto; - } // namespace gl } // namespace mbgl diff --git a/src/mbgl/layout/symbol_projection.cpp b/src/mbgl/layout/symbol_projection.cpp index d2dfd12d98..edf916484b 100644 --- a/src/mbgl/layout/symbol_projection.cpp +++ b/src/mbgl/layout/symbol_projection.cpp @@ -122,7 +122,7 @@ namespace mbgl { } void addDynamicAttributes(const Point& anchorPoint, const float angle, - gl::VertexVector& dynamicVertexArray) { + gl::VertexVector>& dynamicVertexArray) { auto dynamicVertex = SymbolSDFIconProgram::dynamicLayoutVertex(anchorPoint, angle); dynamicVertexArray.emplace_back(dynamicVertex); dynamicVertexArray.emplace_back(dynamicVertex); @@ -130,7 +130,7 @@ namespace mbgl { dynamicVertexArray.emplace_back(dynamicVertex); } - void hideGlyphs(size_t numGlyphs, gl::VertexVector& dynamicVertexArray) { + void hideGlyphs(size_t numGlyphs, gl::VertexVector>& dynamicVertexArray) { const Point offscreenPoint = { -INFINITY, -INFINITY }; for (size_t i = 0; i < numGlyphs; i++) { addDynamicAttributes(offscreenPoint, 0, dynamicVertexArray); @@ -288,7 +288,7 @@ namespace mbgl { const mat4& posMatrix, const mat4& labelPlaneMatrix, const mat4& glCoordMatrix, - gl::VertexVector& dynamicVertexArray, + gl::VertexVector>& dynamicVertexArray, const Point& projectedAnchorPoint, const float aspectRatio) { const float fontScale = fontSize / 24.0; @@ -360,7 +360,7 @@ namespace mbgl { } - void reprojectLineLabels(gl::VertexVector& dynamicVertexArray, const std::vector& placedSymbols, + void reprojectLineLabels(gl::VertexVector>& dynamicVertexArray, const std::vector& placedSymbols, const mat4& posMatrix, const style::SymbolPropertyValues& values, const RenderTile& tile, const SymbolSizeBinder& sizeBinder, const TransformState& state) { diff --git a/src/mbgl/layout/symbol_projection.hpp b/src/mbgl/layout/symbol_projection.hpp index 3e57d162fd..f3dd29add1 100644 --- a/src/mbgl/layout/symbol_projection.hpp +++ b/src/mbgl/layout/symbol_projection.hpp @@ -46,7 +46,7 @@ namespace mbgl { using PointAndCameraDistance = std::pair,float>; PointAndCameraDistance project(const Point& point, const mat4& matrix); - void reprojectLineLabels(gl::VertexVector&, const std::vector&, + void reprojectLineLabels(gl::VertexVector>&, const std::vector&, const mat4& posMatrix, const style::SymbolPropertyValues&, const RenderTile&, const SymbolSizeBinder& sizeBinder, const TransformState&); diff --git a/src/mbgl/programs/attributes.hpp b/src/mbgl/programs/attributes.hpp index d5508e8f1a..42079bfd57 100644 --- a/src/mbgl/programs/attributes.hpp +++ b/src/mbgl/programs/attributes.hpp @@ -1,23 +1,10 @@ #pragma once -#include -#include - -#include +#include namespace mbgl { namespace attributes { -/* - * Pack a pair of values, interpreted as uint8's, into a single float. - * Used to conserve vertex attributes. Values are unpacked in the vertex - * shader using the `unpack_float()` function, defined in _prelude.vertex.glsl. - */ -template -inline uint16_t packUint8Pair(T a, T b) { - return static_cast(a) * 256 + static_cast(b); -} - // Layout attributes MBGL_DEFINE_ATTRIBUTE(int16_t, 2, a_pos); @@ -31,134 +18,40 @@ MBGL_DEFINE_ATTRIBUTE(uint16_t, 2, a_texture_pos); MBGL_DEFINE_ATTRIBUTE(int16_t, 4, a_normal_ed); MBGL_DEFINE_ATTRIBUTE(uint8_t, 1, a_fade_opacity); MBGL_DEFINE_ATTRIBUTE(uint8_t, 2, a_placed); +MBGL_DEFINE_ATTRIBUTE(uint16_t, 3, a_size); +MBGL_DEFINE_ATTRIBUTE(float, 1, a_offset); template struct a_data { + using Type = gfx::AttributeType; static auto name() { return "a_data"; } - using Type = gl::Attribute; -}; - -struct a_size { - static auto name() { return "a_size"; } - using Type = gl::Attribute; -}; - -template -struct a_offset { - static auto name() { return "a_offset"; } - using Type = gl::Attribute; }; // Paint attributes -struct a_color { - static auto name() { return "a_color"; } - using Type = gl::Attribute; -}; - -struct a_fill_color { - static auto name() { return "a_fill_color"; } - using Type = gl::Attribute; -}; - -struct a_halo_color { - static auto name() { return "a_halo_color"; } - using Type = gl::Attribute; -}; - -struct a_stroke_color { - static auto name() { return "a_stroke_color"; } - using Type = gl::Attribute; -}; - -struct a_outline_color { - static auto name() { return "a_outline_color"; } - using Type = gl::Attribute; -}; - -struct a_opacity { - static auto name() { return "a_opacity"; } - using Type = gl::Attribute; -}; - -struct a_stroke_opacity { - static auto name() { return "a_stroke_opacity"; } - using Type = gl::Attribute; -}; - -struct a_blur { - static auto name() { return "a_blur"; } - using Type = gl::Attribute; -}; - -struct a_radius { - static auto name() { return "a_radius"; } - using Type = gl::Attribute; -}; - -struct a_width { - static auto name() { return "a_width"; } - using Type = gl::Attribute; -}; - -struct a_floorwidth { - static auto name() { return "a_floorwidth"; } - using Type = gl::Attribute; -}; - -struct a_height { - static auto name() { return "a_height"; } - using Type = gl::Attribute; -}; - -struct a_base { - static auto name() { return "a_base"; } - using Type = gl::Attribute; -}; - -struct a_gapwidth { - static auto name() { return "a_gapwidth"; } - using Type = gl::Attribute; -}; - -struct a_stroke_width { - static auto name() { return "a_stroke_width"; } - using Type = gl::Attribute; -}; - -template <> -struct a_offset<1> { - static auto name() { return "a_offset"; } - using Type = gl::Attribute; -}; - -struct a_halo_width { - static auto name() { return "a_halo_width"; } - using Type = gl::Attribute; -}; - -struct a_halo_blur { - static auto name() { return "a_halo_blur"; } - using Type = gl::Attribute; -}; - -struct a_weight { - static auto name() { return "a_weight"; } - using Type = gl::Attribute; -}; - -struct a_pattern_to { - static auto name() { return "a_pattern_to"; } - using Type = gl::Attribute; -}; - -struct a_pattern_from { - static auto name() { return "a_pattern_from"; } - using Type = gl::Attribute; -}; +MBGL_DEFINE_ATTRIBUTE(float, 2, a_color); +MBGL_DEFINE_ATTRIBUTE(float, 2, a_fill_color); +MBGL_DEFINE_ATTRIBUTE(float, 2, a_halo_color); +MBGL_DEFINE_ATTRIBUTE(float, 2, a_stroke_color); +MBGL_DEFINE_ATTRIBUTE(float, 2, a_outline_color); +MBGL_DEFINE_ATTRIBUTE(float, 1, a_opacity); +MBGL_DEFINE_ATTRIBUTE(float, 1, a_stroke_opacity); +MBGL_DEFINE_ATTRIBUTE(float, 1, a_blur); +MBGL_DEFINE_ATTRIBUTE(float, 1, a_radius); +MBGL_DEFINE_ATTRIBUTE(float, 1, a_width); +MBGL_DEFINE_ATTRIBUTE(float, 1, a_floorwidth); +MBGL_DEFINE_ATTRIBUTE(float, 1, a_height); +MBGL_DEFINE_ATTRIBUTE(float, 1, a_base); +MBGL_DEFINE_ATTRIBUTE(float, 1, a_gapwidth); +MBGL_DEFINE_ATTRIBUTE(float, 1, a_stroke_width); +MBGL_DEFINE_ATTRIBUTE(float, 1, a_halo_width); +MBGL_DEFINE_ATTRIBUTE(float, 1, a_halo_blur); +MBGL_DEFINE_ATTRIBUTE(float, 1, a_weight); +MBGL_DEFINE_ATTRIBUTE(uint16_t, 4, a_pattern_to); +MBGL_DEFINE_ATTRIBUTE(uint16_t, 4, a_pattern_from); } // namespace attributes -using PositionOnlyLayoutAttributes = gl::Attributes; +using PositionOnlyLayoutAttributes = TypeList; } // namespace mbgl diff --git a/src/mbgl/programs/circle_program.hpp b/src/mbgl/programs/circle_program.hpp index debf7a81c2..3e59402a87 100644 --- a/src/mbgl/programs/circle_program.hpp +++ b/src/mbgl/programs/circle_program.hpp @@ -16,7 +16,7 @@ MBGL_DEFINE_UNIFORM_SCALAR(bool, u_scale_with_map); class CircleProgram : public Program< shaders::circle, gl::Triangle, - gl::Attributes< + TypeList< attributes::a_pos>, TypeList< uniforms::u_matrix, diff --git a/src/mbgl/programs/collision_box_program.hpp b/src/mbgl/programs/collision_box_program.hpp index 1a34ebbb11..46fe882f44 100644 --- a/src/mbgl/programs/collision_box_program.hpp +++ b/src/mbgl/programs/collision_box_program.hpp @@ -12,17 +12,17 @@ namespace mbgl { -using CollisionBoxLayoutAttributes = gl::Attributes< +using CollisionBoxLayoutAttributes = TypeList< attributes::a_pos, attributes::a_anchor_pos, attributes::a_extrude>; -using CollisionBoxDynamicAttributes = gl::Attributes; +using CollisionBoxDynamicAttributes = TypeList; class CollisionBoxProgram : public Program< shaders::collision_box, gl::Line, - gl::ConcatenateAttributes, + TypeListConcat, TypeList< uniforms::u_matrix, uniforms::u_extrude_scale, @@ -32,7 +32,7 @@ class CollisionBoxProgram : public Program< public: using Program::Program; - static CollisionBoxLayoutAttributes::Vertex layoutVertex(Point a, Point anchor, Point o) { + static gfx::Vertex layoutVertex(Point a, Point anchor, Point o) { return { {{ static_cast(a.x), @@ -49,7 +49,7 @@ public: }; } - static CollisionBoxDynamicAttributes::Vertex dynamicVertex(bool placed, bool notUsed) { + static gfx::Vertex dynamicVertex(bool placed, bool notUsed) { return { {{ static_cast(placed), static_cast(notUsed) }} }; @@ -63,19 +63,19 @@ public: gl::ColorMode colorMode, gl::CullFaceMode cullFaceMode, const UniformValues& uniformValues, - const gl::VertexBuffer& layoutVertexBuffer, - const gl::VertexBuffer& dynamicVertexBuffer, + const gl::VertexBuffer>& layoutVertexBuffer, + const gl::VertexBuffer>& dynamicVertexBuffer, const gl::IndexBuffer& indexBuffer, const SegmentVector& segments, - const PaintPropertyBinders& paintPropertyBinders, + const Binders& paintPropertyBinders, const typename PaintProperties::PossiblyEvaluated& currentProperties, float currentZoom, const std::string& layerID) { typename AllUniforms::Values allUniformValues = uniformValues .concat(paintPropertyBinders.uniformValues(currentZoom, currentProperties)); - typename Attributes::Bindings allAttributeBindings = CollisionBoxLayoutAttributes::bindings(layoutVertexBuffer) - .concat(CollisionBoxDynamicAttributes::bindings(dynamicVertexBuffer)) + typename Attributes::Bindings allAttributeBindings = gl::Attributes::bindings(layoutVertexBuffer) + .concat(gl::Attributes::bindings(dynamicVertexBuffer)) .concat(paintPropertyBinders.attributeBindings(currentProperties)); assert(layoutVertexBuffer.vertexCount == dynamicVertexBuffer.vertexCount); @@ -108,7 +108,7 @@ public: class CollisionCircleProgram : public Program< shaders::collision_circle, gl::Triangle, - gl::ConcatenateAttributes, + TypeListConcat, TypeList< uniforms::u_matrix, uniforms::u_extrude_scale, @@ -119,7 +119,7 @@ class CollisionCircleProgram : public Program< public: using Program::Program; - static CollisionBoxLayoutAttributes::Vertex vertex(Point a, Point anchor, Point o) { + static gfx::Vertex vertex(Point a, Point anchor, Point o) { return { {{ static_cast(a.x), @@ -144,19 +144,19 @@ public: gl::ColorMode colorMode, gl::CullFaceMode cullFaceMode, const UniformValues& uniformValues, - const gl::VertexBuffer& layoutVertexBuffer, - const gl::VertexBuffer& dynamicVertexBuffer, + const gl::VertexBuffer>& layoutVertexBuffer, + const gl::VertexBuffer>& dynamicVertexBuffer, const gl::IndexBuffer& indexBuffer, const SegmentVector& segments, - const PaintPropertyBinders& paintPropertyBinders, + const Binders& paintPropertyBinders, const typename PaintProperties::PossiblyEvaluated& currentProperties, float currentZoom, const std::string& layerID) { typename AllUniforms::Values allUniformValues = uniformValues .concat(paintPropertyBinders.uniformValues(currentZoom, currentProperties)); - typename Attributes::Bindings allAttributeBindings = CollisionBoxLayoutAttributes::bindings(layoutVertexBuffer) - .concat(CollisionBoxDynamicAttributes::bindings(dynamicVertexBuffer)) + typename Attributes::Bindings allAttributeBindings = gl::Attributes::bindings(layoutVertexBuffer) + .concat(gl::Attributes::bindings(dynamicVertexBuffer)) .concat(paintPropertyBinders.attributeBindings(currentProperties)); for (auto& segment : segments) { diff --git a/src/mbgl/programs/debug_program.hpp b/src/mbgl/programs/debug_program.hpp index 0accd490ab..17e7d638f9 100644 --- a/src/mbgl/programs/debug_program.hpp +++ b/src/mbgl/programs/debug_program.hpp @@ -11,7 +11,7 @@ namespace mbgl { class DebugProgram : public Program< shaders::debug, gl::Line, - gl::Attributes< + TypeList< attributes::a_pos>, TypeList< uniforms::u_matrix, diff --git a/src/mbgl/programs/extrusion_texture_program.hpp b/src/mbgl/programs/extrusion_texture_program.hpp index fc53563e74..d1ae773f90 100644 --- a/src/mbgl/programs/extrusion_texture_program.hpp +++ b/src/mbgl/programs/extrusion_texture_program.hpp @@ -12,7 +12,7 @@ namespace mbgl { class ExtrusionTextureProgram : public Program< shaders::extrusion_texture, gl::Triangle, - gl::Attributes, + TypeList, TypeList< uniforms::u_matrix, uniforms::u_world, diff --git a/src/mbgl/programs/fill_extrusion_program.hpp b/src/mbgl/programs/fill_extrusion_program.hpp index d29f988e7e..4b8c148f11 100644 --- a/src/mbgl/programs/fill_extrusion_program.hpp +++ b/src/mbgl/programs/fill_extrusion_program.hpp @@ -29,7 +29,7 @@ MBGL_DEFINE_UNIFORM_SCALAR(float, u_lightintensity); MBGL_DEFINE_UNIFORM_SCALAR(float, u_height_factor); } // namespace uniforms -using FillExtrusionLayoutAttributes = gl::Attributes< +using FillExtrusionLayoutAttributes = TypeList< attributes::a_pos, attributes::a_normal_ed>; diff --git a/src/mbgl/programs/heatmap_program.hpp b/src/mbgl/programs/heatmap_program.hpp index 98208c02c8..d2fe0320ab 100644 --- a/src/mbgl/programs/heatmap_program.hpp +++ b/src/mbgl/programs/heatmap_program.hpp @@ -17,7 +17,7 @@ MBGL_DEFINE_UNIFORM_SCALAR(float, u_intensity); class HeatmapProgram : public Program< shaders::heatmap, gl::Triangle, - gl::Attributes< + TypeList< attributes::a_pos>, TypeList< uniforms::u_intensity, diff --git a/src/mbgl/programs/heatmap_texture_program.hpp b/src/mbgl/programs/heatmap_texture_program.hpp index 060e0cc397..dea33edc03 100644 --- a/src/mbgl/programs/heatmap_texture_program.hpp +++ b/src/mbgl/programs/heatmap_texture_program.hpp @@ -16,7 +16,7 @@ MBGL_DEFINE_UNIFORM_SCALAR(uint32_t, u_color_ramp); class HeatmapTextureProgram : public Program< shaders::heatmap_texture, gl::Triangle, - gl::Attributes, + TypeList, TypeList< uniforms::u_matrix, uniforms::u_world, diff --git a/src/mbgl/programs/hillshade_prepare_program.hpp b/src/mbgl/programs/hillshade_prepare_program.hpp index fe077611f8..10decd0343 100644 --- a/src/mbgl/programs/hillshade_prepare_program.hpp +++ b/src/mbgl/programs/hillshade_prepare_program.hpp @@ -16,7 +16,7 @@ MBGL_DEFINE_UNIFORM_SCALAR(float, u_maxzoom); class HillshadePrepareProgram : public Program< shaders::hillshade_prepare, gl::Triangle, - gl::Attributes< + TypeList< attributes::a_pos, attributes::a_texture_pos>, TypeList< diff --git a/src/mbgl/programs/hillshade_program.hpp b/src/mbgl/programs/hillshade_program.hpp index 10143146de..9c71afdb9c 100644 --- a/src/mbgl/programs/hillshade_program.hpp +++ b/src/mbgl/programs/hillshade_program.hpp @@ -21,7 +21,7 @@ MBGL_DEFINE_UNIFORM_VECTOR(float, 2, u_latrange); class HillshadeProgram : public Program< shaders::hillshade, gl::Triangle, - gl::Attributes< + TypeList< attributes::a_pos, attributes::a_texture_pos>, TypeList< diff --git a/src/mbgl/programs/line_program.hpp b/src/mbgl/programs/line_program.hpp index 089c2b2c07..1c96ecbf34 100644 --- a/src/mbgl/programs/line_program.hpp +++ b/src/mbgl/programs/line_program.hpp @@ -29,7 +29,7 @@ MBGL_DEFINE_UNIFORM_VECTOR(float, 2, u_patternscale_b); MBGL_DEFINE_UNIFORM_VECTOR(float, 2, u_gl_units_to_pixels); } // namespace uniforms -using LineLayoutAttributes = gl::Attributes< +using LineLayoutAttributes = TypeList< attributes::a_pos_normal, attributes::a_data>; diff --git a/src/mbgl/programs/program.hpp b/src/mbgl/programs/program.hpp index 30d226854f..429937dd7d 100644 --- a/src/mbgl/programs/program.hpp +++ b/src/mbgl/programs/program.hpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -16,22 +17,22 @@ namespace mbgl { template class Program { public: - using LayoutAttributes = LayoutAttrs; - using LayoutVertex = typename LayoutAttributes::Vertex; + using LayoutAttributes = gl::Attributes; + using LayoutVertex = gfx::Vertex; using PaintProperties = PaintProps; - using PaintPropertyBinders = typename PaintProperties::Binders; - using PaintAttributes = typename PaintPropertyBinders::Attributes; - using Attributes = gl::ConcatenateAttributes; + using Binders = PaintPropertyBinders; + using PaintAttributeList = typename Binders::AttributeList; + using Attributes = gl::Attributes>; - using UniformValues = gfx::UniformValues; - using PaintUniformTypeList = typename PaintPropertyBinders::UniformTypeList; - using AllUniforms = typename TypeListConcat::template ExpandInto; + using UniformValues = gfx::UniformValues; + using PaintUniformList = typename Binders::UniformList; + using AllUniforms = gl::Uniforms>; using ProgramType = gl::Program; @@ -48,7 +49,7 @@ public: static typename AllUniforms::Values computeAllUniformValues( const UniformValues& uniformValues, - const PaintPropertyBinders& paintPropertyBinders, + const Binders& paintPropertyBinders, const typename PaintProperties::PossiblyEvaluated& currentProperties, float currentZoom) { return uniformValues @@ -57,7 +58,7 @@ public: static typename Attributes::Bindings computeAllAttributeBindings( const gl::VertexBuffer& layoutVertexBuffer, - const PaintPropertyBinders& paintPropertyBinders, + const Binders& paintPropertyBinders, const typename PaintProperties::PossiblyEvaluated& currentProperties) { return LayoutAttributes::bindings(layoutVertexBuffer) .concat(paintPropertyBinders.attributeBindings(currentProperties)); @@ -107,8 +108,8 @@ template class ProgramMap { public: using PaintProperties = typename Program::PaintProperties; - using PaintPropertyBinders = typename Program::PaintPropertyBinders; - using Bitset = typename PaintPropertyBinders::Bitset; + using Binders = typename Program::Binders; + using Bitset = typename Binders::Bitset; ProgramMap(gl::Context& context_, ProgramParameters parameters_) : context(context_), @@ -116,7 +117,7 @@ public: } Program& get(const typename PaintProperties::PossiblyEvaluated& currentProperties) { - Bitset bits = PaintPropertyBinders::constants(currentProperties); + Bitset bits = Binders::constants(currentProperties); auto it = programs.find(bits); if (it != programs.end()) { return it->second; @@ -124,7 +125,7 @@ public: return programs.emplace(std::piecewise_construct, std::forward_as_tuple(bits), std::forward_as_tuple(context, - parameters.withAdditionalDefines(PaintPropertyBinders::defines(currentProperties)))).first->second; + parameters.withAdditionalDefines(Binders::defines(currentProperties)))).first->second; } private: diff --git a/src/mbgl/programs/raster_program.hpp b/src/mbgl/programs/raster_program.hpp index b470ff6841..45b324696d 100644 --- a/src/mbgl/programs/raster_program.hpp +++ b/src/mbgl/programs/raster_program.hpp @@ -26,7 +26,7 @@ MBGL_DEFINE_UNIFORM_VECTOR(float, 2, u_tl_parent); class RasterProgram : public Program< shaders::raster, gl::Triangle, - gl::Attributes< + TypeList< attributes::a_pos, attributes::a_texture_pos>, TypeList< diff --git a/src/mbgl/programs/symbol_program.hpp b/src/mbgl/programs/symbol_program.hpp index 155c277f11..d6bad6da77 100644 --- a/src/mbgl/programs/symbol_program.hpp +++ b/src/mbgl/programs/symbol_program.hpp @@ -46,13 +46,13 @@ MBGL_DEFINE_UNIFORM_SCALAR(bool, u_rotate_symbol); MBGL_DEFINE_UNIFORM_SCALAR(float, u_aspect_ratio); } // namespace uniforms -using SymbolLayoutAttributes = gl::Attributes< +using SymbolLayoutAttributes = TypeList< attributes::a_pos_offset, attributes::a_data>; -using SymbolDynamicLayoutAttributes = gl::Attributes; +using SymbolDynamicLayoutAttributes = TypeList; -using SymbolOpacityAttributes = gl::Attributes; +using SymbolOpacityAttributes = TypeList; struct ZoomEvaluatedSize { bool isZoomConstant; @@ -69,12 +69,12 @@ class SymbolSizeBinder { public: virtual ~SymbolSizeBinder() = default; - using UniformTypeList = TypeList< + using UniformList = TypeList< uniforms::u_is_size_zoom_constant, uniforms::u_is_size_feature_constant, uniforms::u_size_t, uniforms::u_size>; - using UniformValues = gfx::UniformValues; + using UniformValues = gfx::UniformValues; static std::unique_ptr create(const float tileZoom, const style::PropertyValue& sizeProperty, @@ -146,10 +146,6 @@ public: class SourceFunctionSymbolSizeBinder final : public SymbolSizeBinder { public: - using Vertex = gl::detail::Vertex>; - using VertexVector = gl::VertexVector; - using VertexBuffer = gl::VertexBuffer; - SourceFunctionSymbolSizeBinder(const float /*tileZoom*/, style::PropertyExpression expression_, const float defaultValue_) : expression(std::move(expression_)), defaultValue(defaultValue_) { @@ -204,7 +200,7 @@ public: class SymbolProgramBase { public: - static SymbolLayoutAttributes::Vertex layoutVertex(Point labelAnchor, + static gfx::Vertex layoutVertex(Point labelAnchor, Point o, float glyphOffsetY, uint16_t tx, @@ -227,7 +223,7 @@ public: }; } - static SymbolDynamicLayoutAttributes::Vertex dynamicLayoutVertex(Point anchorPoint, float labelAngle) { + static gfx::Vertex dynamicLayoutVertex(Point anchorPoint, float labelAngle) { return { {{ anchorPoint.x, @@ -237,7 +233,7 @@ public: }; } - static SymbolOpacityAttributes::Vertex opacityVertex(bool placed, float opacity) { + static gfx::Vertex opacityVertex(bool placed, float opacity) { return { {{ static_cast((static_cast(opacity * 127) << 1) | static_cast(placed)) }} }; @@ -246,25 +242,25 @@ public: template class SymbolProgram : public SymbolProgramBase { public: - using LayoutAttributes = LayoutAttrs; - using LayoutVertex = typename LayoutAttributes::Vertex; + using LayoutAttributes = gl::Attributes; + using LayoutVertex = gfx::Vertex; - using LayoutAndSizeAttributes = gl::ConcatenateAttributes; + using LayoutAndSizeAttributeList = TypeListConcat; using PaintProperties = PaintProps; - using PaintPropertyBinders = typename PaintProperties::Binders; - using PaintAttributes = typename PaintPropertyBinders::Attributes; - using Attributes = gl::ConcatenateAttributes; + using Binders = PaintPropertyBinders; + using PaintAttributeList = typename Binders::AttributeList; + using Attributes = gl::Attributes>; - using UniformValues = gfx::UniformValues; - using SizeUniformTypeList = typename SymbolSizeBinder::UniformTypeList; - using PaintUniformTypeList = typename PaintPropertyBinders::UniformTypeList; - using AllUniforms = typename TypeListConcat::template ExpandInto; + using UniformValues = gfx::UniformValues; + using SizeUniformList = typename SymbolSizeBinder::UniformList; + using PaintUniformList = typename Binders::UniformList; + using AllUniforms = gl::Uniforms>; using ProgramType = gl::Program; @@ -282,7 +278,7 @@ public: static typename AllUniforms::Values computeAllUniformValues( const UniformValues& uniformValues, const SymbolSizeBinder& symbolSizeBinder, - const PaintPropertyBinders& paintPropertyBinders, + const Binders& paintPropertyBinders, const typename PaintProperties::PossiblyEvaluated& currentProperties, float currentZoom) { return uniformValues.concat(symbolSizeBinder.uniformValues(currentZoom)) @@ -291,15 +287,15 @@ public: static typename Attributes::Bindings computeAllAttributeBindings( const gl::VertexBuffer& layoutVertexBuffer, - const gl::VertexBuffer& dynamicLayoutVertexBuffer, - const gl::VertexBuffer& opacityVertexBuffer, - const PaintPropertyBinders& paintPropertyBinders, + const gl::VertexBuffer>& dynamicLayoutVertexBuffer, + const gl::VertexBuffer>& opacityVertexBuffer, + const Binders& paintPropertyBinders, const typename PaintProperties::PossiblyEvaluated& currentProperties) { assert(layoutVertexBuffer.vertexCount == dynamicLayoutVertexBuffer.vertexCount && layoutVertexBuffer.vertexCount == opacityVertexBuffer.vertexCount); - return LayoutAttributes::bindings(layoutVertexBuffer) - .concat(SymbolDynamicLayoutAttributes::bindings(dynamicLayoutVertexBuffer)) - .concat(SymbolOpacityAttributes::bindings(opacityVertexBuffer)) + return gl::Attributes::bindings(layoutVertexBuffer) + .concat(gl::Attributes::bindings(dynamicLayoutVertexBuffer)) + .concat(gl::Attributes::bindings(opacityVertexBuffer)) .concat(paintPropertyBinders.attributeBindings(currentProperties)); } @@ -446,7 +442,7 @@ public: using SymbolSDFIconProgram = SymbolSDFProgram; using SymbolSDFTextProgram = SymbolSDFProgram; -using SymbolLayoutVertex = SymbolLayoutAttributes::Vertex; +using SymbolLayoutVertex = gfx::Vertex; using SymbolIconAttributes = SymbolIconProgram::Attributes; using SymbolTextAttributes = SymbolSDFTextProgram::Attributes; diff --git a/src/mbgl/renderer/buckets/circle_bucket.cpp b/src/mbgl/renderer/buckets/circle_bucket.cpp index b2d8d8ee98..bf54205978 100644 --- a/src/mbgl/renderer/buckets/circle_bucket.cpp +++ b/src/mbgl/renderer/buckets/circle_bucket.cpp @@ -99,7 +99,7 @@ void CircleBucket::addFeature(const GeometryTileFeature& feature, } template -static float get(const RenderCircleLayer& layer, const std::map& paintPropertyBinders) { +static float get(const RenderCircleLayer& layer, const std::map& paintPropertyBinders) { auto it = paintPropertyBinders.find(layer.getID()); if (it == paintPropertyBinders.end() || !it->second.statistics().max()) { return layer.evaluated.get().constantOr(Property::defaultValue()); diff --git a/src/mbgl/renderer/buckets/circle_bucket.hpp b/src/mbgl/renderer/buckets/circle_bucket.hpp index dad8b8b377..9082e891e4 100644 --- a/src/mbgl/renderer/buckets/circle_bucket.hpp +++ b/src/mbgl/renderer/buckets/circle_bucket.hpp @@ -37,7 +37,7 @@ public: optional> vertexBuffer; optional> indexBuffer; - std::map paintPropertyBinders; + std::map paintPropertyBinders; const MapMode mode; }; diff --git a/src/mbgl/renderer/buckets/fill_bucket.hpp b/src/mbgl/renderer/buckets/fill_bucket.hpp index 2724e5b7d3..225d4c661d 100644 --- a/src/mbgl/renderer/buckets/fill_bucket.hpp +++ b/src/mbgl/renderer/buckets/fill_bucket.hpp @@ -50,7 +50,7 @@ public: optional> lineIndexBuffer; optional> triangleIndexBuffer; - std::map paintPropertyBinders; + std::map paintPropertyBinders; }; } // namespace mbgl diff --git a/src/mbgl/renderer/buckets/fill_extrusion_bucket.hpp b/src/mbgl/renderer/buckets/fill_extrusion_bucket.hpp index 42344c4b8d..486eb221e5 100644 --- a/src/mbgl/renderer/buckets/fill_extrusion_bucket.hpp +++ b/src/mbgl/renderer/buckets/fill_extrusion_bucket.hpp @@ -46,7 +46,7 @@ public: optional> vertexBuffer; optional> indexBuffer; - std::unordered_map paintPropertyBinders; + std::unordered_map paintPropertyBinders; }; } // namespace mbgl diff --git a/src/mbgl/renderer/buckets/heatmap_bucket.hpp b/src/mbgl/renderer/buckets/heatmap_bucket.hpp index 9bec9208a8..8948f52acb 100644 --- a/src/mbgl/renderer/buckets/heatmap_bucket.hpp +++ b/src/mbgl/renderer/buckets/heatmap_bucket.hpp @@ -36,7 +36,7 @@ public: optional> vertexBuffer; optional> indexBuffer; - std::map paintPropertyBinders; + std::map paintPropertyBinders; const MapMode mode; }; diff --git a/src/mbgl/renderer/buckets/line_bucket.cpp b/src/mbgl/renderer/buckets/line_bucket.cpp index 0375c3d089..f17a309163 100644 --- a/src/mbgl/renderer/buckets/line_bucket.cpp +++ b/src/mbgl/renderer/buckets/line_bucket.cpp @@ -528,7 +528,7 @@ bool LineBucket::supportsLayer(const style::Layer::Impl& impl) const { } template -static float get(const RenderLineLayer& layer, const std::map& paintPropertyBinders) { +static float get(const RenderLineLayer& layer, const std::map& paintPropertyBinders) { auto it = paintPropertyBinders.find(layer.getID()); if (it == paintPropertyBinders.end() || !it->second.statistics().max()) { return layer.evaluated.get().constantOr(Property::defaultValue()); diff --git a/src/mbgl/renderer/buckets/line_bucket.hpp b/src/mbgl/renderer/buckets/line_bucket.hpp index ed742a0e63..5ebb575c6f 100644 --- a/src/mbgl/renderer/buckets/line_bucket.hpp +++ b/src/mbgl/renderer/buckets/line_bucket.hpp @@ -50,7 +50,7 @@ public: optional> vertexBuffer; optional> indexBuffer; - std::map paintPropertyBinders; + std::map paintPropertyBinders; private: void addGeometry(const GeometryCoordinates&, const GeometryTileFeature&); diff --git a/src/mbgl/renderer/buckets/symbol_bucket.hpp b/src/mbgl/renderer/buckets/symbol_bucket.hpp index 0388c5756b..4fa24aa614 100644 --- a/src/mbgl/renderer/buckets/symbol_bucket.hpp +++ b/src/mbgl/renderer/buckets/symbol_bucket.hpp @@ -80,8 +80,8 @@ public: struct PaintProperties { style::SymbolPaintProperties::PossiblyEvaluated evaluated; - SymbolIconProgram::PaintPropertyBinders iconBinders; - SymbolSDFTextProgram::PaintPropertyBinders textBinders; + SymbolIconProgram::Binders iconBinders; + SymbolSDFTextProgram::Binders textBinders; }; std::map paintProperties; @@ -89,15 +89,15 @@ public: struct TextBuffer { gl::VertexVector vertices; - gl::VertexVector dynamicVertices; - gl::VertexVector opacityVertices; + gl::VertexVector> dynamicVertices; + gl::VertexVector> opacityVertices; gl::IndexVector triangles; SegmentVector segments; std::vector placedSymbols; optional> vertexBuffer; - optional> dynamicVertexBuffer; - optional> opacityVertexBuffer; + optional>> dynamicVertexBuffer; + optional>> opacityVertexBuffer; optional> indexBuffer; } text; @@ -105,26 +105,26 @@ public: struct IconBuffer { gl::VertexVector vertices; - gl::VertexVector dynamicVertices; - gl::VertexVector opacityVertices; + gl::VertexVector> dynamicVertices; + gl::VertexVector> opacityVertices; gl::IndexVector triangles; SegmentVector segments; std::vector placedSymbols; PremultipliedImage atlasImage; optional> vertexBuffer; - optional> dynamicVertexBuffer; - optional> opacityVertexBuffer; + optional>> dynamicVertexBuffer; + optional>> opacityVertexBuffer; optional> indexBuffer; } icon; struct CollisionBuffer { - gl::VertexVector vertices; - gl::VertexVector dynamicVertices; + gl::VertexVector> vertices; + gl::VertexVector> dynamicVertices; SegmentVector segments; - optional> vertexBuffer; - optional> dynamicVertexBuffer; + optional>> vertexBuffer; + optional>> dynamicVertexBuffer; }; struct CollisionBoxBuffer : public CollisionBuffer { diff --git a/src/mbgl/renderer/layers/render_background_layer.cpp b/src/mbgl/renderer/layers/render_background_layer.cpp index 4171e3a670..0efee4a5c1 100644 --- a/src/mbgl/renderer/layers/render_background_layer.cpp +++ b/src/mbgl/renderer/layers/render_background_layer.cpp @@ -8,6 +8,7 @@ #include #include #include +#include namespace mbgl { @@ -47,7 +48,7 @@ void RenderBackgroundLayer::render(PaintParameters& parameters, RenderSource*) { // glClear rather than this method. const Properties<>::PossiblyEvaluated properties; - const BackgroundProgram::PaintPropertyBinders paintAttributeData(properties, 0); + const BackgroundProgram::Binders paintAttributeData(properties, 0); auto draw = [&](auto& program, auto&& uniformValues) { const auto allUniformValues = program.computeAllUniformValues( diff --git a/src/mbgl/renderer/layers/render_custom_layer.cpp b/src/mbgl/renderer/layers/render_custom_layer.cpp index d3ce84be2e..5ff0f1f812 100644 --- a/src/mbgl/renderer/layers/render_custom_layer.cpp +++ b/src/mbgl/renderer/layers/render_custom_layer.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include namespace mbgl { diff --git a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp index fe1641a092..482b626abf 100644 --- a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp +++ b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp @@ -13,6 +13,7 @@ #include #include #include +#include namespace mbgl { @@ -168,7 +169,7 @@ void RenderFillExtrusionLayer::render(PaintParameters& parameters, RenderSource* matrix::ortho(viewportMat, 0, size.width, size.height, 0, 0, 1); const Properties<>::PossiblyEvaluated properties; - const ExtrusionTextureProgram::PaintPropertyBinders paintAttributeData{ properties, 0 }; + const ExtrusionTextureProgram::Binders paintAttributeData{ properties, 0 }; auto& programInstance = parameters.programs.getFillExtrusionLayerPrograms().extrusionTexture; diff --git a/src/mbgl/renderer/layers/render_heatmap_layer.cpp b/src/mbgl/renderer/layers/render_heatmap_layer.cpp index 5e9283c6b3..5c615c5337 100644 --- a/src/mbgl/renderer/layers/render_heatmap_layer.cpp +++ b/src/mbgl/renderer/layers/render_heatmap_layer.cpp @@ -142,7 +142,7 @@ void RenderHeatmapLayer::render(PaintParameters& parameters, RenderSource*) { matrix::ortho(viewportMat, 0, size.width, size.height, 0, 0, 1); const Properties<>::PossiblyEvaluated properties; - const HeatmapTextureProgram::PaintPropertyBinders paintAttributeData{ properties, 0 }; + const HeatmapTextureProgram::Binders paintAttributeData{ properties, 0 }; auto& programInstance = parameters.programs.getHeatmapLayerPrograms().heatmapTexture; diff --git a/src/mbgl/renderer/layers/render_heatmap_layer.hpp b/src/mbgl/renderer/layers/render_heatmap_layer.hpp index edb36255cb..d63c30dcca 100644 --- a/src/mbgl/renderer/layers/render_heatmap_layer.hpp +++ b/src/mbgl/renderer/layers/render_heatmap_layer.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include diff --git a/src/mbgl/renderer/layers/render_hillshade_layer.cpp b/src/mbgl/renderer/layers/render_hillshade_layer.cpp index 8fd8504848..a55c18f32b 100644 --- a/src/mbgl/renderer/layers/render_hillshade_layer.cpp +++ b/src/mbgl/renderer/layers/render_hillshade_layer.cpp @@ -70,7 +70,7 @@ void RenderHillshadeLayer::render(PaintParameters& parameters, RenderSource* src const UnwrappedTileID& id) { auto& programInstance = parameters.programs.getHillshadeLayerPrograms().hillshade; - const HillshadeProgram::PaintPropertyBinders paintAttributeData{ evaluated, 0 }; + const HillshadeProgram::Binders paintAttributeData{ evaluated, 0 }; const auto allUniformValues = programInstance.computeAllUniformValues( HillshadeProgram::UniformValues { @@ -131,7 +131,7 @@ void RenderHillshadeLayer::render(PaintParameters& parameters, RenderSource* src parameters.context.bindTexture(*bucket.dem, 0, gl::TextureFilter::Nearest, gl::TextureMipMap::No, gl::TextureWrap::Clamp, gl::TextureWrap::Clamp); const Properties<>::PossiblyEvaluated properties; - const HillshadePrepareProgram::PaintPropertyBinders paintAttributeData{ properties, 0 }; + const HillshadePrepareProgram::Binders paintAttributeData{ properties, 0 }; auto& programInstance = parameters.programs.getHillshadeLayerPrograms().hillshadePrepare; diff --git a/src/mbgl/renderer/layers/render_line_layer.hpp b/src/mbgl/renderer/layers/render_line_layer.hpp index 2809c7ceb1..af2a5a26e2 100644 --- a/src/mbgl/renderer/layers/render_line_layer.hpp +++ b/src/mbgl/renderer/layers/render_line_layer.hpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace mbgl { diff --git a/src/mbgl/renderer/layers/render_raster_layer.cpp b/src/mbgl/renderer/layers/render_raster_layer.cpp index 4969b3ea52..13f62fa6ad 100644 --- a/src/mbgl/renderer/layers/render_raster_layer.cpp +++ b/src/mbgl/renderer/layers/render_raster_layer.cpp @@ -72,7 +72,7 @@ void RenderRasterLayer::render(PaintParameters& parameters, RenderSource* source if (parameters.pass != RenderPass::Translucent) return; - RasterProgram::PaintPropertyBinders paintAttributeData{ evaluated, 0 }; + RasterProgram::Binders paintAttributeData{ evaluated, 0 }; auto draw = [&] (const mat4& matrix, const auto& vertexBuffer, diff --git a/src/mbgl/renderer/layers/render_symbol_layer.cpp b/src/mbgl/renderer/layers/render_symbol_layer.cpp index 19ddd6c1cb..7239278a79 100644 --- a/src/mbgl/renderer/layers/render_symbol_layer.cpp +++ b/src/mbgl/renderer/layers/render_symbol_layer.cpp @@ -239,7 +239,7 @@ void RenderSymbolLayer::render(PaintParameters& parameters, RenderSource*) { if (bucket.hasCollisionBoxData()) { static const style::Properties<>::PossiblyEvaluated properties {}; - static const CollisionBoxProgram::PaintPropertyBinders paintAttributeData(properties, 0); + static const CollisionBoxProgram::Binders paintAttributeData(properties, 0); auto pixelRatio = tile.id.pixelsToTileUnits(1, parameters.state.getZoom()); const float scale = std::pow(2, parameters.state.getZoom() - tile.tile.id.overscaledZ); @@ -273,7 +273,7 @@ void RenderSymbolLayer::render(PaintParameters& parameters, RenderSource*) { } if (bucket.hasCollisionCircleData()) { static const style::Properties<>::PossiblyEvaluated properties {}; - static const CollisionBoxProgram::PaintPropertyBinders paintAttributeData(properties, 0); + static const CollisionBoxProgram::Binders paintAttributeData(properties, 0); auto pixelRatio = tile.id.pixelsToTileUnits(1, parameters.state.getZoom()); const float scale = std::pow(2, parameters.state.getZoom() - tile.tile.id.overscaledZ); diff --git a/src/mbgl/renderer/paint_parameters.hpp b/src/mbgl/renderer/paint_parameters.hpp index 41f46ae34e..d615c5e9b1 100644 --- a/src/mbgl/renderer/paint_parameters.hpp +++ b/src/mbgl/renderer/paint_parameters.hpp @@ -23,6 +23,10 @@ class ImageManager; class LineAtlas; class UnwrappedTileID; +namespace gl { +class Context; +} + class PaintParameters { public: PaintParameters(gl::Context&, diff --git a/src/mbgl/renderer/paint_property_binder.hpp b/src/mbgl/renderer/paint_property_binder.hpp index 09cea12030..56f187507f 100644 --- a/src/mbgl/renderer/paint_property_binder.hpp +++ b/src/mbgl/renderer/paint_property_binder.hpp @@ -24,13 +24,23 @@ namespace mbgl { between zoom levels, without the need to repopulate vertex buffers each frame as the map is being zoomed. */ -template -using ZoomInterpolatedAttributeType = gl::Attribute; +template +using ZoomInterpolatedAttributeType = gfx::AttributeType; inline std::array attributeValue(float v) { return {{ v }}; } +/* + * Pack a pair of values, interpreted as uint8's, into a single float. + * Used to conserve vertex attributes. Values are unpacked in the vertex + * shader using the `unpack_float()` function, defined in _prelude.vertex.glsl. + */ +template +inline uint16_t packUint8Pair(T a, T b) { + return static_cast(a) * 256 + static_cast(b); +} + /* Encode a four-component color value into a pair of floats. Since csscolorparser uses 8-bit precision for each color component, for each float we use the upper 8 @@ -40,8 +50,8 @@ inline std::array attributeValue(float v) { */ inline std::array attributeValue(const Color& color) { return {{ - static_cast(mbgl::attributes::packUint8Pair(255 * color.r, 255 * color.g)), - static_cast(mbgl::attributes::packUint8Pair(255 * color.b, 255 * color.a)) + static_cast(packUint8Pair(255 * color.r, 255 * color.g)), + static_cast(packUint8Pair(255 * color.b, 255 * color.a)) }}; } @@ -163,8 +173,9 @@ private: template class SourceFunctionPaintPropertyBinder : public PaintPropertyBinder, A> { public: - using BaseAttribute = A; - using BaseVertex = gl::detail::Vertex; + using BaseAttributeType = A; + using BaseAttributeValue = typename A::Value; + using BaseVertex = gfx::Vertex; using AttributeType = ZoomInterpolatedAttributeType; @@ -190,7 +201,7 @@ public: if (currentValue.isConstant()) { return {}; } else { - return std::tuple> { AttributeType::binding(*vertexBuffer, 0, BaseAttribute::Dimensions) }; + return std::tuple> { gl::attributeBinding(*vertexBuffer, 0, BaseAttributeType::Dimensions) }; } } @@ -220,7 +231,7 @@ public: using AttributeType = ZoomInterpolatedAttributeType; using AttributeValue = typename AttributeType::Value; - using Vertex = gl::detail::Vertex; + using Vertex = gfx::Vertex; CompositeFunctionPaintPropertyBinder(style::PropertyExpression expression_, float zoom, T defaultValue_) : expression(std::move(expression_)), @@ -248,7 +259,7 @@ public: if (currentValue.isConstant()) { return {}; } else { - return std::tuple> { AttributeType::binding(*vertexBuffer, 0) }; + return std::tuple> { gl::attributeBinding(*vertexBuffer, 0) }; } } @@ -283,14 +294,14 @@ public: using AttributeType = ZoomInterpolatedAttributeType; using AttributeType2 = ZoomInterpolatedAttributeType; - using BaseAttribute = A1; - using BaseAttributeValue = typename BaseAttribute::Value; + using BaseAttributeType = A1; + using BaseAttributeValue = typename BaseAttributeType::Value; - using BaseAttribute2 = A2; - using BaseAttributeValue2 = typename BaseAttribute2::Value; + using BaseAttributeType2 = A2; + using BaseAttributeValue2 = typename BaseAttributeType2::Value; - using Vertex = gl::detail::Vertex; - using Vertex2 = gl::detail::Vertex; + using Vertex = gfx::Vertex; + using Vertex2 = gfx::Vertex; CompositeCrossFadedPaintPropertyBinder(style::PropertyExpression expression_, float zoom, T defaultValue_) : expression(std::move(expression_)), @@ -344,10 +355,10 @@ public: return {}; } else { return std::tuple, optional> { - AttributeType::binding(*patternToVertexBuffer, 0, BaseAttribute::Dimensions), - AttributeType2::binding( + gl::attributeBinding(*patternToVertexBuffer, 0, BaseAttributeType::Dimensions), + gl::attributeBinding( crossfade.fromScale == 2 ? *zoomInVertexBuffer : *zoomOutVertexBuffer, - 0, BaseAttribute2::Dimensions) }; + 0, BaseAttributeType2::Dimensions) }; } } @@ -420,7 +431,7 @@ struct ZoomInterpolatedAttribute { }; template -struct InterpolationUniformType { +struct InterpolationUniform { using Value = float; static auto name() { static const std::string name = Attr::name() + std::string("_t"); @@ -441,11 +452,11 @@ private: struct Detail> { using Binder = PaintPropertyBinder; using ZoomInterpolatedAttributeList = TypeList...>; - using InterpolationUniformTypeList = TypeList...>; + using InterpolationUniformList = TypeList...>; }; template - using Property = Detail; + using Property = Detail; public: template @@ -485,9 +496,10 @@ public: template using ZoomInterpolatedAttributeList = typename Property

::ZoomInterpolatedAttributeList; template - using InterpolationUniformTypeList = typename Property

::InterpolationUniformTypeList; + using InterpolationUniformList = typename Property

::InterpolationUniformList; - using Attributes = typename TypeListConcat...>::template ExpandInto; + using AttributeList = TypeListConcat...>; + using Attributes = gl::Attributes; using AttributeBindings = typename Attributes::Bindings; template @@ -497,9 +509,9 @@ public: ) }; } - using UniformTypeList = TypeListConcat..., typename Ps::Uniforms...>; - using UniformValues = gfx::UniformValues; - using Uniforms = typename UniformTypeList::template ExpandInto; + using UniformList = TypeListConcat..., typename Ps::UniformList...>; + using UniformValues = gfx::UniformValues; + using Uniforms = gl::Uniforms; template UniformValues uniformValues(float currentZoom, EvaluatedProperties& currentProperties) const { @@ -547,7 +559,7 @@ public: std::vector result; util::ignore({ (currentProperties.template get().isConstant() - ? UniformDefines::appendDefines(result) + ? UniformDefines::appendDefines(result) : (void) 0, 0)... }); return result; diff --git a/src/mbgl/renderer/render_layer.cpp b/src/mbgl/renderer/render_layer.cpp index 8892991ac6..32236d0f24 100644 --- a/src/mbgl/renderer/render_layer.cpp +++ b/src/mbgl/renderer/render_layer.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include namespace mbgl { diff --git a/src/mbgl/renderer/render_static_data.cpp b/src/mbgl/renderer/render_static_data.cpp index 0b3937ded0..292a0298b0 100644 --- a/src/mbgl/renderer/render_static_data.cpp +++ b/src/mbgl/renderer/render_static_data.cpp @@ -3,12 +3,12 @@ namespace mbgl { -static gl::VertexVector tileVertices() { - gl::VertexVector result; - result.emplace_back(PositionOnlyLayoutAttributes::Vertex({{{ 0, 0 }}})); - result.emplace_back(PositionOnlyLayoutAttributes::Vertex({{{ util::EXTENT, 0 }}})); - result.emplace_back(PositionOnlyLayoutAttributes::Vertex({{{ 0, util::EXTENT }}})); - result.emplace_back(PositionOnlyLayoutAttributes::Vertex({{{ util::EXTENT, util::EXTENT }}})); +static gl::VertexVector> tileVertices() { + gl::VertexVector> result; + result.emplace_back(gfx::Vertex({{{ 0, 0 }}})); + result.emplace_back(gfx::Vertex({{{ util::EXTENT, 0 }}})); + result.emplace_back(gfx::Vertex({{{ 0, util::EXTENT }}})); + result.emplace_back(gfx::Vertex({{{ util::EXTENT, util::EXTENT }}})); return result; } diff --git a/src/mbgl/renderer/render_static_data.hpp b/src/mbgl/renderer/render_static_data.hpp index 57dd7ab812..2e53067af6 100644 --- a/src/mbgl/renderer/render_static_data.hpp +++ b/src/mbgl/renderer/render_static_data.hpp @@ -16,7 +16,7 @@ class RenderStaticData { public: RenderStaticData(gl::Context&, float pixelRatio, const optional& programCacheDir); - gl::VertexBuffer tileVertexBuffer; + gl::VertexBuffer> tileVertexBuffer; gl::VertexBuffer rasterVertexBuffer; gl::VertexBuffer extrusionTextureVertexBuffer; diff --git a/src/mbgl/renderer/render_tile.cpp b/src/mbgl/renderer/render_tile.cpp index 61b92fb6d4..a3f95ad869 100644 --- a/src/mbgl/renderer/render_tile.cpp +++ b/src/mbgl/renderer/render_tile.cpp @@ -72,7 +72,7 @@ void RenderTile::finishRender(PaintParameters& parameters) { return; static const style::Properties<>::PossiblyEvaluated properties {}; - static const DebugProgram::PaintPropertyBinders paintAttributeData(properties, 0); + static const DebugProgram::Binders paintAttributeData(properties, 0); auto& program = parameters.programs.debug; diff --git a/src/mbgl/renderer/renderer_impl.cpp b/src/mbgl/renderer/renderer_impl.cpp index 9058b0d62b..44ea982986 100644 --- a/src/mbgl/renderer/renderer_impl.cpp +++ b/src/mbgl/renderer/renderer_impl.cpp @@ -435,7 +435,7 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) { MBGL_DEBUG_GROUP(parameters.context, "clipping masks"); static const Properties<>::PossiblyEvaluated properties {}; - static const ClippingMaskProgram::PaintPropertyBinders paintAttributeData(properties, 0); + static const ClippingMaskProgram::Binders paintAttributeData(properties, 0); for (const auto& clipID : parameters.clipIDGenerator.getClipIDs()) { auto& program = parameters.staticData.programs.clippingMask; diff --git a/src/mbgl/renderer/sources/render_image_source.cpp b/src/mbgl/renderer/sources/render_image_source.cpp index 957403fc2f..69a5f2cc83 100644 --- a/src/mbgl/renderer/sources/render_image_source.cpp +++ b/src/mbgl/renderer/sources/render_image_source.cpp @@ -56,7 +56,7 @@ void RenderImageSource::finishRender(PaintParameters& parameters) { } static const style::Properties<>::PossiblyEvaluated properties {}; - static const DebugProgram::PaintPropertyBinders paintAttributeData(properties, 0); + static const DebugProgram::Binders paintAttributeData(properties, 0); auto& programInstance = parameters.programs.debug; diff --git a/src/mbgl/style/layers/line_layer_properties.hpp b/src/mbgl/style/layers/line_layer_properties.hpp index f6eeaa154f..bab6e77ce5 100644 --- a/src/mbgl/style/layers/line_layer_properties.hpp +++ b/src/mbgl/style/layers/line_layer_properties.hpp @@ -56,7 +56,7 @@ struct LineGapWidth : DataDrivenPaintProperty, uniforms::u_offset> { +struct LineOffset : DataDrivenPaintProperty { static float defaultValue() { return 0; } }; diff --git a/src/mbgl/style/paint_property.hpp b/src/mbgl/style/paint_property.hpp index 58de3354fb..343e689a32 100644 --- a/src/mbgl/style/paint_property.hpp +++ b/src/mbgl/style/paint_property.hpp @@ -34,9 +34,9 @@ public: static constexpr bool IsDataDriven = true; using Attribute = A; - using Attributes = TypeList; + using AttributeList = TypeList; using Uniform = U; - using Uniforms = TypeList; + using UniformList = TypeList; }; template @@ -50,9 +50,9 @@ public: static constexpr bool IsDataDriven = true; using Attribute = A1; - using Attributes = TypeList; - using Uniforms = TypeList; + using AttributeList = TypeList; using Uniform = U1; + using UniformList = TypeList; }; template diff --git a/src/mbgl/style/properties.hpp b/src/mbgl/style/properties.hpp index e7f05db959..d836735c65 100644 --- a/src/mbgl/style/properties.hpp +++ b/src/mbgl/style/properties.hpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include @@ -122,7 +122,6 @@ public: using EvaluatedTypes = TypeList; using DataDrivenProperties = FilteredTypeList; - using Binders = PaintPropertyBinders; template using Tuple = IndexedTuple; diff --git a/src/mbgl/util/offscreen_texture.hpp b/src/mbgl/util/offscreen_texture.hpp index 36f24f16d3..c2aca9bacd 100644 --- a/src/mbgl/util/offscreen_texture.hpp +++ b/src/mbgl/util/offscreen_texture.hpp @@ -1,5 +1,7 @@ #pragma once +#include +#include #include namespace mbgl { diff --git a/test/gl/bucket.test.cpp b/test/gl/bucket.test.cpp index 56d8ef372d..7e8740d8f9 100644 --- a/test/gl/bucket.test.cpp +++ b/test/gl/bucket.test.cpp @@ -22,7 +22,7 @@ bool operator==(const Segment& lhs, const Segment& rhs) std::tie(rhs.vertexOffset, rhs.indexOffset, rhs.vertexLength, rhs.indexLength); } -namespace gl { +namespace gfx { namespace detail { template @@ -31,7 +31,7 @@ bool operator==(const Vertex& lhs, const Vertex& rhs) { } } // namespace detail -} // namespace gl +} // namespace gfx } // namespace mbgl using namespace mbgl; -- cgit v1.2.1