From cca3adb375444bdc1bd3d19399b37942715f7c31 Mon Sep 17 00:00:00 2001 From: Alex Cristici Date: Thu, 18 Apr 2024 14:22:11 +0300 Subject: [PATCH] Layer group uniforms (#2247) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- CMakeLists.txt | 2 - bazel/core.bzl | 2 - include/mbgl/gl/layer_group_gl.hpp | 17 + include/mbgl/mtl/layer_group.hpp | 11 + include/mbgl/mtl/tile_layer_group.hpp | 11 + include/mbgl/renderer/layer_group.hpp | 6 + include/mbgl/shaders/background_layer_ubo.hpp | 34 +- .../mbgl/shaders/fill_extrusion_layer_ubo.hpp | 12 +- include/mbgl/shaders/fill_layer_ubo.hpp | 77 +--- .../mbgl/shaders/gl/drawable_background.hpp | 5 +- .../gl/drawable_background_pattern.hpp | 20 +- include/mbgl/shaders/gl/drawable_circle.hpp | 12 +- .../gl/drawable_custom_symbol_icon.hpp | 2 +- include/mbgl/shaders/gl/drawable_fill.hpp | 36 +- .../shaders/gl/drawable_fill_extrusion.hpp | 49 ++- .../gl/drawable_fill_extrusion_pattern.hpp | 96 ++--- .../mbgl/shaders/gl/drawable_fill_outline.hpp | 42 +-- .../gl/drawable_fill_outline_pattern.hpp | 40 ++- .../gl/drawable_fill_outline_triangulated.hpp | 25 +- .../mbgl/shaders/gl/drawable_fill_pattern.hpp | 48 +-- include/mbgl/shaders/gl/drawable_heatmap.hpp | 10 +- .../shaders/gl/drawable_heatmap_texture.hpp | 8 +- include/mbgl/shaders/gl/drawable_line.hpp | 60 ++-- .../shaders/gl/drawable_line_gradient.hpp | 62 ++-- .../mbgl/shaders/gl/drawable_line_pattern.hpp | 74 ++-- include/mbgl/shaders/gl/drawable_line_sdf.hpp | 61 ++-- include/mbgl/shaders/gl/drawable_raster.hpp | 13 +- .../mbgl/shaders/gl/drawable_symbol_icon.hpp | 91 +++-- .../mbgl/shaders/gl/drawable_symbol_sdf.hpp | 108 +++--- .../gl/drawable_symbol_text_and_icon.hpp | 108 +++--- include/mbgl/shaders/gl/shader_info.hpp | 12 +- .../shaders/heatmap_texture_layer_ubo.hpp | 6 +- include/mbgl/shaders/line_layer_ubo.hpp | 108 ++---- include/mbgl/shaders/mtl/background.hpp | 12 +- .../mbgl/shaders/mtl/background_pattern.hpp | 36 +- include/mbgl/shaders/mtl/circle.hpp | 30 +- include/mbgl/shaders/mtl/clipping_mask.hpp | 6 +- include/mbgl/shaders/mtl/collision_box.hpp | 16 +- include/mbgl/shaders/mtl/collision_circle.hpp | 14 +- include/mbgl/shaders/mtl/common.hpp | 172 +++++---- .../mbgl/shaders/mtl/custom_symbol_icon.hpp | 10 +- include/mbgl/shaders/mtl/debug.hpp | 8 +- include/mbgl/shaders/mtl/fill.hpp | 121 +++---- include/mbgl/shaders/mtl/fill_extrusion.hpp | 55 +-- .../shaders/mtl/fill_extrusion_pattern.hpp | 71 +--- include/mbgl/shaders/mtl/heatmap.hpp | 16 +- include/mbgl/shaders/mtl/heatmap_texture.hpp | 14 +- include/mbgl/shaders/mtl/hillshade.hpp | 12 +- .../mbgl/shaders/mtl/hillshade_prepare.hpp | 10 +- include/mbgl/shaders/mtl/line.hpp | 340 +++++++++++++----- include/mbgl/shaders/mtl/line_gradient.hpp | 167 --------- include/mbgl/shaders/mtl/raster.hpp | 36 +- include/mbgl/shaders/mtl/shader_program.hpp | 22 +- include/mbgl/shaders/mtl/symbol_icon.hpp | 44 +-- include/mbgl/shaders/mtl/symbol_sdf.hpp | 68 ++-- .../mbgl/shaders/mtl/symbol_text_and_icon.hpp | 64 ++-- include/mbgl/shaders/mtl/widevector.hpp | 24 +- include/mbgl/shaders/raster_layer_ubo.hpp | 8 +- include/mbgl/shaders/shader_defines.hpp | 7 - include/mbgl/shaders/symbol_layer_ubo.hpp | 96 ++--- shaders/drawable.background.fragment.glsl | 5 +- .../drawable.background_pattern.fragment.glsl | 7 +- .../drawable.background_pattern.vertex.glsl | 13 +- shaders/drawable.circle.fragment.glsl | 2 +- shaders/drawable.circle.vertex.glsl | 10 +- .../drawable.custom.symbol_icon.vertex.glsl | 2 +- shaders/drawable.fill.fragment.glsl | 17 +- shaders/drawable.fill.vertex.glsl | 17 +- shaders/drawable.fill_extrusion.vertex.glsl | 49 ++- ...wable.fill_extrusion_pattern.fragment.glsl | 48 +-- ...rawable.fill_extrusion_pattern.vertex.glsl | 48 +-- shaders/drawable.fill_outline.fragment.glsl | 19 +- shaders/drawable.fill_outline.vertex.glsl | 21 +- ...rawable.fill_outline_pattern.fragment.glsl | 20 +- .../drawable.fill_outline_pattern.vertex.glsl | 20 +- ...le.fill_outline_triangulated.fragment.glsl | 12 +- ...able.fill_outline_triangulated.vertex.glsl | 13 +- shaders/drawable.fill_pattern.fragment.glsl | 24 +- shaders/drawable.fill_pattern.vertex.glsl | 24 +- shaders/drawable.heatmap.fragment.glsl | 2 +- shaders/drawable.heatmap.vertex.glsl | 8 +- .../drawable.heatmap_texture.fragment.glsl | 4 +- shaders/drawable.heatmap_texture.vertex.glsl | 4 +- shaders/drawable.line.fragment.glsl | 29 +- shaders/drawable.line.vertex.glsl | 31 +- shaders/drawable.line_gradient.fragment.glsl | 30 +- shaders/drawable.line_gradient.vertex.glsl | 32 +- shaders/drawable.line_pattern.fragment.glsl | 36 +- shaders/drawable.line_pattern.vertex.glsl | 38 +- shaders/drawable.line_sdf.fragment.glsl | 30 +- shaders/drawable.line_sdf.vertex.glsl | 31 +- shaders/drawable.raster.fragment.glsl | 7 +- shaders/drawable.raster.vertex.glsl | 6 +- shaders/drawable.symbol_icon.fragment.glsl | 41 ++- shaders/drawable.symbol_icon.vertex.glsl | 50 +-- shaders/drawable.symbol_sdf.fragment.glsl | 54 +-- shaders/drawable.symbol_sdf.vertex.glsl | 54 +-- ...rawable.symbol_text_and_icon.fragment.glsl | 54 +-- .../drawable.symbol_text_and_icon.vertex.glsl | 54 +-- src/mbgl/gl/drawable_gl.cpp | 16 +- src/mbgl/gl/layer_group_gl.cpp | 57 +++ src/mbgl/mtl/context.cpp | 4 +- src/mbgl/mtl/drawable.cpp | 1 - src/mbgl/mtl/layer_group.cpp | 22 +- src/mbgl/mtl/renderer_backend.cpp | 1 - src/mbgl/mtl/tile_layer_group.cpp | 18 +- .../layers/background_layer_tweaker.cpp | 69 ++-- .../layers/background_layer_tweaker.hpp | 3 - .../renderer/layers/circle_layer_tweaker.cpp | 14 +- .../renderer/layers/circle_layer_tweaker.hpp | 1 - .../layers/collision_layer_tweaker.cpp | 6 +- .../layers/fill_extrusion_layer_tweaker.cpp | 13 +- .../layers/fill_extrusion_layer_tweaker.hpp | 7 +- .../renderer/layers/fill_layer_tweaker.cpp | 125 ++----- .../renderer/layers/fill_layer_tweaker.hpp | 13 +- .../renderer/layers/heatmap_layer_tweaker.cpp | 29 +- .../renderer/layers/heatmap_layer_tweaker.hpp | 5 - .../layers/heatmap_texture_layer_tweaker.cpp | 33 +- .../layers/heatmap_texture_layer_tweaker.hpp | 3 - .../layers/hillshade_layer_tweaker.cpp | 27 +- .../hillshade_prepare_layer_tweaker.cpp | 2 + .../renderer/layers/line_layer_tweaker.cpp | 147 ++------ .../renderer/layers/line_layer_tweaker.hpp | 18 +- .../renderer/layers/raster_layer_tweaker.cpp | 85 ++--- .../renderer/layers/render_circle_layer.cpp | 8 +- .../layers/render_fill_extrusion_layer.cpp | 14 +- .../renderer/layers/render_fill_layer.cpp | 46 ++- .../renderer/layers/render_heatmap_layer.cpp | 8 +- .../renderer/layers/render_line_layer.cpp | 17 +- .../renderer/layers/render_symbol_layer.cpp | 24 +- .../renderer/layers/symbol_layer_tweaker.cpp | 55 +-- .../renderer/layers/symbol_layer_tweaker.hpp | 12 +- .../renderer/sources/render_tile_source.cpp | 67 ++-- src/mbgl/shaders/gl/shader_info.cpp | 295 +++++++-------- src/mbgl/shaders/mtl/background.cpp | 10 +- src/mbgl/shaders/mtl/background_pattern.cpp | 12 +- src/mbgl/shaders/mtl/circle.cpp | 28 +- src/mbgl/shaders/mtl/clipping_mask.cpp | 8 +- src/mbgl/shaders/mtl/collision_box.cpp | 16 +- src/mbgl/shaders/mtl/collision_circle.cpp | 16 +- src/mbgl/shaders/mtl/custom_symbol_icon.cpp | 14 +- src/mbgl/shaders/mtl/debug.cpp | 8 +- src/mbgl/shaders/mtl/fill.cpp | 89 +++-- src/mbgl/shaders/mtl/fill_extrusion.cpp | 20 +- .../shaders/mtl/fill_extrusion_pattern.cpp | 27 +- src/mbgl/shaders/mtl/heatmap.cpp | 16 +- src/mbgl/shaders/mtl/heatmap_texture.cpp | 10 +- src/mbgl/shaders/mtl/hillshade.cpp | 12 +- src/mbgl/shaders/mtl/hillshade_prepare.cpp | 12 +- src/mbgl/shaders/mtl/line.cpp | 107 +++--- src/mbgl/shaders/mtl/line_gradient.cpp | 26 -- src/mbgl/shaders/mtl/raster.cpp | 11 +- src/mbgl/shaders/mtl/symbol_icon.cpp | 26 +- src/mbgl/shaders/mtl/symbol_sdf.cpp | 36 +- src/mbgl/shaders/mtl/symbol_text_and_icon.cpp | 34 +- .../style/layers/custom_drawable_layer.cpp | 81 +++-- test/util/hash.test.cpp | 1 - 157 files changed, 2734 insertions(+), 2864 deletions(-) delete mode 100644 include/mbgl/shaders/mtl/line_gradient.hpp delete mode 100644 src/mbgl/shaders/mtl/line_gradient.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b288860c..db3a22bfa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1228,7 +1228,6 @@ if(MBGL_WITH_METAL) ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/hillshade.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/hillshade_prepare.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/line.hpp - ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/line_gradient.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/raster.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/shader_group.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/shader_program.hpp @@ -1274,7 +1273,6 @@ if(MBGL_WITH_METAL) ${PROJECT_SOURCE_DIR}src/mbgl/shaders/mtl/hillshade.cpp ${PROJECT_SOURCE_DIR}src/mbgl/shaders/mtl/hillshade_prepare.cpp ${PROJECT_SOURCE_DIR}src/mbgl/shaders/mtl/line.cpp - ${PROJECT_SOURCE_DIR}src/mbgl/shaders/mtl/line_gradient.cpp ${PROJECT_SOURCE_DIR}src/mbgl/shaders/mtl/raster.cpp ${PROJECT_SOURCE_DIR}src/mbgl/shaders/mtl/symbol_icon.cpp ${PROJECT_SOURCE_DIR}src/mbgl/shaders/mtl/symbol_sdf.cpp diff --git a/bazel/core.bzl b/bazel/core.bzl index b9c36f306..5da7139b2 100644 --- a/bazel/core.bzl +++ b/bazel/core.bzl @@ -1072,7 +1072,6 @@ MLN_DRAWABLES_MTL_SOURCE = [ "src/mbgl/shaders/mtl/hillshade.cpp", "src/mbgl/shaders/mtl/hillshade_prepare.cpp", "src/mbgl/shaders/mtl/line.cpp", - "src/mbgl/shaders/mtl/line_gradient.cpp", "src/mbgl/shaders/mtl/raster.cpp", "src/mbgl/shaders/mtl/symbol_icon.cpp", "src/mbgl/shaders/mtl/symbol_sdf.cpp", @@ -1117,7 +1116,6 @@ MLN_DRAWABLES_MTL_HEADERS = [ "include/mbgl/shaders/mtl/hillshade.hpp", "include/mbgl/shaders/mtl/hillshade_prepare.hpp", "include/mbgl/shaders/mtl/line.hpp", - "include/mbgl/shaders/mtl/line_gradient.hpp", "include/mbgl/shaders/mtl/raster.hpp", "include/mbgl/shaders/mtl/shader_group.hpp", "include/mbgl/shaders/mtl/shader_program.hpp", diff --git a/include/mbgl/gl/layer_group_gl.hpp b/include/mbgl/gl/layer_group_gl.hpp index dc8173f19..0250a8545 100644 --- a/include/mbgl/gl/layer_group_gl.hpp +++ b/include/mbgl/gl/layer_group_gl.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include namespace mbgl { @@ -19,7 +20,15 @@ public: void upload(gfx::UploadPass&) override; void render(RenderOrchestrator&, PaintParameters&) override; + const gfx::UniformBufferArray& getUniformBuffers() const override { return uniformBuffers; }; + + gfx::UniformBufferArray& mutableUniformBuffers() override { return uniformBuffers; }; + + void bindUniformBuffers() const; + void unbindUniformBuffers() const; + protected: + UniformBufferArrayGL uniformBuffers; }; /** @@ -33,7 +42,15 @@ public: void upload(gfx::UploadPass&) override; void render(RenderOrchestrator&, PaintParameters&) override; + const gfx::UniformBufferArray& getUniformBuffers() const override { return uniformBuffers; }; + + gfx::UniformBufferArray& mutableUniformBuffers() override { return uniformBuffers; }; + + void bindUniformBuffers() const; + void unbindUniformBuffers() const; + protected: + UniformBufferArrayGL uniformBuffers; }; } // namespace gl diff --git a/include/mbgl/mtl/layer_group.hpp b/include/mbgl/mtl/layer_group.hpp index aba0a0d42..90f742942 100644 --- a/include/mbgl/mtl/layer_group.hpp +++ b/include/mbgl/mtl/layer_group.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include namespace mbgl { @@ -8,6 +9,8 @@ class PaintParameters; namespace mtl { +class RenderPass; + /** A layer group for non-tile-based drawables */ @@ -19,7 +22,15 @@ public: void upload(gfx::UploadPass&) override; void render(RenderOrchestrator&, PaintParameters&) override; + const gfx::UniformBufferArray& getUniformBuffers() const override { return uniformBuffers; }; + + gfx::UniformBufferArray& mutableUniformBuffers() override { return uniformBuffers; }; + + void bindUniformBuffers(RenderPass&) const noexcept; + void unbindUniformBuffers(RenderPass&) const noexcept {} + protected: + UniformBufferArray uniformBuffers; }; } // namespace mtl diff --git a/include/mbgl/mtl/tile_layer_group.hpp b/include/mbgl/mtl/tile_layer_group.hpp index 069906168..89b51e804 100644 --- a/include/mbgl/mtl/tile_layer_group.hpp +++ b/include/mbgl/mtl/tile_layer_group.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -13,6 +14,8 @@ class PaintParameters; namespace mtl { +class RenderPass; + /** A layer group for tile-based drawables */ @@ -24,9 +27,17 @@ public: void upload(gfx::UploadPass&) override; void render(RenderOrchestrator&, PaintParameters&) override; + const gfx::UniformBufferArray& getUniformBuffers() const override { return uniformBuffers; }; + + gfx::UniformBufferArray& mutableUniformBuffers() override { return uniformBuffers; }; + + void bindUniformBuffers(RenderPass&) const noexcept; + void unbindUniformBuffers(RenderPass&) const noexcept {} + protected: std::optional stateNone; std::optional stateDepth; + UniformBufferArray uniformBuffers; }; } // namespace mtl diff --git a/include/mbgl/renderer/layer_group.hpp b/include/mbgl/renderer/layer_group.hpp index dd9c0b00b..27b6cdcde 100644 --- a/include/mbgl/renderer/layer_group.hpp +++ b/include/mbgl/renderer/layer_group.hpp @@ -101,6 +101,12 @@ public: void runTweakers(const RenderTree&, PaintParameters&); + /// Get the uniform buffers attached to this layer group + virtual const gfx::UniformBufferArray& getUniformBuffers() const = 0; + + /// Get the mutable uniform buffer array attached to this layer group + virtual gfx::UniformBufferArray& mutableUniformBuffers() = 0; + protected: const Type type; bool enabled = true; diff --git a/include/mbgl/shaders/background_layer_ubo.hpp b/include/mbgl/shaders/background_layer_ubo.hpp index 167d6eee4..903a47487 100644 --- a/include/mbgl/shaders/background_layer_ubo.hpp +++ b/include/mbgl/shaders/background_layer_ubo.hpp @@ -7,10 +7,13 @@ namespace mbgl { namespace shaders { +// +// Background + struct alignas(16) BackgroundDrawableUBO { std::array matrix; }; -static_assert(sizeof(BackgroundDrawableUBO) % 16 == 0); +static_assert(sizeof(BackgroundDrawableUBO) == 64); struct alignas(16) BackgroundLayerUBO { /* 0 */ Color color; @@ -20,6 +23,18 @@ struct alignas(16) BackgroundLayerUBO { }; static_assert(sizeof(BackgroundLayerUBO) == 32); +// +// Background pattern + +struct alignas(16) BackgroundPatternDrawableUBO { + std::array matrix; + std::array pixel_coord_upper; + std::array pixel_coord_lower; + float tile_units_to_pixels; + float pad1, pad2, pad3; +}; +static_assert(sizeof(BackgroundPatternDrawableUBO) == 96); + struct alignas(16) BackgroundPatternLayerUBO { /* 0 */ std::array pattern_tl_a; /* 8 */ std::array pattern_br_a; @@ -28,17 +43,14 @@ struct alignas(16) BackgroundPatternLayerUBO { /* 32 */ std::array texsize; /* 40 */ std::array pattern_size_a; /* 48 */ std::array pattern_size_b; - /* 56 */ std::array pixel_coord_upper; - /* 64 */ std::array pixel_coord_lower; - /* 72 */ float tile_units_to_pixels; - /* 76 */ float scale_a; - /* 80 */ float scale_b; - /* 84 */ float mix; - /* 88 */ float opacity; - /* 92 */ float pad1; - /* 96 */ + /* 56 */ float scale_a; + /* 60 */ float scale_b; + /* 64 */ float mix; + /* 68 */ float opacity; + /* 72 */ float pad1, pad2; + /* 80 */ }; -static_assert(sizeof(BackgroundPatternLayerUBO) == 96); +static_assert(sizeof(BackgroundPatternLayerUBO) == 80); enum { idBackgroundDrawableUBO, diff --git a/include/mbgl/shaders/fill_extrusion_layer_ubo.hpp b/include/mbgl/shaders/fill_extrusion_layer_ubo.hpp index 10dcb6543..81772721e 100644 --- a/include/mbgl/shaders/fill_extrusion_layer_ubo.hpp +++ b/include/mbgl/shaders/fill_extrusion_layer_ubo.hpp @@ -20,7 +20,7 @@ struct alignas(16) FillExtrusionDrawableUBO { static_assert(sizeof(FillExtrusionDrawableUBO) == 7 * 16); /// Evaluated properties that do not depend on the tile -struct alignas(16) FillExtrusionDrawablePropsUBO { +struct alignas(16) FillExtrusionPropsUBO { /* 0 */ Color color; /* 16 */ std::array light_color; /* 28 */ float pad1; @@ -34,15 +34,15 @@ struct alignas(16) FillExtrusionDrawablePropsUBO { /* 68 */ float pad2, pad3, pad4; /* 80 */ }; -static_assert(sizeof(FillExtrusionDrawablePropsUBO) == 5 * 16); +static_assert(sizeof(FillExtrusionPropsUBO) == 5 * 16); /// Evaluated properties that depend on the tile -struct alignas(16) FillExtrusionDrawableTilePropsUBO { +struct alignas(16) FillExtrusionTilePropsUBO { /* 0 */ std::array pattern_from; /* 16 */ std::array pattern_to; /* 32 */ }; -static_assert(sizeof(FillExtrusionDrawableTilePropsUBO) == 2 * 16); +static_assert(sizeof(FillExtrusionTilePropsUBO) == 2 * 16); /// Attribute interpolations struct alignas(16) FillExtrusionInterpolateUBO { @@ -58,8 +58,8 @@ static_assert(sizeof(FillExtrusionInterpolateUBO) == 2 * 16); enum { idFillExtrusionDrawableUBO, - idFillExtrusionDrawablePropsUBO, - idFillExtrusionDrawableTilePropsUBO, + idFillExtrusionPropsUBO, + idFillExtrusionTilePropsUBO, idFillExtrusionInterpolateUBO, fillExtrusionUBOCount }; diff --git a/include/mbgl/shaders/fill_layer_ubo.hpp b/include/mbgl/shaders/fill_layer_ubo.hpp index fd24f726d..c88013c08 100644 --- a/include/mbgl/shaders/fill_layer_ubo.hpp +++ b/include/mbgl/shaders/fill_layer_ubo.hpp @@ -13,13 +13,6 @@ struct alignas(16) FillDrawableUBO { }; static_assert(sizeof(FillDrawableUBO) == 4 * 16); -struct alignas(16) FillEvaluatedPropsUBO { - Color color; - float opacity; - float pad1, pad2, pad3; -}; -static_assert(sizeof(FillEvaluatedPropsUBO) == 2 * 16); - struct alignas(16) FillInterpolateUBO { float color_t; float opacity_t; @@ -27,13 +20,6 @@ struct alignas(16) FillInterpolateUBO { }; static_assert(sizeof(FillInterpolateUBO) % 16 == 0); -enum { - idFillDrawableUBO, - idFillEvaluatedPropsUBO, - idFillInterpolateUBO, - fillUBOCount -}; - // // Fill outline @@ -45,13 +31,6 @@ struct alignas(16) FillOutlineDrawableUBO { }; static_assert(sizeof(FillOutlineDrawableUBO) == 5 * 16); -struct alignas(16) FillOutlineEvaluatedPropsUBO { - Color outline_color; - float opacity; - float pad1, pad2, pad3; -}; -static_assert(sizeof(FillOutlineEvaluatedPropsUBO) == 2 * 16); - struct alignas(16) FillOutlineInterpolateUBO { float outline_color_t; float opacity_t; @@ -59,13 +38,6 @@ struct alignas(16) FillOutlineInterpolateUBO { }; static_assert(sizeof(FillOutlineInterpolateUBO) == 1 * 16); -enum { - idFillOutlineDrawableUBO, - idFillOutlineEvaluatedPropsUBO, - idFillOutlineInterpolateUBO, - fillOutlineUBOCount -}; - // // Fill Pattern @@ -80,13 +52,6 @@ struct alignas(16) FillPatternDrawableUBO { }; static_assert(sizeof(FillPatternDrawableUBO) == 7 * 16); -struct alignas(16) FillPatternEvaluatedPropsUBO { - float opacity; - float fade; - float pad1, pad2; -}; -static_assert(sizeof(FillPatternEvaluatedPropsUBO) == 1 * 16); - struct alignas(16) FillPatternTilePropsUBO { std::array pattern_from; std::array pattern_to; @@ -101,14 +66,6 @@ struct alignas(16) FillPatternInterpolateUBO { }; static_assert(sizeof(FillPatternInterpolateUBO) == 1 * 16); -enum { - idFillPatternDrawableUBO, - idFillPatternTilePropsUBO, - idFillPatternEvaluatedPropsUBO, - idFillPatternInterpolateUBO, - fillPatternUBOCount -}; - // // Fill pattern outline @@ -122,13 +79,6 @@ struct alignas(16) FillOutlinePatternDrawableUBO { }; static_assert(sizeof(FillOutlinePatternDrawableUBO) == 7 * 16); -struct alignas(16) FillOutlinePatternEvaluatedPropsUBO { - float opacity; - float fade; - float pad1, pad2; -}; -static_assert(sizeof(FillOutlinePatternEvaluatedPropsUBO) == 16); - struct alignas(16) FillOutlinePatternTilePropsUBO { std::array pattern_from; std::array pattern_to; @@ -143,14 +93,6 @@ struct alignas(16) FillOutlinePatternInterpolateUBO { }; static_assert(sizeof(FillOutlinePatternInterpolateUBO) == 1 * 16); -enum { - idFillOutlinePatternDrawableUBO, - idFillOutlinePatternTilePropsUBO, - idFillOutlinePatternEvaluatedPropsUBO, - idFillOutlinePatternInterpolateUBO, - fillOutlinePatternUBOCount -}; - // // Fill outline triangulated @@ -162,18 +104,25 @@ struct alignas(16) FillOutlineTriangulatedDrawableUBO { }; static_assert(sizeof(FillOutlineTriangulatedDrawableUBO) % 16 == 0); -struct alignas(16) FillOutlineTriangulatedPropertiesUBO { +// +// Fill evaluated properties + +struct alignas(16) FillEvaluatedPropsUBO { Color color; + Color outline_color; float opacity; + float fade; float width; - float pad1, pad2; + float pad1; }; -static_assert(sizeof(FillOutlineTriangulatedPropertiesUBO) % 16 == 0); +static_assert(sizeof(FillEvaluatedPropsUBO) == 3 * 16); enum { - idFillOutlineTriangulatedDrawableUBO, - idFillOutlineTriangulatedPropertiesUBO, - fillOutlineTriangulatedUBOCount + idFillDrawableUBO, + idFillTilePropsUBO, + idFillInterpolateUBO, + idFillEvaluatedPropsUBO, + fillUBOCount }; } // namespace shaders diff --git a/include/mbgl/shaders/gl/drawable_background.hpp b/include/mbgl/shaders/gl/drawable_background.hpp index bb7271459..e7abe2b93 100644 --- a/include/mbgl/shaders/gl/drawable_background.hpp +++ b/include/mbgl/shaders/gl/drawable_background.hpp @@ -19,11 +19,12 @@ void main() { )"; static constexpr const char* fragment = R"(layout (std140) uniform BackgroundLayerUBO { highp vec4 u_color; - highp vec4 u_opacity_pad3; + highp float u_opacity; + highp float layer_pad1, layer_pad2, layer_pad3; }; void main() { - fragColor = u_color * u_opacity_pad3.x; + fragColor = u_color * u_opacity; #ifdef OVERDRAW_INSPECTOR fragColor = vec4(1.0); #endif diff --git a/include/mbgl/shaders/gl/drawable_background_pattern.hpp b/include/mbgl/shaders/gl/drawable_background_pattern.hpp index 52183580b..424e011e3 100644 --- a/include/mbgl/shaders/gl/drawable_background_pattern.hpp +++ b/include/mbgl/shaders/gl/drawable_background_pattern.hpp @@ -8,10 +8,14 @@ namespace shaders { template <> struct ShaderSource { static constexpr const char* name = "BackgroundPatternShader"; - static constexpr const char* vertex = R"(layout (std140) uniform BackgroundDrawableUBO { + static constexpr const char* vertex = R"(layout (std140) uniform BackgroundPatternDrawableUBO { highp mat4 u_matrix; + highp vec2 u_pixel_coord_upper; + highp vec2 u_pixel_coord_lower; + highp float u_tile_units_to_pixels; + highp float drawable_pad1, drawable_pad2, drawable_pad3; }; -layout (std140) uniform BackgroundLayerUBO { +layout (std140) uniform BackgroundPatternLayerUBO { highp vec2 u_pattern_tl_a; highp vec2 u_pattern_br_a; highp vec2 u_pattern_tl_b; @@ -19,14 +23,11 @@ layout (std140) uniform BackgroundLayerUBO { highp vec2 u_texsize; highp vec2 u_pattern_size_a; highp vec2 u_pattern_size_b; - highp vec2 u_pixel_coord_upper; - highp vec2 u_pixel_coord_lower; - highp float u_tile_units_to_pixels; highp float u_scale_a; highp float u_scale_b; highp float u_mix; highp float u_opacity; - highp float pad; + highp float layer_pad1, layer_pad2; }; layout (location = 0) in vec2 a_pos; @@ -40,7 +41,7 @@ void main() { v_pos_b = get_pattern_pos(u_pixel_coord_upper, u_pixel_coord_lower, u_scale_b * u_pattern_size_b, u_tile_units_to_pixels, a_pos); } )"; - static constexpr const char* fragment = R"(layout (std140) uniform BackgroundLayerUBO { + static constexpr const char* fragment = R"(layout (std140) uniform BackgroundPatternLayerUBO { highp vec2 u_pattern_tl_a; highp vec2 u_pattern_br_a; highp vec2 u_pattern_tl_b; @@ -48,14 +49,11 @@ void main() { highp vec2 u_texsize; highp vec2 u_pattern_size_a; highp vec2 u_pattern_size_b; - highp vec2 u_pixel_coord_upper; - highp vec2 u_pixel_coord_lower; - highp float u_tile_units_to_pixels; highp float u_scale_a; highp float u_scale_b; highp float u_mix; highp float u_opacity; - highp float pad; + highp float layer_pad1, layer_pad2; }; uniform sampler2D u_image; diff --git a/include/mbgl/shaders/gl/drawable_circle.hpp b/include/mbgl/shaders/gl/drawable_circle.hpp index 169c5691d..058613dfb 100644 --- a/include/mbgl/shaders/gl/drawable_circle.hpp +++ b/include/mbgl/shaders/gl/drawable_circle.hpp @@ -14,13 +14,13 @@ out vec3 v_data; layout (std140) uniform CircleDrawableUBO { highp mat4 u_matrix; highp vec2 u_extrude_scale; - lowp vec2 pad2_; + lowp vec2 drawable_pad1; }; layout (std140) uniform CirclePaintParamsUBO { highp float u_camera_to_center_distance; - lowp float pad3_; - lowp vec2 pad4_; + lowp float params_pad1; + lowp vec2 params_pad2; }; layout (std140) uniform CircleEvaluatedPropsUBO { @@ -33,7 +33,7 @@ layout (std140) uniform CircleEvaluatedPropsUBO { lowp float u_stroke_opacity; bool u_scale_with_map; bool u_pitch_with_map; - lowp float pad0_; + lowp float props_pad1; }; layout (std140) uniform CircleInterpolateUBO { @@ -44,7 +44,7 @@ layout (std140) uniform CircleInterpolateUBO { lowp float u_stroke_color_t; lowp float u_stroke_width_t; lowp float u_stroke_opacity_t; - lowp float pad1_; + lowp float interp_pad1; }; #ifndef HAS_UNIFORM_u_color @@ -162,7 +162,7 @@ layout (std140) uniform CircleEvaluatedPropsUBO { lowp float u_stroke_opacity; bool u_scale_with_map; bool u_pitch_with_map; - lowp float pad0_; + lowp float props_pad1; }; #ifndef HAS_UNIFORM_u_color diff --git a/include/mbgl/shaders/gl/drawable_custom_symbol_icon.hpp b/include/mbgl/shaders/gl/drawable_custom_symbol_icon.hpp index 77b4a76b1..c54e31e11 100644 --- a/include/mbgl/shaders/gl/drawable_custom_symbol_icon.hpp +++ b/include/mbgl/shaders/gl/drawable_custom_symbol_icon.hpp @@ -23,7 +23,7 @@ layout(std140) uniform CustomSymbolIconParametersUBO { bool u_pitch_with_map; highp float u_camera_to_center_distance; highp float u_aspect_ratio; - highp float pad0, pad1, pad3; + highp float params_pad1, params_pad2, params_pad3; }; out vec2 v_tex; diff --git a/include/mbgl/shaders/gl/drawable_fill.hpp b/include/mbgl/shaders/gl/drawable_fill.hpp index 988a0d525..38dff9f4a 100644 --- a/include/mbgl/shaders/gl/drawable_fill.hpp +++ b/include/mbgl/shaders/gl/drawable_fill.hpp @@ -11,17 +11,18 @@ struct ShaderSource { static constexpr const char* vertex = R"(layout (std140) uniform FillDrawableUBO { highp mat4 u_matrix; }; -layout (std140) uniform FillEvaluatedPropsUBO { - highp vec4 u_color; - highp float u_opacity; - highp float padding_props1; - highp float padding_props2; - highp float padding_props3; -}; layout (std140) uniform FillInterpolateUBO { highp float u_color_t; highp float u_opacity_t; - highp float pad_interp_1, pad_interp_2; + highp float interp_pad1, interp_pad2; +}; +layout (std140) uniform FillEvaluatedPropsUBO { + highp vec4 u_color; + highp vec4 u_outline_color; + highp float u_opacity; + highp float u_fade; + highp float u_width; + highp float props_pad1; }; layout (location = 0) in vec2 a_pos; @@ -50,17 +51,18 @@ lowp float opacity = u_opacity; gl_Position = u_matrix * vec4(a_pos, 0, 1); } )"; - static constexpr const char* fragment = R"(layout (std140) uniform FillEvaluatedPropsUBO { - highp vec4 u_color; - highp float u_opacity; - highp float padding_props1; - highp float padding_props2; - highp float padding_props3; -}; -layout (std140) uniform FillInterpolateUBO { + static constexpr const char* fragment = R"(layout (std140) uniform FillInterpolateUBO { highp float u_color_t; highp float u_opacity_t; - highp float pad_interp_1, pad_interp_2; + highp float interp_pad1, interp_pad2; +}; +layout (std140) uniform FillEvaluatedPropsUBO { + highp vec4 u_color; + highp vec4 u_outline_color; + highp float u_opacity; + highp float u_fade; + highp float u_width; + highp float props_pad1; }; #ifndef HAS_UNIFORM_u_color diff --git a/include/mbgl/shaders/gl/drawable_fill_extrusion.hpp b/include/mbgl/shaders/gl/drawable_fill_extrusion.hpp index a4ebfe9ec..e4ad268f3 100644 --- a/include/mbgl/shaders/gl/drawable_fill_extrusion.hpp +++ b/include/mbgl/shaders/gl/drawable_fill_extrusion.hpp @@ -12,7 +12,29 @@ struct ShaderSource { layout (location = 1) in vec4 a_normal_ed; out vec4 v_color; -layout (std140) uniform FillExtrusionDrawableTilePropsUBO { +layout (std140) uniform FillExtrusionDrawableUBO { + highp mat4 u_matrix; + highp vec4 u_scale; + highp vec2 u_texsize; + highp vec2 u_pixel_coord_upper; + highp vec2 u_pixel_coord_lower; + highp float u_height_factor; + highp float drawable_pad1; +}; +layout (std140) uniform FillExtrusionPropsUBO { + highp vec4 u_color; + highp vec3 u_lightcolor; + highp float props_pad1; + highp vec3 u_lightpos; + highp float u_base; + highp float u_height; + highp float u_lightintensity; + highp float u_vertical_gradient; + highp float u_opacity; + highp float u_fade; + highp float props_pad2, props_pad3, props_pad4; +}; +layout (std140) uniform FillExtrusionTilePropsUBO { highp vec4 u_pattern_from; highp vec4 u_pattern_to; }; @@ -22,31 +44,8 @@ layout (std140) uniform FillExtrusionInterpolateUBO { highp float u_color_t; highp float u_pattern_from_t; highp float u_pattern_to_t; - highp float u_pad_interp1, u_pad_interp2, u_pad_interp3; + highp float interp_pad1, interp_pad2, interp_pad3; }; -layout (std140) uniform FillExtrusionDrawableUBO { - highp mat4 u_matrix; - highp vec4 u_scale; - highp vec2 u_texsize; - highp vec2 u_pixel_coord_upper; - highp vec2 u_pixel_coord_lower; - highp float u_height_factor; - highp float u_pad_drawable; -}; -layout (std140) uniform FillExtrusionDrawablePropsUBO { - highp vec4 u_color; - highp vec3 u_lightcolor; - highp float u_pad1; - highp vec3 u_lightpos; - highp float u_base; - highp float u_height; - highp float u_lightintensity; - highp float u_vertical_gradient; - highp float u_opacity; - highp float u_fade; - highp float u_pad_props2, u_pad_props3, u_pad_props4; -}; - #ifndef HAS_UNIFORM_u_base layout (location = 2) in highp vec2 a_base; #endif diff --git a/include/mbgl/shaders/gl/drawable_fill_extrusion_pattern.hpp b/include/mbgl/shaders/gl/drawable_fill_extrusion_pattern.hpp index 3d912f6fe..72a648281 100644 --- a/include/mbgl/shaders/gl/drawable_fill_extrusion_pattern.hpp +++ b/include/mbgl/shaders/gl/drawable_fill_extrusion_pattern.hpp @@ -15,7 +15,29 @@ out vec2 v_pos_a; out vec2 v_pos_b; out vec4 v_lighting; -layout (std140) uniform FillExtrusionDrawableTilePropsUBO { +layout (std140) uniform FillExtrusionDrawableUBO { + highp mat4 u_matrix; + highp vec4 u_scale; + highp vec2 u_texsize; + highp vec2 u_pixel_coord_upper; + highp vec2 u_pixel_coord_lower; + highp float u_height_factor; + highp float drawable_pad1; +}; +layout (std140) uniform FillExtrusionPropsUBO { + highp vec4 u_color; + highp vec3 u_lightcolor; + highp float props_pad1; + highp vec3 u_lightpos; + highp float u_base; + highp float u_height; + highp float u_lightintensity; + highp float u_vertical_gradient; + highp float u_opacity; + highp float u_fade; + highp float props_pad2, props_pad3, props_pad4; +}; +layout (std140) uniform FillExtrusionTilePropsUBO { highp vec4 u_pattern_from; highp vec4 u_pattern_to; }; @@ -25,29 +47,7 @@ layout (std140) uniform FillExtrusionInterpolateUBO { highp float u_color_t; highp float u_pattern_from_t; highp float u_pattern_to_t; - highp float u_pad_interp1, u_pad_interp2, u_pad_interp3; -}; -layout (std140) uniform FillExtrusionDrawableUBO { - highp mat4 u_matrix; - highp vec4 u_scale; - highp vec2 u_texsize; - highp vec2 u_pixel_coord_upper; - highp vec2 u_pixel_coord_lower; - highp float u_height_factor; - highp float u_pad_drawable; -}; -layout (std140) uniform FillExtrusionDrawablePropsUBO { - highp vec4 u_color; - highp vec3 u_lightcolor; - highp float u_pad1; - highp vec3 u_lightpos; - highp float u_base; - highp float u_height; - highp float u_lightintensity; - highp float u_vertical_gradient; - highp float u_opacity; - highp float u_fade; - highp float u_pad_props2, u_pad_props3, u_pad_props4; + highp float interp_pad1, interp_pad2, interp_pad3; }; #ifndef HAS_UNIFORM_u_base @@ -140,7 +140,29 @@ mediump vec4 pattern_to = u_pattern_to; in vec2 v_pos_b; in vec4 v_lighting; -layout (std140) uniform FillExtrusionDrawableTilePropsUBO { +layout (std140) uniform FillExtrusionDrawableUBO { + highp mat4 u_matrix; + highp vec4 u_scale; + highp vec2 u_texsize; + highp vec2 u_pixel_coord_upper; + highp vec2 u_pixel_coord_lower; + highp float u_height_factor; + highp float drawable_pad1; +}; +layout (std140) uniform FillExtrusionPropsUBO { + highp vec4 u_color; + highp vec3 u_lightcolor; + highp float props_pad1; + highp vec3 u_lightpos; + highp float u_base; + highp float u_height; + highp float u_lightintensity; + highp float u_vertical_gradient; + highp float u_opacity; + highp float u_fade; + highp float props_pad2, props_pad3, props_pad4; +}; +layout (std140) uniform FillExtrusionTilePropsUBO { highp vec4 u_pattern_from; highp vec4 u_pattern_to; }; @@ -150,29 +172,7 @@ layout (std140) uniform FillExtrusionInterpolateUBO { highp float u_color_t; highp float u_pattern_from_t; highp float u_pattern_to_t; - highp float u_pad_interp1, u_pad_interp2, u_pad_interp3; -}; -layout (std140) uniform FillExtrusionDrawableUBO { - highp mat4 u_matrix; - highp vec4 u_scale; - highp vec2 u_texsize; - highp vec2 u_pixel_coord_upper; - highp vec2 u_pixel_coord_lower; - highp float u_height_factor; - highp float u_pad_drawable; -}; -layout (std140) uniform FillExtrusionDrawablePropsUBO { - highp vec4 u_color; - highp vec3 u_lightcolor; - highp float u_pad1; - highp vec3 u_lightpos; - highp float u_base; - highp float u_height; - highp float u_lightintensity; - highp float u_vertical_gradient; - highp float u_opacity; - highp float u_fade; - highp float u_pad_props2, u_pad_props3, u_pad_props4; + highp float interp_pad1, interp_pad2, interp_pad3; }; uniform sampler2D u_image; diff --git a/include/mbgl/shaders/gl/drawable_fill_outline.hpp b/include/mbgl/shaders/gl/drawable_fill_outline.hpp index ebbd70345..fc742ca36 100644 --- a/include/mbgl/shaders/gl/drawable_fill_outline.hpp +++ b/include/mbgl/shaders/gl/drawable_fill_outline.hpp @@ -11,20 +11,21 @@ struct ShaderSource { static constexpr const char* vertex = R"(layout (std140) uniform FillOutlineDrawableUBO { highp mat4 u_matrix; highp vec2 u_world; - highp vec2 pad; -}; -layout (std140) uniform FillOutlineEvaluatedPropsUBO { - highp vec4 u_outline_color; - highp float u_opacity; - highp float padding_props1; - highp float padding_props2; - highp float padding_props3; + highp vec2 drawable_pad1; }; layout (std140) uniform FillOutlineInterpolateUBO { highp float u_outline_color_t; highp float u_opacity_t; - highp float u_padding_interp1; - highp float u_padding_interp2; + highp float interp_pad1; + highp float interp_pad2; +}; +layout (std140) uniform FillEvaluatedPropsUBO { + highp vec4 u_color; + highp vec4 u_outline_color; + highp float u_opacity; + highp float u_fade; + highp float u_width; + highp float props_pad1; }; layout (location = 0) in vec2 a_pos; @@ -56,18 +57,19 @@ lowp float opacity = u_opacity; v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world; } )"; - static constexpr const char* fragment = R"(layout (std140) uniform FillOutlineEvaluatedPropsUBO { - highp vec4 u_outline_color; - highp float u_opacity; - highp float padding_props1; - highp float padding_props2; - highp float padding_props3; -}; -layout (std140) uniform FillOutlineInterpolateUBO { + static constexpr const char* fragment = R"(layout (std140) uniform FillOutlineInterpolateUBO { highp float u_outline_color_t; highp float u_opacity_t; - highp float u_padding_interp1; - highp float u_padding_interp2; + highp float interp_pad1; + highp float interp_pad2; +}; +layout (std140) uniform FillEvaluatedPropsUBO { + highp vec4 u_color; + highp vec4 u_outline_color; + highp float u_opacity; + highp float u_fade; + highp float u_width; + highp float props_pad1; }; in vec2 v_pos; diff --git a/include/mbgl/shaders/gl/drawable_fill_outline_pattern.hpp b/include/mbgl/shaders/gl/drawable_fill_outline_pattern.hpp index b62c98ded..864e29ed7 100644 --- a/include/mbgl/shaders/gl/drawable_fill_outline_pattern.hpp +++ b/include/mbgl/shaders/gl/drawable_fill_outline_pattern.hpp @@ -16,21 +16,23 @@ struct ShaderSource { highp vec2 u_pixel_coord_upper; highp vec2 u_pixel_coord_lower; highp vec2 u_texsize; - highp float pad1; - highp float pad2; + highp float drawable_pad1; + highp float drawable_pad2; }; -layout (std140) uniform FillPatternEvaluatedPropsUBO { - highp float u_opacity; - highp float u_fade; - highp float padding_props1; - highp float padding_props2; +layout (std140) uniform FillPatternTilePropsUBO { + highp vec4 u_pattern_from; + highp vec4 u_pattern_to; }; layout (std140) uniform FillPatternInterpolateUBO { highp float u_pattern_from_t; highp float u_pattern_to_t; highp float u_opacity_t; - highp float u_padding_interp1; + highp float interp_pad1; }; -layout (std140) uniform FillPatternTilePropsUBO { - highp vec4 u_pattern_from; - highp vec4 u_pattern_to; +layout (std140) uniform FillEvaluatedPropsUBO { + highp vec4 u_color; + highp vec4 u_outline_color; + highp float u_opacity; + highp float u_fade; + highp float u_width; + highp float props_pad1; }; layout (location = 0) in vec2 a_pos; @@ -93,24 +95,26 @@ mediump vec4 pattern_to = u_pattern_to; highp vec2 u_pixel_coord_upper; highp vec2 u_pixel_coord_lower; highp vec2 u_texsize; - highp float pad1; - highp float pad2; + highp float drawable_pad1; + highp float drawable_pad2; }; -layout (std140) uniform FillPatternEvaluatedPropsUBO { - highp float u_opacity; - highp float u_fade; - highp float padding_props1; - highp float padding_props2; +layout (std140) uniform FillPatternTilePropsUBO { + highp vec4 u_pattern_from; + highp vec4 u_pattern_to; }; layout (std140) uniform FillPatternInterpolateUBO { highp float u_pattern_from_t; highp float u_pattern_to_t; highp float u_opacity_t; - highp float u_padding_interp1; + highp float interp_pad1; }; -layout (std140) uniform FillPatternTilePropsUBO { - highp vec4 u_pattern_from; - highp vec4 u_pattern_to; +layout (std140) uniform FillEvaluatedPropsUBO { + highp vec4 u_color; + highp vec4 u_outline_color; + highp float u_opacity; + highp float u_fade; + highp float u_width; + highp float props_pad1; }; uniform sampler2D u_image; diff --git a/include/mbgl/shaders/gl/drawable_heatmap.hpp b/include/mbgl/shaders/gl/drawable_heatmap.hpp index b46ddf2e1..ebec009db 100644 --- a/include/mbgl/shaders/gl/drawable_heatmap.hpp +++ b/include/mbgl/shaders/gl/drawable_heatmap.hpp @@ -14,21 +14,21 @@ out vec2 v_extrude; layout (std140) uniform HeatmapDrawableUBO { highp mat4 u_matrix; highp float u_extrude_scale; - lowp float pad1_; - lowp vec2 pad2_; + lowp float drawable_pad1; + lowp vec2 drawable_pad2; }; layout (std140) uniform HeatmapEvaluatedPropsUBO { highp float u_weight; highp float u_radius; highp float u_intensity; - lowp float pad0_; + lowp float props_pad1; }; layout (std140) uniform HeatmapInterpolateUBO { lowp float u_weight_t; lowp float u_radius_t; - lowp vec2 pad3_; + lowp vec2 interp_pad1; }; #ifndef HAS_UNIFORM_u_weight @@ -95,7 +95,7 @@ layout (std140) uniform HeatmapEvaluatedPropsUBO { highp float u_weight; highp float u_radius; highp float u_intensity; - lowp float pad0_; + lowp float props_pad1; }; #ifndef HAS_UNIFORM_u_weight diff --git a/include/mbgl/shaders/gl/drawable_heatmap_texture.hpp b/include/mbgl/shaders/gl/drawable_heatmap_texture.hpp index ba4ad4459..8c019a1cd 100644 --- a/include/mbgl/shaders/gl/drawable_heatmap_texture.hpp +++ b/include/mbgl/shaders/gl/drawable_heatmap_texture.hpp @@ -11,11 +11,11 @@ struct ShaderSource { static constexpr const char* vertex = R"(layout (location = 0) in vec2 a_pos; out vec2 v_pos; -layout (std140) uniform HeatmapTextureDrawableUBO { +layout (std140) uniform HeatmapTexturePropsUBO { highp mat4 u_matrix; highp vec2 u_world; highp float u_opacity; - lowp float pad0_; + lowp float props_pad1; }; void main() { @@ -29,11 +29,11 @@ void main() { uniform sampler2D u_image; uniform sampler2D u_color_ramp; -layout (std140) uniform HeatmapTextureDrawableUBO { +layout (std140) uniform HeatmapTexturePropsUBO { highp mat4 u_matrix; highp vec2 u_world; highp float u_opacity; - lowp float pad0_; + lowp float props_pad1; }; void main() { diff --git a/include/mbgl/shaders/gl/drawable_line.hpp b/include/mbgl/shaders/gl/drawable_line.hpp index e5dcdabe4..f3868060b 100644 --- a/include/mbgl/shaders/gl/drawable_line.hpp +++ b/include/mbgl/shaders/gl/drawable_line.hpp @@ -21,25 +21,13 @@ layout (location = 1) in vec4 a_data; layout (std140) uniform LineDynamicUBO { highp vec2 u_units_to_pixels; - lowp float pad0, pad1; + lowp float dynamic_pad1, dynamic_pad2; }; -layout (std140) uniform LineUBO { +layout (std140) uniform LineDrawableUBO { highp mat4 u_matrix; mediump float u_ratio; - lowp float pad2, pad3, pad4; -}; - -layout (std140) uniform LinePropertiesUBO { - highp vec4 u_color; - lowp float u_blur; - lowp float u_opacity; - mediump float u_gapwidth; - lowp float u_offset; - mediump float u_width; - - highp float pad5; - highp vec2 pad6; + lowp float drawable_pad1, drawable_pad2, drawable_pad3; }; layout (std140) uniform LineInterpolationUBO { @@ -49,8 +37,19 @@ layout (std140) uniform LineInterpolationUBO { lowp float u_gapwidth_t; lowp float u_offset_t; lowp float u_width_t; + highp vec2 interp_pad1; +}; - highp vec2 pad7; +layout (std140) uniform LineEvaluatedPropsUBO { + highp vec4 u_color; + lowp float u_blur; + lowp float u_opacity; + mediump float u_gapwidth; + lowp float u_offset; + mediump float u_width; + lowp float u_floorwidth; + highp float props_pad1; + highp float props_pad2; }; out vec2 v_normal; @@ -162,22 +161,10 @@ mediump float width = u_width; v_width2 = vec2(outset, inset); } )"; - static constexpr const char* fragment = R"(layout (std140) uniform LineUBO { + static constexpr const char* fragment = R"(layout (std140) uniform LineDrawableUBO { highp mat4 u_matrix; mediump float u_ratio; - lowp float pad2, pad3, pad4; -}; - -layout (std140) uniform LinePropertiesUBO { - highp vec4 u_color; - lowp float u_blur; - lowp float u_opacity; - mediump float u_gapwidth; - lowp float u_offset; - mediump float u_width; - - highp float pad5; - highp vec2 pad6; + lowp float drawable_pad1, drawable_pad2, drawable_pad3; }; layout (std140) uniform LineInterpolationUBO { @@ -187,8 +174,19 @@ layout (std140) uniform LineInterpolationUBO { lowp float u_gapwidth_t; lowp float u_offset_t; lowp float u_width_t; + highp vec2 interp_pad1; +}; - highp vec2 pad7; +layout (std140) uniform LineEvaluatedPropsUBO { + highp vec4 u_color; + lowp float u_blur; + lowp float u_opacity; + mediump float u_gapwidth; + lowp float u_offset; + mediump float u_width; + lowp float u_floorwidth; + highp float props_pad1; + highp float props_pad2; }; in vec2 v_width2; diff --git a/include/mbgl/shaders/gl/drawable_line_gradient.hpp b/include/mbgl/shaders/gl/drawable_line_gradient.hpp index 6ba9b50e1..f3c0b7725 100644 --- a/include/mbgl/shaders/gl/drawable_line_gradient.hpp +++ b/include/mbgl/shaders/gl/drawable_line_gradient.hpp @@ -25,24 +25,13 @@ layout (location = 1) in vec4 a_data; layout (std140) uniform LineDynamicUBO { highp vec2 u_units_to_pixels; - lowp float pad0, pad1; + lowp float dynamic_pad1, dynamic_pad2; }; -layout (std140) uniform LineGradientUBO { +layout (std140) uniform LineGradientDrawableUBO { highp mat4 u_matrix; mediump float u_ratio; - lowp float pad2, pad3, pad4; -}; - -layout (std140) uniform LineGradientPropertiesUBO { - lowp float u_blur; - lowp float u_opacity; - mediump float u_gapwidth; - lowp float u_offset; - mediump float u_width; - - highp float pad5; - highp vec2 pad6; + lowp float drawable_pad1, drawable_pad2, drawable_pad3; }; layout (std140) uniform LineGradientInterpolationUBO { @@ -51,9 +40,20 @@ layout (std140) uniform LineGradientInterpolationUBO { lowp float u_gapwidth_t; lowp float u_offset_t; lowp float u_width_t; + highp float interp_pad1; + highp vec2 interp_pad2; +}; - highp float pad7; - highp vec2 pad8; +layout (std140) uniform LineEvaluatedPropsUBO { + highp vec4 u_color; + lowp float u_blur; + lowp float u_opacity; + mediump float u_gapwidth; + lowp float u_offset; + mediump float u_width; + lowp float u_floorwidth; + highp float props_pad1; + highp float props_pad2; }; out vec2 v_normal; @@ -156,21 +156,10 @@ mediump float width = u_width; v_width2 = vec2(outset, inset); } )"; - static constexpr const char* fragment = R"(layout (std140) uniform LineGradientUBO { + static constexpr const char* fragment = R"(layout (std140) uniform LineGradientDrawableUBO { highp mat4 u_matrix; mediump float u_ratio; - lowp float pad2, pad3, pad4; -}; - -layout (std140) uniform LineGradientPropertiesUBO { - lowp float u_blur; - lowp float u_opacity; - mediump float u_gapwidth; - lowp float u_offset; - mediump float u_width; - - highp float pad5; - highp vec2 pad6; + lowp float drawable_pad1, drawable_pad2, drawable_pad3; }; layout (std140) uniform LineGradientInterpolationUBO { @@ -179,9 +168,20 @@ layout (std140) uniform LineGradientInterpolationUBO { lowp float u_gapwidth_t; lowp float u_offset_t; lowp float u_width_t; + highp float interp_pad1; + highp vec2 interp_pad2; +}; - highp float pad7; - highp vec2 pad8; +layout (std140) uniform LineEvaluatedPropsUBO { + highp vec4 u_color; + lowp float u_blur; + lowp float u_opacity; + mediump float u_gapwidth; + lowp float u_offset; + mediump float u_width; + lowp float u_floorwidth; + highp float props_pad1; + highp float props_pad2; }; uniform sampler2D u_image; diff --git a/include/mbgl/shaders/gl/drawable_line_pattern.hpp b/include/mbgl/shaders/gl/drawable_line_pattern.hpp index d2fdbe3a9..666206c1b 100644 --- a/include/mbgl/shaders/gl/drawable_line_pattern.hpp +++ b/include/mbgl/shaders/gl/drawable_line_pattern.hpp @@ -25,10 +25,10 @@ layout (location = 1) in vec4 a_data; layout (std140) uniform LineDynamicUBO { highp vec2 u_units_to_pixels; - lowp float pad0, pad1; + lowp float dynamic_pad1, dynamic_pad2; }; -layout (std140) uniform LinePatternUBO { +layout (std140) uniform LinePatternDrawableUBO { highp mat4 u_matrix; mediump vec4 u_scale; highp vec2 u_texsize; @@ -36,22 +36,6 @@ layout (std140) uniform LinePatternUBO { highp float u_fade; }; -layout (std140) uniform LinePatternPropertiesUBO { - lowp float u_blur; - lowp float u_opacity; - lowp float u_offset; - mediump float u_gapwidth; - mediump float u_width; - - highp float pad2; - highp vec2 pad3; -}; - -layout (std140) uniform LinePatternTilePropertiesUBO { - lowp vec4 u_pattern_from; - lowp vec4 u_pattern_to; -}; - layout (std140) uniform LinePatternInterpolationUBO { lowp float u_blur_t; lowp float u_opacity_t; @@ -60,8 +44,24 @@ layout (std140) uniform LinePatternInterpolationUBO { lowp float u_width_t; lowp float u_pattern_from_t; lowp float u_pattern_to_t; + highp float interp_pad1; +}; - highp float pad4; +layout (std140) uniform LinePatternTilePropertiesUBO { + lowp vec4 u_pattern_from; + lowp vec4 u_pattern_to; +}; + +layout (std140) uniform LineEvaluatedPropsUBO { + highp vec4 u_color; + lowp float u_blur; + lowp float u_opacity; + mediump float u_gapwidth; + lowp float u_offset; + mediump float u_width; + lowp float u_floorwidth; + highp float props_pad1; + highp float props_pad2; }; out vec2 v_normal; @@ -182,7 +182,7 @@ mediump vec4 pattern_to = u_pattern_to; v_width2 = vec2(outset, inset); } )"; - static constexpr const char* fragment = R"(layout (std140) uniform LinePatternUBO { + static constexpr const char* fragment = R"(layout (std140) uniform LinePatternDrawableUBO { highp mat4 u_matrix; mediump vec4 u_scale; highp vec2 u_texsize; @@ -190,22 +190,6 @@ mediump vec4 pattern_to = u_pattern_to; highp float u_fade; }; -layout (std140) uniform LinePatternPropertiesUBO { - lowp float u_blur; - lowp float u_opacity; - lowp float u_offset; - mediump float u_gapwidth; - mediump float u_width; - - highp float pad2; - highp vec2 pad3; -}; - -layout (std140) uniform LinePatternTilePropertiesUBO { - lowp vec4 u_pattern_from; - lowp vec4 u_pattern_to; -}; - layout (std140) uniform LinePatternInterpolationUBO { lowp float u_blur_t; lowp float u_opacity_t; @@ -214,8 +198,24 @@ layout (std140) uniform LinePatternInterpolationUBO { lowp float u_width_t; lowp float u_pattern_from_t; lowp float u_pattern_to_t; + highp float interp_pad1; +}; - highp float pad4; +layout (std140) uniform LinePatternTilePropertiesUBO { + lowp vec4 u_pattern_from; + lowp vec4 u_pattern_to; +}; + +layout (std140) uniform LineEvaluatedPropsUBO { + highp vec4 u_color; + lowp float u_blur; + lowp float u_opacity; + mediump float u_gapwidth; + lowp float u_offset; + mediump float u_width; + lowp float u_floorwidth; + highp float props_pad1; + highp float props_pad2; }; uniform sampler2D u_image; diff --git a/include/mbgl/shaders/gl/drawable_line_sdf.hpp b/include/mbgl/shaders/gl/drawable_line_sdf.hpp index 52d39174d..d14664510 100644 --- a/include/mbgl/shaders/gl/drawable_line_sdf.hpp +++ b/include/mbgl/shaders/gl/drawable_line_sdf.hpp @@ -25,10 +25,10 @@ layout (location = 1) in vec4 a_data; layout (std140) uniform LineDynamicUBO { highp vec2 u_units_to_pixels; - lowp float pad0, pad1; + lowp float dynamic_pad1, dynamic_pad2; }; -layout (std140) uniform LineSDFUBO { +layout (std140) uniform LineSDFDrawableUBO { highp mat4 u_matrix; highp vec2 u_patternscale_a; highp vec2 u_patternscale_b; @@ -37,19 +37,7 @@ layout (std140) uniform LineSDFUBO { highp float u_tex_y_b; highp float u_sdfgamma; highp float u_mix; - lowp float pad2, pad3, pad4; -}; - -layout (std140) uniform LineSDFPropertiesUBO { - highp vec4 u_color; - lowp float u_blur; - lowp float u_opacity; - mediump float u_gapwidth; - lowp float u_offset; - mediump float u_width; - lowp float u_floorwidth; - - highp vec2 pad5; + lowp float drawable_pad1, drawable_pad2, drawable_pad3; }; layout (std140) uniform LineSDFInterpolationUBO { @@ -60,8 +48,19 @@ layout (std140) uniform LineSDFInterpolationUBO { lowp float u_offset_t; lowp float u_width_t; lowp float u_floorwidth_t; + highp float interp_pad1; +}; - highp float pad6; +layout (std140) uniform LineEvaluatedPropsUBO { + highp vec4 u_color; + lowp float u_blur; + lowp float u_opacity; + mediump float u_gapwidth; + lowp float u_offset; + mediump float u_width; + lowp float u_floorwidth; + highp float props_pad1; + highp float props_pad2; }; out vec2 v_normal; @@ -187,7 +186,7 @@ lowp float floorwidth = u_floorwidth; } )"; static constexpr const char* fragment = R"( -layout (std140) uniform LineSDFUBO { +layout (std140) uniform LineSDFDrawableUBO { highp mat4 u_matrix; highp vec2 u_patternscale_a; highp vec2 u_patternscale_b; @@ -196,20 +195,7 @@ layout (std140) uniform LineSDFUBO { highp float u_tex_y_b; highp float u_sdfgamma; highp float u_mix; - - lowp float pad2, pad3, pad4; -}; - -layout (std140) uniform LineSDFPropertiesUBO { - highp vec4 u_color; - lowp float u_blur; - lowp float u_opacity; - mediump float u_gapwidth; - lowp float u_offset; - mediump float u_width; - lowp float u_floorwidth; - - highp vec2 pad5; + lowp float drawable_pad1, drawable_pad2, drawable_pad3; }; layout (std140) uniform LineSDFInterpolationUBO { @@ -220,8 +206,19 @@ layout (std140) uniform LineSDFInterpolationUBO { lowp float u_offset_t; lowp float u_width_t; lowp float u_floorwidth_t; + highp float interp_pad1; +}; - highp float pad6; +layout (std140) uniform LineEvaluatedPropsUBO { + highp vec4 u_color; + lowp float u_blur; + lowp float u_opacity; + mediump float u_gapwidth; + lowp float u_offset; + mediump float u_width; + lowp float u_floorwidth; + highp float props_pad1; + highp float props_pad2; }; uniform sampler2D u_image; diff --git a/include/mbgl/shaders/gl/drawable_raster.hpp b/include/mbgl/shaders/gl/drawable_raster.hpp index 88aeea88d..36eea70f8 100644 --- a/include/mbgl/shaders/gl/drawable_raster.hpp +++ b/include/mbgl/shaders/gl/drawable_raster.hpp @@ -10,6 +10,8 @@ struct ShaderSource { static constexpr const char* name = "RasterShader"; static constexpr const char* vertex = R"(layout (std140) uniform RasterDrawableUBO { highp mat4 u_matrix; +}; +layout (std140) uniform RasterEvaluatedPropsUBO { highp vec3 u_spin_weights; highp vec2 u_tl_parent; highp float u_scale_parent; @@ -20,8 +22,8 @@ struct ShaderSource { highp float u_brightness_high; highp float u_saturation_factor; highp float u_contrast_factor; - highp float pad1; - highp float pad2; + highp float props_pad1; + highp float props_pad2; }; layout (location = 0) in vec2 a_pos; @@ -41,8 +43,7 @@ void main() { v_pos1 = (v_pos0 * u_scale_parent) + u_tl_parent; } )"; - static constexpr const char* fragment = R"(layout (std140) uniform RasterDrawableUBO { - highp mat4 u_matrix; + static constexpr const char* fragment = R"(layout (std140) uniform RasterEvaluatedPropsUBO { highp vec3 u_spin_weights; highp vec2 u_tl_parent; highp float u_scale_parent; @@ -53,8 +54,8 @@ void main() { highp float u_brightness_high; highp float u_saturation_factor; highp float u_contrast_factor; - highp float pad1; - highp float pad2; + highp float props_pad1; + highp float props_pad2; }; uniform sampler2D u_image0; uniform sampler2D u_image1; diff --git a/include/mbgl/shaders/gl/drawable_symbol_icon.hpp b/include/mbgl/shaders/gl/drawable_symbol_icon.hpp index fe648f653..9d3bc3fa9 100644 --- a/include/mbgl/shaders/gl/drawable_symbol_icon.hpp +++ b/include/mbgl/shaders/gl/drawable_symbol_icon.hpp @@ -14,6 +14,13 @@ layout (location = 2) in vec4 a_pixeloffset; layout (location = 3) in vec3 a_projected_pos; layout (location = 4) in float a_fade_opacity; +layout (std140) uniform SymbolDynamicUBO { + highp float u_fade_change; + highp float u_camera_to_center_distance; + highp float u_aspect_ratio; + highp float dynamic_pad1; +}; + layout (std140) uniform SymbolDrawableUBO { highp mat4 u_matrix; highp mat4 u_label_plane_matrix; @@ -24,26 +31,10 @@ layout (std140) uniform SymbolDrawableUBO { highp float u_gamma_scale; bool u_rotate_symbol; - highp vec2 u_pad1; + highp vec2 drawable_pad1; }; -layout (std140) uniform SymbolDynamicUBO { - highp float u_fade_change; - highp float u_camera_to_center_distance; - highp float u_aspect_ratio; - highp float pad0; -}; - -layout (std140) uniform SymbolDrawablePaintUBO { - highp vec4 u_fill_color; - highp vec4 u_halo_color; - highp float u_opacity; - highp float u_halo_width; - highp float u_halo_blur; - highp float u_padding; -}; - -layout (std140) uniform SymbolDrawableTilePropsUBO { +layout (std140) uniform SymbolTilePropsUBO { bool u_is_text; bool u_is_halo; bool u_pitch_with_map; @@ -51,16 +42,31 @@ layout (std140) uniform SymbolDrawableTilePropsUBO { bool u_is_size_feature_constant; highp float u_size_t; // used to interpolate between zoom stops when size is a composite function highp float u_size; // used when size is both zoom and feature constant - bool u_pad3; + bool tileprops_pad1; }; -layout (std140) uniform SymbolDrawableInterpolateUBO { +layout (std140) uniform SymbolInterpolateUBO { highp float u_fill_color_t; highp float u_halo_color_t; highp float u_opacity_t; highp float u_halo_width_t; highp float u_halo_blur_t; - highp float u_pad4,u_pad5,u_pad6; + highp float interp_pad1, interp_pad2, interp_pad3; +}; + +layout (std140) uniform SymbolEvaluatedPropsUBO { + highp vec4 u_text_fill_color; + highp vec4 u_text_halo_color; + highp float u_text_opacity; + highp float u_text_halo_width; + highp float u_text_halo_blur; + highp float props_pad1; + highp vec4 u_icon_fill_color; + highp vec4 u_icon_halo_color; + highp float u_icon_opacity; + highp float u_icon_halo_width; + highp float u_icon_halo_blur; + highp float props_pad2; }; out vec2 v_tex; @@ -72,6 +78,8 @@ out lowp float opacity; #endif void main() { + highp float u_opacity = u_is_text ? u_text_opacity : u_icon_opacity; + #ifndef HAS_UNIFORM_u_opacity opacity = unpack_mix_vec2(a_opacity, u_opacity_t); #else @@ -140,22 +148,39 @@ lowp float opacity = u_opacity; )"; static constexpr const char* fragment = R"(uniform sampler2D u_texture; -layout (std140) uniform SymbolDrawablePaintUBO { - highp vec4 u_fill_color; - highp vec4 u_halo_color; - highp float u_opacity; - highp float u_halo_width; - highp float u_halo_blur; - highp float u_padding; -}; - -layout (std140) uniform SymbolDrawableInterpolateUBO { +layout (std140) uniform SymbolInterpolateUBO { highp float u_fill_color_t; highp float u_halo_color_t; highp float u_opacity_t; highp float u_halo_width_t; highp float u_halo_blur_t; - highp float u_pad4,u_pad5,u_pad6; + highp float interp_pad1, interp_pad2,interp_pad3; +}; + +layout (std140) uniform SymbolTilePropsUBO { + bool u_is_text; + bool u_is_halo; + bool u_pitch_with_map; + bool u_is_size_zoom_constant; + bool u_is_size_feature_constant; + highp float u_size_t; // used to interpolate between zoom stops when size is a composite function + highp float u_size; // used when size is both zoom and feature constant + bool tileprops_pad1; +}; + +layout (std140) uniform SymbolEvaluatedPropsUBO { + highp vec4 u_text_fill_color; + highp vec4 u_text_halo_color; + highp float u_text_opacity; + highp float u_text_halo_width; + highp float u_text_halo_blur; + highp float props_pad1; + highp vec4 u_icon_fill_color; + highp vec4 u_icon_halo_color; + highp float u_icon_opacity; + highp float u_icon_halo_width; + highp float u_icon_halo_blur; + highp float props_pad2; }; in vec2 v_tex; @@ -166,6 +191,8 @@ in lowp float opacity; #endif void main() { + highp float u_opacity = u_is_text ? u_text_opacity : u_icon_opacity; + #ifdef HAS_UNIFORM_u_opacity lowp float opacity = u_opacity; #endif diff --git a/include/mbgl/shaders/gl/drawable_symbol_sdf.hpp b/include/mbgl/shaders/gl/drawable_symbol_sdf.hpp index 9a6b3d0a7..a67272d10 100644 --- a/include/mbgl/shaders/gl/drawable_symbol_sdf.hpp +++ b/include/mbgl/shaders/gl/drawable_symbol_sdf.hpp @@ -22,6 +22,13 @@ layout (location = 4) in float a_fade_opacity; // [ text-size(lowerZoomStop, feature), // text-size(upperZoomStop, feature) ] +layout (std140) uniform SymbolDynamicUBO { + highp float u_fade_change; + highp float u_camera_to_center_distance; + highp float u_aspect_ratio; + highp float dynamic_pad1; +}; + layout (std140) uniform SymbolDrawableUBO { highp mat4 u_matrix; highp mat4 u_label_plane_matrix; @@ -32,26 +39,10 @@ layout (std140) uniform SymbolDrawableUBO { highp float u_gamma_scale; bool u_rotate_symbol; - highp vec2 u_pad1; + highp vec2 drawable_pad1; }; -layout (std140) uniform SymbolDynamicUBO { - highp float u_fade_change; - highp float u_camera_to_center_distance; - highp float u_aspect_ratio; - highp float pad0; -}; - -layout (std140) uniform SymbolDrawablePaintUBO { - highp vec4 u_fill_color; - highp vec4 u_halo_color; - highp float u_opacity; - highp float u_halo_width; - highp float u_halo_blur; - highp float u_padding; -}; - -layout (std140) uniform SymbolDrawableTilePropsUBO { +layout (std140) uniform SymbolTilePropsUBO { bool u_is_text; bool u_is_halo; bool u_pitch_with_map; @@ -59,16 +50,31 @@ layout (std140) uniform SymbolDrawableTilePropsUBO { bool u_is_size_feature_constant; highp float u_size_t; // used to interpolate between zoom stops when size is a composite function highp float u_size; // used when size is both zoom and feature constant - bool u_pad3; + bool tileprops_pad1; }; -layout (std140) uniform SymbolDrawableInterpolateUBO { +layout (std140) uniform SymbolInterpolateUBO { highp float u_fill_color_t; highp float u_halo_color_t; highp float u_opacity_t; highp float u_halo_width_t; highp float u_halo_blur_t; - highp float u_pad4,u_pad5,u_pad6; + highp float interp_pad1, interp_pad2, interp_pad3; +}; + +layout (std140) uniform SymbolEvaluatedPropsUBO { + highp vec4 u_text_fill_color; + highp vec4 u_text_halo_color; + highp float u_text_opacity; + highp float u_text_halo_width; + highp float u_text_halo_blur; + highp float props_pad1; + highp vec4 u_icon_fill_color; + highp vec4 u_icon_halo_color; + highp float u_icon_opacity; + highp float u_icon_halo_width; + highp float u_icon_halo_blur; + highp float props_pad2; }; out vec2 v_data0; @@ -96,6 +102,12 @@ out lowp float halo_blur; #endif void main() { + highp vec4 u_fill_color = u_is_text ? u_text_fill_color : u_icon_fill_color; + highp vec4 u_halo_color = u_is_text ? u_text_halo_color : u_icon_halo_color; + highp float u_opacity = u_is_text ? u_text_opacity : u_icon_opacity; + highp float u_halo_width = u_is_text ? u_text_halo_width : u_icon_halo_width; + highp float u_halo_blur = u_is_text ? u_text_halo_blur : u_icon_halo_blur; + #ifndef HAS_UNIFORM_u_fill_color fill_color = unpack_mix_color(a_fill_color, u_fill_color_t); #else @@ -193,6 +205,13 @@ lowp float halo_blur = u_halo_blur; )"; static constexpr const char* fragment = R"(#define SDF_PX 8.0 +layout (std140) uniform SymbolDynamicUBO { + highp float u_fade_change; + highp float u_camera_to_center_distance; + highp float u_aspect_ratio; + highp float dynamic_pad1; +}; + layout (std140) uniform SymbolDrawableUBO { highp mat4 u_matrix; highp mat4 u_label_plane_matrix; @@ -203,26 +222,10 @@ layout (std140) uniform SymbolDrawableUBO { highp float u_gamma_scale; bool u_rotate_symbol; - highp vec2 u_pad1; + highp vec2 drawable_pad1; }; -layout (std140) uniform SymbolDynamicUBO { - highp float u_fade_change; - highp float u_camera_to_center_distance; - highp float u_aspect_ratio; - highp float pad0; -}; - -layout (std140) uniform SymbolDrawablePaintUBO { - highp vec4 u_fill_color; - highp vec4 u_halo_color; - highp float u_opacity; - highp float u_halo_width; - highp float u_halo_blur; - highp float u_padding; -}; - -layout (std140) uniform SymbolDrawableTilePropsUBO { +layout (std140) uniform SymbolTilePropsUBO { bool u_is_text; bool u_is_halo; bool u_pitch_with_map; @@ -230,16 +233,31 @@ layout (std140) uniform SymbolDrawableTilePropsUBO { bool u_is_size_feature_constant; highp float u_size_t; // used to interpolate between zoom stops when size is a composite function highp float u_size; // used when size is both zoom and feature constant - bool u_pad3; + bool tileprops_pad1; }; -layout (std140) uniform SymbolDrawableInterpolateUBO { +layout (std140) uniform SymbolInterpolateUBO { highp float u_fill_color_t; highp float u_halo_color_t; highp float u_opacity_t; highp float u_halo_width_t; highp float u_halo_blur_t; - highp float u_pad4,u_pad5,u_pad6; + highp float interp_pad1, interp_pad2, interp_pad3; +}; + +layout (std140) uniform SymbolEvaluatedPropsUBO { + highp vec4 u_text_fill_color; + highp vec4 u_text_halo_color; + highp float u_text_opacity; + highp float u_text_halo_width; + highp float u_text_halo_blur; + highp float props_pad1; + highp vec4 u_icon_fill_color; + highp vec4 u_icon_halo_color; + highp float u_icon_opacity; + highp float u_icon_halo_width; + highp float u_icon_halo_blur; + highp float props_pad2; }; uniform sampler2D u_texture; @@ -264,6 +282,12 @@ in lowp float halo_blur; #endif void main() { + highp vec4 u_fill_color = u_is_text ? u_text_fill_color : u_icon_fill_color; + highp vec4 u_halo_color = u_is_text ? u_text_halo_color : u_icon_halo_color; + highp float u_opacity = u_is_text ? u_text_opacity : u_icon_opacity; + highp float u_halo_width = u_is_text ? u_text_halo_width : u_icon_halo_width; + highp float u_halo_blur = u_is_text ? u_text_halo_blur : u_icon_halo_blur; + #ifdef HAS_UNIFORM_u_fill_color highp vec4 fill_color = u_fill_color; #endif diff --git a/include/mbgl/shaders/gl/drawable_symbol_text_and_icon.hpp b/include/mbgl/shaders/gl/drawable_symbol_text_and_icon.hpp index 7d0f6abe8..657bffbc1 100644 --- a/include/mbgl/shaders/gl/drawable_symbol_text_and_icon.hpp +++ b/include/mbgl/shaders/gl/drawable_symbol_text_and_icon.hpp @@ -21,6 +21,13 @@ layout (location = 3) in float a_fade_opacity; // [ text-size(lowerZoomStop, feature), // text-size(upperZoomStop, feature) ] +layout (std140) uniform SymbolDynamicUBO { + highp float u_fade_change; + highp float u_camera_to_center_distance; + highp float u_aspect_ratio; + highp float dynamic_pad1; +}; + layout (std140) uniform SymbolDrawableUBO { highp mat4 u_matrix; highp mat4 u_label_plane_matrix; @@ -31,26 +38,10 @@ layout (std140) uniform SymbolDrawableUBO { highp float u_gamma_scale; bool u_rotate_symbol; - highp vec2 u_pad1; + highp vec2 drawable_pad1; }; -layout (std140) uniform SymbolDynamicUBO { - highp float u_fade_change; - highp float u_camera_to_center_distance; - highp float u_aspect_ratio; - highp float pad0; -}; - -layout (std140) uniform SymbolDrawablePaintUBO { - highp vec4 u_fill_color; - highp vec4 u_halo_color; - highp float u_opacity; - highp float u_halo_width; - highp float u_halo_blur; - highp float u_padding; -}; - -layout (std140) uniform SymbolDrawableTilePropsUBO { +layout (std140) uniform SymbolTilePropsUBO { bool u_is_text; bool u_is_halo; bool u_pitch_with_map; @@ -58,16 +49,31 @@ layout (std140) uniform SymbolDrawableTilePropsUBO { bool u_is_size_feature_constant; highp float u_size_t; // used to interpolate between zoom stops when size is a composite function highp float u_size; // used when size is both zoom and feature constant - bool u_pad3; + bool tileprops_pad1; }; -layout (std140) uniform SymbolDrawableInterpolateUBO { +layout (std140) uniform SymbolInterpolateUBO { highp float u_fill_color_t; highp float u_halo_color_t; highp float u_opacity_t; highp float u_halo_width_t; highp float u_halo_blur_t; - highp float u_pad4,u_pad5,u_pad6; + highp float interp_pad1, interp_pad2, interp_pad3; +}; + +layout (std140) uniform SymbolEvaluatedPropsUBO { + highp vec4 u_text_fill_color; + highp vec4 u_text_halo_color; + highp float u_text_opacity; + highp float u_text_halo_width; + highp float u_text_halo_blur; + highp float props_pad1; + highp vec4 u_icon_fill_color; + highp vec4 u_icon_halo_color; + highp float u_icon_opacity; + highp float u_icon_halo_width; + highp float u_icon_halo_blur; + highp float props_pad2; }; out vec4 v_data0; @@ -95,6 +101,12 @@ out lowp float halo_blur; #endif void main() { + highp vec4 u_fill_color = u_is_text ? u_text_fill_color : u_icon_fill_color; + highp vec4 u_halo_color = u_is_text ? u_text_halo_color : u_icon_halo_color; + highp float u_opacity = u_is_text ? u_text_opacity : u_icon_opacity; + highp float u_halo_width = u_is_text ? u_text_halo_width : u_icon_halo_width; + highp float u_halo_blur = u_is_text ? u_text_halo_blur : u_icon_halo_blur; + #ifndef HAS_UNIFORM_u_fill_color fill_color = unpack_mix_color(a_fill_color, u_fill_color_t); #else @@ -196,6 +208,13 @@ lowp float halo_blur = u_halo_blur; #define SDF 1.0 #define ICON 0.0 +layout (std140) uniform SymbolDynamicUBO { + highp float u_fade_change; + highp float u_camera_to_center_distance; + highp float u_aspect_ratio; + highp float dynamic_pad1; +}; + layout (std140) uniform SymbolDrawableUBO { highp mat4 u_matrix; highp mat4 u_label_plane_matrix; @@ -206,26 +225,10 @@ layout (std140) uniform SymbolDrawableUBO { highp float u_gamma_scale; bool u_rotate_symbol; - highp vec2 u_pad1; + highp vec2 drawable_pad1; }; -layout (std140) uniform SymbolDynamicUBO { - highp float u_fade_change; - highp float u_camera_to_center_distance; - highp float u_aspect_ratio; - highp float pad0; -}; - -layout (std140) uniform SymbolDrawablePaintUBO { - highp vec4 u_fill_color; - highp vec4 u_halo_color; - highp float u_opacity; - highp float u_halo_width; - highp float u_halo_blur; - highp float u_padding; -}; - -layout (std140) uniform SymbolDrawableTilePropsUBO { +layout (std140) uniform SymbolTilePropsUBO { bool u_is_text; bool u_is_halo; bool u_pitch_with_map; @@ -233,16 +236,31 @@ layout (std140) uniform SymbolDrawableTilePropsUBO { bool u_is_size_feature_constant; highp float u_size_t; // used to interpolate between zoom stops when size is a composite function highp float u_size; // used when size is both zoom and feature constant - bool u_pad3; + bool tileprops_pad1; }; -layout (std140) uniform SymbolDrawableInterpolateUBO { +layout (std140) uniform SymbolInterpolateUBO { highp float u_fill_color_t; highp float u_halo_color_t; highp float u_opacity_t; highp float u_halo_width_t; highp float u_halo_blur_t; - highp float u_pad4,u_pad5,u_pad6; + highp float interp_pad1, interp_pad2,interp_pad3; +}; + +layout (std140) uniform SymbolEvaluatedPropsUBO { + highp vec4 u_text_fill_color; + highp vec4 u_text_halo_color; + highp float u_text_opacity; + highp float u_text_halo_width; + highp float u_text_halo_blur; + highp float props_pad1; + highp vec4 u_icon_fill_color; + highp vec4 u_icon_halo_color; + highp float u_icon_opacity; + highp float u_icon_halo_width; + highp float u_icon_halo_blur; + highp float props_pad2; }; uniform sampler2D u_texture; @@ -268,6 +286,12 @@ in lowp float halo_blur; #endif void main() { + highp vec4 u_fill_color = u_is_text ? u_text_fill_color : u_icon_fill_color; + highp vec4 u_halo_color = u_is_text ? u_text_halo_color : u_icon_halo_color; + highp float u_opacity = u_is_text ? u_text_opacity : u_icon_opacity; + highp float u_halo_width = u_is_text ? u_text_halo_width : u_icon_halo_width; + highp float u_halo_blur = u_is_text ? u_text_halo_blur : u_icon_halo_blur; + #ifdef HAS_UNIFORM_u_fill_color highp vec4 fill_color = u_fill_color; #endif diff --git a/include/mbgl/shaders/gl/shader_info.hpp b/include/mbgl/shaders/gl/shader_info.hpp index 2d62f3124..6447924f3 100644 --- a/include/mbgl/shaders/gl/shader_info.hpp +++ b/include/mbgl/shaders/gl/shader_info.hpp @@ -8,12 +8,6 @@ namespace mbgl { namespace shaders { -struct AttributeInfo { - AttributeInfo(std::string_view name, std::size_t id); - std::string_view name; - std::size_t id; -}; - struct UniformBlockInfo { UniformBlockInfo(std::string_view name, std::size_t id); std::string_view name; @@ -21,6 +15,12 @@ struct UniformBlockInfo { std::size_t binding; }; +struct AttributeInfo { + AttributeInfo(std::string_view name, std::size_t id); + std::string_view name; + std::size_t id; +}; + struct TextureInfo { TextureInfo(std::string_view name, std::size_t id); std::string_view name; diff --git a/include/mbgl/shaders/heatmap_texture_layer_ubo.hpp b/include/mbgl/shaders/heatmap_texture_layer_ubo.hpp index f11a550da..fdc941e02 100644 --- a/include/mbgl/shaders/heatmap_texture_layer_ubo.hpp +++ b/include/mbgl/shaders/heatmap_texture_layer_ubo.hpp @@ -5,16 +5,16 @@ namespace mbgl { namespace shaders { -struct alignas(16) HeatmapTextureDrawableUBO { +struct alignas(16) HeatmapTexturePropsUBO { std::array matrix; std::array world; float opacity; float pad1; }; -static_assert(sizeof(HeatmapTextureDrawableUBO) % 16 == 0); +static_assert(sizeof(HeatmapTexturePropsUBO) % 16 == 0); enum { - idHeatmapTextureDrawableUBO, + idHeatmapTexturePropsUBO, heatmapTextureUBOCount }; diff --git a/include/mbgl/shaders/line_layer_ubo.hpp b/include/mbgl/shaders/line_layer_ubo.hpp index c8c12baaa..be3bf1442 100644 --- a/include/mbgl/shaders/line_layer_ubo.hpp +++ b/include/mbgl/shaders/line_layer_ubo.hpp @@ -15,23 +15,12 @@ struct alignas(16) LineDynamicUBO { }; static_assert(sizeof(LineDynamicUBO) == 16); -struct alignas(16) LineUBO { +struct alignas(16) LineDrawableUBO { std::array matrix; float ratio; float pad1, pad2, pad3; }; -static_assert(sizeof(LineUBO) % 16 == 0); - -struct alignas(16) LinePropertiesUBO { - Color color; - float blur; - float opacity; - float gapwidth; - float offset; - float width; - float pad1, pad2, pad3; -}; -static_assert(sizeof(LinePropertiesUBO) % 16 == 0); +static_assert(sizeof(LineDrawableUBO) % 16 == 0); struct alignas(16) LineInterpolationUBO { float color_t; @@ -44,28 +33,10 @@ struct alignas(16) LineInterpolationUBO { }; static_assert(sizeof(LineInterpolationUBO) % 16 == 0); -enum { - idLineDynamicUBO, - idLineUBO, - idLinePropertiesUBO, - idLineInterpolationUBO, - lineUBOCount -}; - // // Line gradient -using LineGradientUBO = LineUBO; - -struct alignas(16) LineGradientPropertiesUBO { - float blur; - float opacity; - float gapwidth; - float offset; - float width; - float pad1, pad2, pad3; -}; -static_assert(sizeof(LineGradientPropertiesUBO) % 16 == 0); +using LineGradientDrawableUBO = LineDrawableUBO; struct alignas(16) LineGradientInterpolationUBO { float blur_t; @@ -77,35 +48,17 @@ struct alignas(16) LineGradientInterpolationUBO { }; static_assert(sizeof(LineGradientInterpolationUBO) % 16 == 0); -enum { - idLineGradientDynamicUBO, - idLineGradientUBO, - idLineGradientPropertiesUBO, - idLineGradientInterpolationUBO, - lineGradientUBOCount -}; - // // Line pattern -struct alignas(16) LinePatternUBO { +struct alignas(16) LinePatternDrawableUBO { std::array matrix; std::array scale; std::array texsize; float ratio; float fade; }; -static_assert(sizeof(LinePatternUBO) % 16 == 0); - -struct alignas(16) LinePatternPropertiesUBO { - float blur; - float opacity; - float offset; - float gapwidth; - float width; - float pad1, pad2, pad3; -}; -static_assert(sizeof(LinePatternPropertiesUBO) % 16 == 0); +static_assert(sizeof(LinePatternDrawableUBO) % 16 == 0); struct alignas(16) LinePatternInterpolationUBO { float blur_t; @@ -125,19 +78,10 @@ struct alignas(16) LinePatternTilePropertiesUBO { }; static_assert(sizeof(LinePatternTilePropertiesUBO) % 16 == 0); -enum { - idLinePatternDynamicUBO, - idLinePatternUBO, - idLinePatternPropertiesUBO, - idLinePatternInterpolationUBO, - idLinePatternTilePropertiesUBO, - linePatternUBOCount -}; - // // Line SDF -struct alignas(16) LineSDFUBO { +struct alignas(16) LineSDFDrawableUBO { std::array matrix; std::array patternscale_a; std::array patternscale_b; @@ -148,19 +92,7 @@ struct alignas(16) LineSDFUBO { float mix; float pad1, pad2, pad3; }; -static_assert(sizeof(LineSDFUBO) % 16 == 0); - -struct alignas(16) LineSDFPropertiesUBO { - Color color; - float blur; - float opacity; - float gapwidth; - float offset; - float width; - float floorwidth; - float pad1, pad2; -}; -static_assert(sizeof(LineSDFPropertiesUBO) % 16 == 0); +static_assert(sizeof(LineSDFDrawableUBO) % 16 == 0); struct alignas(16) LineSDFInterpolationUBO { float color_t; @@ -174,12 +106,28 @@ struct alignas(16) LineSDFInterpolationUBO { }; static_assert(sizeof(LineSDFInterpolationUBO) % 16 == 0); +// +// Line evaluated properties + +struct alignas(16) LineEvaluatedPropsUBO { + Color color; + float blur; + float opacity; + float gapwidth; + float offset; + float width; + float floorwidth; + float pad1, pad2; +}; +static_assert(sizeof(LineEvaluatedPropsUBO) % 16 == 0); + enum { - idLineSDFDynamicUBO, - idLineSDFUBO, - idLineSDFPropertiesUBO, - idLineSDFInterpolationUBO, - lineSDFUBOCount + idLineDynamicUBO, + idLineDrawableUBO, + idLineInterpolationUBO, + idLineTilePropertiesUBO, + idLineEvaluatedPropsUBO, + lineUBOCount }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/background.hpp b/include/mbgl/shaders/mtl/background.hpp index 9598440da..41a85e893 100644 --- a/include/mbgl/shaders/mtl/background.hpp +++ b/include/mbgl/shaders/mtl/background.hpp @@ -14,9 +14,9 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array uniforms; static const std::array textures; static constexpr auto source = R"( @@ -24,7 +24,7 @@ struct ShaderSource { using namespace metal; struct VertexStage { - short2 position [[attribute(0)]]; + short2 position [[attribute(2)]]; }; struct FragmentStage { @@ -37,20 +37,18 @@ struct alignas(16) BackgroundDrawableUBO { struct alignas(16) BackgroundLayerUBO { float4 color; float opacity; - bool overdrawInspector; - uint8_t pad1, pad2, pad3; - float pad4, pad5; + float pad1, pad2, pad3; }; FragmentStage vertex vertexMain(VertexStage in [[stage_in]], - device const BackgroundDrawableUBO& drawableUBO [[buffer(1)]]) { + device const BackgroundDrawableUBO& drawableUBO [[buffer(0)]]) { return { .position = drawableUBO.matrix * float4(float2(in.position.xy), 0, 1) }; } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const BackgroundLayerUBO& layerUBO [[buffer(2)]]) { + device const BackgroundLayerUBO& layerUBO [[buffer(1)]]) { #if defined(OVERDRAW_INSPECTOR) return half4(1.0); #endif diff --git a/include/mbgl/shaders/mtl/background_pattern.hpp b/include/mbgl/shaders/mtl/background_pattern.hpp index b9c8c34fa..747b016cd 100644 --- a/include/mbgl/shaders/mtl/background_pattern.hpp +++ b/include/mbgl/shaders/mtl/background_pattern.hpp @@ -11,9 +11,9 @@ struct ShaderSource static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array uniforms; static const std::array textures; static constexpr auto source = R"( @@ -21,7 +21,7 @@ struct ShaderSource using namespace metal; struct VertexStage { - short2 position [[attribute(0)]]; + short2 position [[attribute(2)]]; }; struct FragmentStage { @@ -30,10 +30,14 @@ struct FragmentStage { float2 pos_b; }; -struct alignas(16) BackgroundDrawableUBO { +struct alignas(16) BackgroundPatternDrawableUBO { float4x4 matrix; + float2 pixel_coord_upper; + float2 pixel_coord_lower; + float tile_units_to_pixels; + float pad1, pad2, pad3; }; -struct alignas(16) BackgroundLayerUBO { +struct alignas(16) BackgroundPatternLayerUBO { float2 pattern_tl_a; float2 pattern_br_a; float2 pattern_tl_b; @@ -41,30 +45,26 @@ struct alignas(16) BackgroundLayerUBO { float2 texsize; float2 pattern_size_a; float2 pattern_size_b; - float2 pixel_coord_upper; - float2 pixel_coord_lower; - float tile_units_to_pixels; float scale_a; float scale_b; float mix; float opacity; - bool overdrawInspector; - uint8_t pad1, pad2, pad3; + float pad1, pad2; }; FragmentStage vertex vertexMain(VertexStage in [[stage_in]], - device const BackgroundDrawableUBO& drawableUBO [[buffer(1)]], - device const BackgroundLayerUBO& layerUBO [[buffer(2)]]) { + device const BackgroundPatternDrawableUBO& drawableUBO [[buffer(0)]], + device const BackgroundPatternLayerUBO& layerUBO [[buffer(1)]]) { const float2 pos = float2(in.position); - const float2 pos_a = get_pattern_pos(layerUBO.pixel_coord_upper, - layerUBO.pixel_coord_lower, + const float2 pos_a = get_pattern_pos(drawableUBO.pixel_coord_upper, + drawableUBO.pixel_coord_lower, layerUBO.scale_a * layerUBO.pattern_size_a, - layerUBO.tile_units_to_pixels, + drawableUBO.tile_units_to_pixels, pos); - const float2 pos_b = get_pattern_pos(layerUBO.pixel_coord_upper, - layerUBO.pixel_coord_lower, + const float2 pos_b = get_pattern_pos(drawableUBO.pixel_coord_upper, + drawableUBO.pixel_coord_lower, layerUBO.scale_b * layerUBO.pattern_size_b, - layerUBO.tile_units_to_pixels, + drawableUBO.tile_units_to_pixels, pos); return { .position = drawableUBO.matrix * float4(float2(in.position.xy), 0, 1), @@ -74,7 +74,7 @@ FragmentStage vertex vertexMain(VertexStage in [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const BackgroundLayerUBO& layerUBO [[buffer(2)]], + device const BackgroundPatternLayerUBO& layerUBO [[buffer(1)]], texture2d image [[texture(0)]], sampler image_sampler [[sampler(0)]]) { #if defined(OVERDRAW_INSPECTOR) diff --git a/include/mbgl/shaders/mtl/circle.hpp b/include/mbgl/shaders/mtl/circle.hpp index e958b0bb4..156616c7a 100644 --- a/include/mbgl/shaders/mtl/circle.hpp +++ b/include/mbgl/shaders/mtl/circle.hpp @@ -14,35 +14,35 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array uniforms; static const std::array textures; static constexpr auto source = R"( struct VertexStage { - short2 position [[attribute(0)]]; + short2 position [[attribute(4)]]; #if !defined(HAS_UNIFORM_u_color) - float4 color [[attribute(1)]]; + float4 color [[attribute(5)]]; #endif #if !defined(HAS_UNIFORM_u_radius) - float2 radius [[attribute(2)]]; + float2 radius [[attribute(6)]]; #endif #if !defined(HAS_UNIFORM_u_blur) - float2 blur [[attribute(3)]]; + float2 blur [[attribute(7)]]; #endif #if !defined(HAS_UNIFORM_u_opacity) - float2 opacity [[attribute(4)]]; + float2 opacity [[attribute(8)]]; #endif #if !defined(HAS_UNIFORM_u_stroke_color) - float4 stroke_color [[attribute(5)]]; + float4 stroke_color [[attribute(9)]]; #endif #if !defined(HAS_UNIFORM_u_stroke_width) - float2 stroke_width [[attribute(6)]]; + float2 stroke_width [[attribute(10)]]; #endif #if !defined(HAS_UNIFORM_u_stroke_opacity) - float2 stroke_opacity [[attribute(7)]]; + float2 stroke_opacity [[attribute(11)]]; #endif }; @@ -108,10 +108,10 @@ struct alignas(16) CircleInterpolateUBO { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const CircleDrawableUBO& drawable [[buffer(8)]], - device const CirclePaintParamsUBO& params [[buffer(9)]], - device const CircleEvaluatedPropsUBO& props [[buffer(10)]], - device const CircleInterpolateUBO& interp [[buffer(11)]]) { + device const CircleDrawableUBO& drawable [[buffer(0)]], + device const CirclePaintParamsUBO& params [[buffer(1)]], + device const CircleEvaluatedPropsUBO& props [[buffer(2)]], + device const CircleInterpolateUBO& interp [[buffer(3)]]) { #if defined(HAS_UNIFORM_u_radius) const auto radius = props.radius; @@ -189,8 +189,8 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const CirclePaintParamsUBO& params [[buffer(9)]], - device const CircleEvaluatedPropsUBO& props [[buffer(10)]]) { + device const CirclePaintParamsUBO& params [[buffer(1)]], + device const CircleEvaluatedPropsUBO& props [[buffer(2)]]) { #if defined(OVERDRAW_INSPECTOR) return half4(1.0); #endif diff --git a/include/mbgl/shaders/mtl/clipping_mask.hpp b/include/mbgl/shaders/mtl/clipping_mask.hpp index aff9b5e91..a331c2687 100644 --- a/include/mbgl/shaders/mtl/clipping_mask.hpp +++ b/include/mbgl/shaders/mtl/clipping_mask.hpp @@ -20,9 +20,9 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array uniforms; static const std::array textures; static constexpr auto source = R"( @@ -38,7 +38,7 @@ struct alignas(16) ClipUBO { static_assert(sizeof(ClipUBO) == 5 * 16, "unexpected padding"); struct VertexStage { - short2 position [[attribute(0)]]; + short2 position [[attribute(1)]]; }; struct FragmentStage { @@ -51,7 +51,7 @@ struct FragmentResult { }; FragmentStage vertex vertexMain(VertexStage in [[stage_in]], - device const ClipUBO& clipUBO [[buffer(1)]]) { + device const ClipUBO& clipUBO [[buffer(0)]]) { return { clipUBO.matrix * float4(float2(in.position.xy), 0, 1) }; } diff --git a/include/mbgl/shaders/mtl/collision_box.hpp b/include/mbgl/shaders/mtl/collision_box.hpp index 0f6cf4a0a..b99d15eee 100644 --- a/include/mbgl/shaders/mtl/collision_box.hpp +++ b/include/mbgl/shaders/mtl/collision_box.hpp @@ -14,19 +14,19 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array uniforms; static const std::array textures; static constexpr auto source = R"( struct VertexStage { - short2 pos [[attribute(0)]]; - short2 anchor_pos [[attribute(1)]]; - short2 extrude [[attribute(2)]]; - ushort2 placed [[attribute(3)]]; - float2 shift [[attribute(4)]]; + short2 pos [[attribute(1)]]; + short2 anchor_pos [[attribute(2)]]; + short2 extrude [[attribute(3)]]; + ushort2 placed [[attribute(4)]]; + float2 shift [[attribute(5)]]; }; struct FragmentStage { @@ -43,7 +43,7 @@ struct alignas(16) CollisionBoxUBO { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const CollisionBoxUBO& drawable [[buffer(5)]]) { + device const CollisionBoxUBO& drawable [[buffer(0)]]) { float4 projectedPoint = drawable.matrix * float4(float2(vertx.anchor_pos), 0, 1); float camera_to_anchor_distance = projectedPoint.w; @@ -66,7 +66,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const CollisionBoxUBO& drawable [[buffer(5)]]) { + device const CollisionBoxUBO& drawable [[buffer(0)]]) { float alpha = 0.5; diff --git a/include/mbgl/shaders/mtl/collision_circle.hpp b/include/mbgl/shaders/mtl/collision_circle.hpp index 69bd046ad..712dedce1 100644 --- a/include/mbgl/shaders/mtl/collision_circle.hpp +++ b/include/mbgl/shaders/mtl/collision_circle.hpp @@ -14,18 +14,18 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array uniforms; static const std::array textures; static constexpr auto source = R"( struct VertexStage { - short2 pos [[attribute(0)]]; - short2 anchor_pos [[attribute(1)]]; - short2 extrude [[attribute(2)]]; - ushort2 placed [[attribute(3)]]; + short2 pos [[attribute(1)]]; + short2 anchor_pos [[attribute(2)]]; + short2 extrude [[attribute(3)]]; + ushort2 placed [[attribute(4)]]; }; struct FragmentStage { @@ -45,7 +45,7 @@ struct alignas(16) CollisionCircleUBO { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const CollisionCircleUBO& drawable [[buffer(4)]]) { + device const CollisionCircleUBO& drawable [[buffer(0)]]) { float4 projectedPoint = drawable.matrix * float4(float2(vertx.anchor_pos), 0, 1); float camera_to_anchor_distance = projectedPoint.w; @@ -77,7 +77,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const CollisionCircleUBO& drawable [[buffer(4)]]) { + device const CollisionCircleUBO& drawable [[buffer(0)]]) { float alpha = 0.5; diff --git a/include/mbgl/shaders/mtl/common.hpp b/include/mbgl/shaders/mtl/common.hpp index 39d655b14..02a6f825a 100644 --- a/include/mbgl/shaders/mtl/common.hpp +++ b/include/mbgl/shaders/mtl/common.hpp @@ -54,82 +54,82 @@ float4 unpack_mix_color(const float4 packedColors, const float t) { decode_color(float2(packedColors[2], packedColors[3])), t); } +struct alignas(16) FillEvaluatedPropsUBO { + float4 color; + float4 outline_color; + float opacity; + float fade; + float width; + float pad1; +}; + +struct alignas(16) FillExtrusionDrawableUBO { + /* 0 */ float4x4 matrix; + /* 64 */ float4 scale; + /* 80 */ float2 texsize; + /* 88 */ float2 pixel_coord_upper; + /* 96 */ float2 pixel_coord_lower; + /* 104 */ float height_factor; + /* 108 */ float pad; + /* 112 */ +}; +static_assert(sizeof(FillExtrusionDrawableUBO) == 7 * 16, "unexpected padding"); + +struct alignas(16) FillExtrusionPropsUBO { + /* 0 */ float4 color; + /* 16 */ float4 light_color_pad; + /* 32 */ float4 light_position_base; + /* 48 */ float height; + /* 52 */ float light_intensity; + /* 56 */ float vertical_gradient; + /* 60 */ float opacity; + /* 64 */ float fade; + /* 68 */ float pad2, pad3, pad4; + /* 80 */ +}; +static_assert(sizeof(FillExtrusionPropsUBO) == 5 * 16, "unexpected padding"); + +struct alignas(16) FillExtrusionTilePropsUBO { + /* 0 */ float4 pattern_from; + /* 16 */ float4 pattern_to; + /* 32 */ +}; +static_assert(sizeof(FillExtrusionTilePropsUBO) == 2 * 16, "unexpected padding"); + +struct alignas(16) FillExtrusionInterpolateUBO { + /* 0 */ float base_t; + /* 4 */ float height_t; + /* 8 */ float color_t; + /* 12 */ float pattern_from_t; + /* 16 */ float pattern_to_t; + /* 20 */ float pad1, pad2, pad3; + /* 32 */ +}; +static_assert(sizeof(FillExtrusionInterpolateUBO) == 2 * 16, "unexpected padding"); + struct alignas(16) LineDynamicUBO { float2 units_to_pixels; float pad1, pad2; }; -struct alignas(16) LineUBO { - float4x4 matrix; - float ratio; - float pad1, pad2, pad3; -}; - -struct alignas(16) LineGradientUBO { - float4x4 matrix; - float ratio; - float pad1, pad2, pad3; -}; - -struct alignas(16) LinePropertiesUBO { +struct alignas(16) LineEvaluatedPropsUBO { float4 color; float blur; float opacity; float gapwidth; float offset; float width; - float pad1, pad2, pad3; -}; - -struct alignas(16) LineGradientPropertiesUBO { - float blur; - float opacity; - float gapwidth; - float offset; - float width; - float pad1, pad2, pad3; -}; - -struct alignas(16) LineInterpolationUBO { - float color_t; - float blur_t; - float opacity_t; - float gapwidth_t; - float offset_t; - float width_t; + float floorwidth; float pad1, pad2; }; -struct alignas(16) LineGradientInterpolationUBO { - float blur_t; - float opacity_t; - float gapwidth_t; - float offset_t; - float width_t; - float pad1, pad2, pad3; +struct alignas(16) SymbolDynamicUBO { + float fade_change; + float camera_to_center_distance; + float aspect_ratio; + float pad; }; - -struct alignas(16) SymbolDrawableTilePropsUBO { - /*bool*/ int is_text; - /*bool*/ int is_halo; - /*bool*/ int pitch_with_map; - /*bool*/ int is_size_zoom_constant; - /*bool*/ int is_size_feature_constant; - float size_t; - float size; - float padding; -}; -static_assert(sizeof(SymbolDrawableTilePropsUBO) == 2 * 16, "unexpected padding"); - -struct alignas(16) SymbolDrawableInterpolateUBO { - float fill_color_t; - float halo_color_t; - float opacity_t; - float halo_width_t; - float halo_blur_t; - float pad1, pad2, pad3; -}; -static_assert(sizeof(SymbolDrawableInterpolateUBO) == 32, "unexpected padding"); +static_assert(sizeof(SymbolDynamicUBO) == 16, "unexpected padding"); struct alignas(16) SymbolDrawableUBO { float4x4 matrix; @@ -145,23 +145,43 @@ struct alignas(16) SymbolDrawableUBO { }; static_assert(sizeof(SymbolDrawableUBO) == 14 * 16, "unexpected padding"); -struct alignas(16) SymbolDynamicUBO { - float fade_change; - float camera_to_center_distance; - float aspect_ratio; - float pad; -}; -static_assert(sizeof(SymbolDynamicUBO) == 16, "unexpected padding"); - -struct alignas(16) SymbolDrawablePaintUBO { - float4 fill_color; - float4 halo_color; - float opacity; - float halo_width; - float halo_blur; +struct alignas(16) SymbolTilePropsUBO { + /*bool*/ int is_text; + /*bool*/ int is_halo; + /*bool*/ int pitch_with_map; + /*bool*/ int is_size_zoom_constant; + /*bool*/ int is_size_feature_constant; + float size_t; + float size; float padding; }; -static_assert(sizeof(SymbolDrawablePaintUBO) == 3 * 16, "unexpected padding"); +static_assert(sizeof(SymbolTilePropsUBO) == 2 * 16, "unexpected padding"); + +struct alignas(16) SymbolInterpolateUBO { + float fill_color_t; + float halo_color_t; + float opacity_t; + float halo_width_t; + float halo_blur_t; + float pad1, pad2, pad3; +}; +static_assert(sizeof(SymbolInterpolateUBO) == 32, "unexpected padding"); + +struct alignas(16) SymbolEvaluatedPropsUBO { + float4 text_fill_color; + float4 text_halo_color; + float text_opacity; + float text_halo_width; + float text_halo_blur; + float pad1; + float4 icon_fill_color; + float4 icon_halo_color; + float icon_opacity; + float icon_halo_width; + float icon_halo_blur; + float pad2; +}; +static_assert(sizeof(SymbolEvaluatedPropsUBO) == 6 * 16, "unexpected padding"); // unpack pattern position inline float2 get_pattern_pos(const float2 pixel_coord_upper, const float2 pixel_coord_lower, diff --git a/include/mbgl/shaders/mtl/custom_symbol_icon.hpp b/include/mbgl/shaders/mtl/custom_symbol_icon.hpp index a2dd97502..db149f3a4 100644 --- a/include/mbgl/shaders/mtl/custom_symbol_icon.hpp +++ b/include/mbgl/shaders/mtl/custom_symbol_icon.hpp @@ -14,9 +14,9 @@ struct ShaderSource static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array uniforms; static const std::array textures; static constexpr auto source = R"( @@ -36,8 +36,8 @@ struct alignas(16) CustomSymbolIconParametersUBO { }; struct VertexStage { - float2 a_pos [[attribute(0)]]; - float2 a_tex [[attribute(1)]]; + float2 a_pos [[attribute(2)]]; + float2 a_tex [[attribute(3)]]; }; struct FragmentStage { @@ -59,8 +59,8 @@ float2 ellipseRotateVec2(float2 v, float angle, float radiusRatio /* A/B */) { } FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const CustomSymbolIconDrawableUBO& drawable [[buffer(2)]], - device const CustomSymbolIconParametersUBO& parameters [[buffer(3)]]) { + device const CustomSymbolIconDrawableUBO& drawable [[buffer(0)]], + device const CustomSymbolIconParametersUBO& parameters [[buffer(1)]]) { const float2 extrude = glMod(float2(vertx.a_pos), 2.0) * 2.0 - 1.0; const float2 anchor = (parameters.anchor - float2(0.5, 0.5)) * 2.0; diff --git a/include/mbgl/shaders/mtl/debug.hpp b/include/mbgl/shaders/mtl/debug.hpp index 998db726f..dd0362108 100644 --- a/include/mbgl/shaders/mtl/debug.hpp +++ b/include/mbgl/shaders/mtl/debug.hpp @@ -14,15 +14,15 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array uniforms; static const std::array textures; static constexpr auto source = R"( struct VertexStage { - short2 pos [[attribute(0)]]; + short2 pos [[attribute(1)]]; }; struct FragmentStage { @@ -38,7 +38,7 @@ struct alignas(16) DebugUBO { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const DebugUBO& debugUBO [[buffer(1)]]) { + device const DebugUBO& debugUBO [[buffer(0)]]) { const float4 position = debugUBO.matrix * float4(float2(vertx.pos) * debugUBO.overlay_scale, 0, 1); @@ -53,7 +53,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const DebugUBO& debugUBO [[buffer(1)]], + device const DebugUBO& debugUBO [[buffer(0)]], texture2d overlay [[texture(0)]], sampler overlay_sampler [[sampler(0)]]) { diff --git a/include/mbgl/shaders/mtl/fill.hpp b/include/mbgl/shaders/mtl/fill.hpp index 1cc80fa0f..a00a2548e 100644 --- a/include/mbgl/shaders/mtl/fill.hpp +++ b/include/mbgl/shaders/mtl/fill.hpp @@ -14,21 +14,21 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array uniforms; static const std::array textures; static constexpr auto source = R"( struct VertexStage { - short2 position [[attribute(0)]]; + short2 position [[attribute(4)]]; #if !defined(HAS_UNIFORM_u_color) - float4 color [[attribute(1)]]; + float4 color [[attribute(5)]]; #endif #if !defined(HAS_UNIFORM_u_opacity) - float2 opacity [[attribute(2)]]; + float2 opacity [[attribute(6)]]; #endif }; @@ -47,20 +47,15 @@ struct alignas(16) FillDrawableUBO { float4x4 matrix; }; -struct alignas(16) FillEvaluatedPropsUBO { - float4 color; - float opacity; -}; - struct alignas(16) FillInterpolateUBO { float color_t; float opacity_t; }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const FillDrawableUBO& drawable [[buffer(3)]], - device const FillEvaluatedPropsUBO& props [[buffer(4)]], - device const FillInterpolateUBO& interp [[buffer(5)]]) { + device const FillDrawableUBO& drawable [[buffer(0)]], + device const FillInterpolateUBO& interp [[buffer(2)]], + device const FillEvaluatedPropsUBO& props [[buffer(3)]]) { return { .position = drawable.matrix * float4(float2(vertx.position), 0.0f, 1.0f), #if !defined(HAS_UNIFORM_u_color) @@ -73,7 +68,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const FillEvaluatedPropsUBO& props [[buffer(4)]]) { + device const FillEvaluatedPropsUBO& props [[buffer(3)]]) { #if defined(OVERDRAW_INSPECTOR) return half4(1.0); #endif @@ -101,16 +96,16 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array uniforms; static const std::array textures; static constexpr auto source = R"( struct VertexStage { - short2 position [[attribute(0)]]; - float4 outline_color [[attribute(1)]]; - float2 opacity [[attribute(2)]]; + short2 position [[attribute(4)]]; + float4 outline_color [[attribute(5)]]; + float2 opacity [[attribute(6)]]; }; struct FragmentStage { @@ -130,20 +125,15 @@ struct alignas(16) FillOutlineDrawableUBO { float2 pad1; }; -struct alignas(16) FillOutlineEvaluatedPropsUBO { - float4 outline_color; - float opacity; -}; - struct alignas(16) FillOutlineInterpolateUBO { float outline_color_t; float opacity_t; }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const FillOutlineDrawableUBO& drawable [[buffer(3)]], - device const FillOutlineEvaluatedPropsUBO& props [[buffer(4)]], - device const FillOutlineInterpolateUBO& interp [[buffer(5)]]) { + device const FillOutlineDrawableUBO& drawable [[buffer(0)]], + device const FillOutlineInterpolateUBO& interp [[buffer(2)]], + device const FillEvaluatedPropsUBO& props [[buffer(3)]]) { const float4 position = drawable.matrix * float4(float2(vertx.position), 0.0f, 1.0f); return { .position = position, @@ -158,7 +148,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const FillOutlineEvaluatedPropsUBO& props [[buffer(4)]]) { + device const FillEvaluatedPropsUBO& props [[buffer(3)]]) { #if defined(OVERDRAW_INSPECTOR) return half4(1.0); #endif @@ -192,23 +182,23 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array uniforms; static const std::array textures; static constexpr auto source = R"( struct VertexStage { - short2 position [[attribute(0)]]; + short2 position [[attribute(4)]]; #if !defined(HAS_UNIFORM_u_pattern_from) - ushort4 pattern_from [[attribute(1)]]; + ushort4 pattern_from [[attribute(5)]]; #endif #if !defined(HAS_UNIFORM_u_pattern_to) - ushort4 pattern_to [[attribute(2)]]; + ushort4 pattern_to [[attribute(6)]]; #endif #if !defined(HAS_UNIFORM_u_opacity) - float2 opacity [[attribute(3)]]; + float2 opacity [[attribute(7)]]; #endif }; @@ -236,11 +226,6 @@ struct alignas(16) FillPatternDrawableUBO { float2 texsize; }; -struct alignas(16) FillPatternEvaluatedPropsUBO { - float opacity; - float fade; -}; - struct alignas(16) FillPatternTilePropsUBO { float4 pattern_from; float4 pattern_to; @@ -253,10 +238,10 @@ struct alignas(16) FillPatternInterpolateUBO { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const FillPatternDrawableUBO& drawable [[buffer(4)]], - device const FillPatternTilePropsUBO& tileProps [[buffer(5)]], - device const FillPatternEvaluatedPropsUBO& props [[buffer(6)]], - device const FillPatternInterpolateUBO& interp [[buffer(7)]]) { + device const FillPatternDrawableUBO& drawable [[buffer(0)]], + device const FillPatternTilePropsUBO& tileProps [[buffer(1)]], + device const FillPatternInterpolateUBO& interp [[buffer(2)]], + device const FillEvaluatedPropsUBO& props [[buffer(3)]]) { #if defined(HAS_UNIFORM_u_pattern_from) const auto pattern_from = float4(tileProps.pattern_from); #else @@ -300,9 +285,9 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const FillPatternDrawableUBO& drawable [[buffer(4)]], - device const FillPatternTilePropsUBO& tileProps [[buffer(5)]], - device const FillPatternEvaluatedPropsUBO& props [[buffer(6)]], + device const FillPatternDrawableUBO& drawable [[buffer(0)]], + device const FillPatternTilePropsUBO& tileProps [[buffer(1)]], + device const FillEvaluatedPropsUBO& props [[buffer(3)]], texture2d image0 [[texture(0)]], sampler image0_sampler [[sampler(0)]]) { #if defined(OVERDRAW_INSPECTOR) @@ -351,24 +336,24 @@ struct ShaderSource uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array uniforms; static const std::array textures; static constexpr auto source = R"( struct VertexStage { - short2 position [[attribute(0)]]; + short2 position [[attribute(4)]]; #if !defined(HAS_UNIFORM_u_pattern_from) - ushort4 pattern_from [[attribute(1)]]; + ushort4 pattern_from [[attribute(5)]]; #endif #if !defined(HAS_UNIFORM_u_pattern_to) - ushort4 pattern_to [[attribute(2)]]; + ushort4 pattern_to [[attribute(6)]]; #endif #if !defined(HAS_UNIFORM_u_opacity) - float2 opacity [[attribute(3)]]; + float2 opacity [[attribute(7)]]; #endif }; @@ -398,11 +383,6 @@ struct alignas(16) FillOutlinePatternDrawableUBO { float2 texsize; }; -struct alignas(16) FillOutlinePatternEvaluatedPropsUBO { - float opacity; - float fade; -}; - struct alignas(16) FillOutlinePatternTilePropsUBO { float4 pattern_from; float4 pattern_to; @@ -415,10 +395,10 @@ struct alignas(16) FillOutlinePatternInterpolateUBO { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const FillOutlinePatternDrawableUBO& drawable [[buffer(4)]], - device const FillOutlinePatternTilePropsUBO& tileProps [[buffer(5)]], - device const FillOutlinePatternEvaluatedPropsUBO& props [[buffer(6)]], - device const FillOutlinePatternInterpolateUBO& interp [[buffer(7)]]) { + device const FillOutlinePatternDrawableUBO& drawable [[buffer(0)]], + device const FillOutlinePatternTilePropsUBO& tileProps [[buffer(1)]], + device const FillOutlinePatternInterpolateUBO& interp [[buffer(2)]], + device const FillEvaluatedPropsUBO& props [[buffer(3)]]) { #if defined(HAS_UNIFORM_u_pattern_from) const auto pattern_from = tileProps.pattern_from; #else @@ -469,9 +449,9 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const FillOutlinePatternDrawableUBO& drawable [[buffer(4)]], - device const FillOutlinePatternTilePropsUBO& tileProps [[buffer(5)]], - device const FillOutlinePatternEvaluatedPropsUBO& props [[buffer(6)]], + device const FillOutlinePatternDrawableUBO& drawable [[buffer(0)]], + device const FillOutlinePatternTilePropsUBO& tileProps [[buffer(1)]], + device const FillEvaluatedPropsUBO& props [[buffer(3)]], texture2d image0 [[texture(0)]], sampler image0_sampler [[sampler(0)]]) { #if defined(OVERDRAW_INSPECTOR) @@ -524,15 +504,15 @@ struct ShaderSource uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array uniforms; static const std::array textures; static constexpr auto source = R"( struct VertexStage { - short2 pos_normal [[attribute(0)]]; - uchar4 data [[attribute(1)]]; + short2 pos_normal [[attribute(4)]]; + uchar4 data [[attribute(5)]]; }; struct FragmentStage { @@ -549,16 +529,9 @@ struct alignas(16) FillOutlineTriangulatedDrawableUBO { float pad; }; -struct alignas(16) FillOutlineTriangulatedPropertiesUBO { - float4 color; - float opacity; - float width; - float pad1, pad2; -}; - FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const FillOutlineTriangulatedDrawableUBO& drawable [[buffer(2)]], - device const FillOutlineTriangulatedPropertiesUBO& props [[buffer(3)]]) { + device const FillOutlineTriangulatedDrawableUBO& drawable [[buffer(0)]], + device const FillEvaluatedPropsUBO& props [[buffer(3)]]) { // the distance over which the line edge fades out. // Retina devices need a smaller distance to avoid aliasing. @@ -595,7 +568,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const FillOutlineTriangulatedPropertiesUBO& props [[buffer(3)]]) { + device const FillEvaluatedPropsUBO& props [[buffer(3)]]) { // Calculate the distance of the pixel from the line in pixels. const float dist = length(in.normal) * in.width2; @@ -605,7 +578,7 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], const float blur2 = (1.0 / DEVICE_PIXEL_RATIO) * in.gamma_scale; const float alpha = clamp(min(dist + blur2, in.width2 - dist) / blur2, 0.0, 1.0); - return half4(props.color * (alpha * props.opacity)); + return half4(props.outline_color * (alpha * props.opacity)); } )"; }; diff --git a/include/mbgl/shaders/mtl/fill_extrusion.hpp b/include/mbgl/shaders/mtl/fill_extrusion.hpp index 48e76079e..191e0aff0 100644 --- a/include/mbgl/shaders/mtl/fill_extrusion.hpp +++ b/include/mbgl/shaders/mtl/fill_extrusion.hpp @@ -14,61 +14,24 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array uniforms; static const std::array textures; static constexpr auto source = R"( -struct alignas(16) FillExtrusionInterpolateUBO { - /* 0 */ float base_t; - /* 4 */ float height_t; - /* 8 */ float color_t; - /* 12 */ float pattern_from_t; - /* 16 */ float pattern_to_t; - /* 20 */ float pad1, pad2, pad3; - /* 32 */ -}; -static_assert(sizeof(FillExtrusionInterpolateUBO) == 2 * 16, "unexpected padding"); - -struct alignas(16) FillExtrusionDrawableUBO { - /* 0 */ float4x4 matrix; - /* 64 */ float4 scale; - /* 80 */ float2 texsize; - /* 88 */ float2 pixel_coord_upper; - /* 96 */ float2 pixel_coord_lower; - /* 104 */ float height_factor; - /* 108 */ float pad; - /* 112 */ -}; -static_assert(sizeof(FillExtrusionDrawableUBO) == 7 * 16, "unexpected padding"); - -struct alignas(16) FillExtrusionDrawablePropsUBO { - /* 0 */ float4 color; - /* 16 */ float4 light_color_pad; - /* 32 */ float4 light_position_base; - /* 48 */ float height; - /* 52 */ float light_intensity; - /* 56 */ float vertical_gradient; - /* 60 */ float opacity; - /* 64 */ float fade; - /* 68 */ float pad2, pad3, pad4; - /* 80 */ -}; -static_assert(sizeof(FillExtrusionDrawablePropsUBO) == 5 * 16, "unexpected padding"); - struct VertexStage { - short2 pos [[attribute(0)]]; - short4 normal_ed [[attribute(1)]]; + short2 pos [[attribute(4)]]; + short4 normal_ed [[attribute(5)]]; #if !defined(HAS_UNIFORM_u_color) - float4 color [[attribute(2)]]; + float4 color [[attribute(6)]]; #endif #if !defined(HAS_UNIFORM_u_base) - float base [[attribute(3)]]; + float base [[attribute(7)]]; #endif #if !defined(HAS_UNIFORM_u_height) - float height [[attribute(4)]]; + float height [[attribute(8)]]; #endif }; @@ -83,9 +46,9 @@ struct FragmentOutput { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const FillExtrusionDrawableUBO& fill [[buffer(5)]], - device const FillExtrusionDrawablePropsUBO& props [[buffer(6)]], - device const FillExtrusionInterpolateUBO& interp [[buffer(7)]]) { + device const FillExtrusionDrawableUBO& fill [[buffer(0)]], + device const FillExtrusionPropsUBO& props [[buffer(1)]], + device const FillExtrusionInterpolateUBO& interp [[buffer(3)]]) { #if defined(HAS_UNIFORM_u_base) const auto base = props.light_position_base.w; diff --git a/include/mbgl/shaders/mtl/fill_extrusion_pattern.hpp b/include/mbgl/shaders/mtl/fill_extrusion_pattern.hpp index ae7d125aa..bb61f9c25 100644 --- a/include/mbgl/shaders/mtl/fill_extrusion_pattern.hpp +++ b/include/mbgl/shaders/mtl/fill_extrusion_pattern.hpp @@ -14,70 +14,27 @@ struct ShaderSource uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array uniforms; static const std::array textures; static constexpr auto source = R"( -struct alignas(16) FillExtrusionDrawableTilePropsUBO { - /* 0 */ float4 pattern_from; - /* 16 */ float4 pattern_to; - /* 32 */ -}; - -struct alignas(16) FillExtrusionInterpolateUBO { - /* 0 */ float base_t; - /* 4 */ float height_t; - /* 8 */ float color_t; - /* 12 */ float pattern_from_t; - /* 16 */ float pattern_to_t; - /* 20 */ float pad1, pad2, pad3; - /* 32 */ -}; -static_assert(sizeof(FillExtrusionInterpolateUBO) == 2 * 16, "unexpected padding"); - -struct alignas(16) FillExtrusionDrawableUBO { - /* 0 */ float4x4 matrix; - /* 64 */ float4 scale; - /* 80 */ float2 texsize; - /* 88 */ float2 pixel_coord_upper; - /* 96 */ float2 pixel_coord_lower; - /* 104 */ float height_factor; - /* 108 */ float pad; - /* 112 */ -}; -static_assert(sizeof(FillExtrusionDrawableUBO) == 7 * 16, "unexpected padding"); - -struct alignas(16) FillExtrusionDrawablePropsUBO { - /* 0 */ float4 color; - /* 16 */ float4 light_color_pad; - /* 32 */ float4 light_position_base; - /* 48 */ float height; - /* 52 */ float light_intensity; - /* 56 */ float vertical_gradient; - /* 60 */ float opacity; - /* 64 */ float fade; - /* 68 */ float pad2, pad3, pad4; - /* 80 */ -}; -static_assert(sizeof(FillExtrusionDrawablePropsUBO) == 5 * 16, "unexpected padding"); - struct VertexStage { - short2 pos [[attribute(0)]]; - short4 normal_ed [[attribute(1)]]; + short2 pos [[attribute(4)]]; + short4 normal_ed [[attribute(5)]]; #if !defined(HAS_UNIFORM_u_base) - float base [[attribute(2)]]; + float base [[attribute(6)]]; #endif #if !defined(HAS_UNIFORM_u_height) - float height [[attribute(3)]]; + float height [[attribute(7)]]; #endif #if !defined(HAS_UNIFORM_u_pattern_from) - ushort4 pattern_from [[attribute(4)]]; + ushort4 pattern_from [[attribute(8)]]; #endif #if !defined(HAS_UNIFORM_u_pattern_to) - ushort4 pattern_to [[attribute(5)]]; + ushort4 pattern_to [[attribute(9)]]; #endif }; @@ -101,10 +58,10 @@ struct FragmentOutput { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const FillExtrusionDrawableUBO& fill [[buffer(6)]], - device const FillExtrusionDrawablePropsUBO& props [[buffer(7)]], - device const FillExtrusionDrawableTilePropsUBO& tileProps [[buffer(8)]], - device const FillExtrusionInterpolateUBO& interp [[buffer(9)]]) { + device const FillExtrusionDrawableUBO& fill [[buffer(0)]], + device const FillExtrusionPropsUBO& props [[buffer(1)]], + device const FillExtrusionTilePropsUBO& tileProps [[buffer(2)]], + device const FillExtrusionInterpolateUBO& interp [[buffer(3)]]) { #if defined(HAS_UNIFORM_u_base) const auto base = props.light_position_base.w; @@ -192,9 +149,9 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } fragment FragmentOutput fragmentMain(FragmentStage in [[stage_in]], - device const FillExtrusionDrawableUBO& fill [[buffer(6)]], - device const FillExtrusionDrawablePropsUBO& props [[buffer(7)]], - device const FillExtrusionDrawableTilePropsUBO& tileProps [[buffer(8)]], + device const FillExtrusionDrawableUBO& fill [[buffer(0)]], + device const FillExtrusionPropsUBO& props [[buffer(1)]], + device const FillExtrusionTilePropsUBO& tileProps [[buffer(2)]], texture2d image0 [[texture(0)]], sampler image0_sampler [[sampler(0)]]) { #if defined(OVERDRAW_INSPECTOR) diff --git a/include/mbgl/shaders/mtl/heatmap.hpp b/include/mbgl/shaders/mtl/heatmap.hpp index 5ac4d6c88..8bd7feb4d 100644 --- a/include/mbgl/shaders/mtl/heatmap.hpp +++ b/include/mbgl/shaders/mtl/heatmap.hpp @@ -14,21 +14,21 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array uniforms; static const std::array textures; static constexpr auto source = R"( struct VertexStage { - short2 pos [[attribute(0)]]; + short2 pos [[attribute(3)]]; #if !defined(HAS_UNIFORM_u_weight) - float2 weight [[attribute(1)]]; + float2 weight [[attribute(4)]]; #endif #if !defined(HAS_UNIFORM_u_radius) - float2 radius [[attribute(2)]]; + float2 radius [[attribute(5)]]; #endif }; @@ -67,9 +67,9 @@ constant const float ZERO = 1.0 / 255.0 / 16.0; #define GAUSS_COEF 0.3989422804014327 FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const HeatmapDrawableUBO& drawable [[buffer(3)]], - device const HeatmapEvaluatedPropsUBO& props [[buffer(4)]], - device const HeatmapInterpolateUBO& interp [[buffer(5)]]) { + device const HeatmapDrawableUBO& drawable [[buffer(0)]], + device const HeatmapEvaluatedPropsUBO& props [[buffer(1)]], + device const HeatmapInterpolateUBO& interp [[buffer(2)]]) { #if defined(HAS_UNIFORM_u_weight) const auto weight = props.weight; @@ -117,7 +117,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const HeatmapEvaluatedPropsUBO& props [[buffer(4)]]) { + device const HeatmapEvaluatedPropsUBO& props [[buffer(1)]]) { #if defined(OVERDRAW_INSPECTOR) return half4(1.0); #endif diff --git a/include/mbgl/shaders/mtl/heatmap_texture.hpp b/include/mbgl/shaders/mtl/heatmap_texture.hpp index 05cfeafd5..4446ed215 100644 --- a/include/mbgl/shaders/mtl/heatmap_texture.hpp +++ b/include/mbgl/shaders/mtl/heatmap_texture.hpp @@ -14,15 +14,15 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array uniforms; static const std::array textures; static constexpr auto source = R"( struct VertexStage { - short2 pos [[attribute(0)]]; + short2 pos [[attribute(1)]]; }; struct FragmentStage { @@ -30,7 +30,7 @@ struct FragmentStage { float2 pos; }; -struct alignas(16) HeatmapTextureDrawableUBO { +struct alignas(16) HeatmapTexturePropsUBO { float4x4 matrix; float2 world; float opacity; @@ -39,10 +39,10 @@ struct alignas(16) HeatmapTextureDrawableUBO { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const HeatmapTextureDrawableUBO& drawable [[buffer(1)]]) { + device const HeatmapTexturePropsUBO& props [[buffer(0)]]) { const float2 pos = float2(vertx.pos); - const float4 position = drawable.matrix * float4(pos * drawable.world, 0, 1); + const float4 position = props.matrix * float4(pos * props.world, 0, 1); return { .position = position, @@ -51,7 +51,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const HeatmapTextureDrawableUBO& drawable [[buffer(1)]], + device const HeatmapTexturePropsUBO& props [[buffer(0)]], texture2d image [[texture(0)]], texture2d color_ramp [[texture(1)]], sampler image_sampler [[sampler(0)]], @@ -63,7 +63,7 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], float t = image.sample(image_sampler, in.pos).r; float4 color = color_ramp.sample(color_ramp_sampler, float2(t, 0.5)); - return half4(color * drawable.opacity); + return half4(color * props.opacity); } )"; }; diff --git a/include/mbgl/shaders/mtl/hillshade.hpp b/include/mbgl/shaders/mtl/hillshade.hpp index 7d784a6ef..d42414a4f 100644 --- a/include/mbgl/shaders/mtl/hillshade.hpp +++ b/include/mbgl/shaders/mtl/hillshade.hpp @@ -14,16 +14,16 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array uniforms; static const std::array textures; static constexpr auto source = R"( struct VertexStage { - short2 pos [[attribute(0)]]; - short2 texture_pos [[attribute(1)]]; + short2 pos [[attribute(2)]]; + short2 texture_pos [[attribute(3)]]; }; struct FragmentStage { @@ -44,7 +44,7 @@ struct alignas(16) HillshadeEvaluatedPropsUBO { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const HillshadeDrawableUBO& drawable [[buffer(2)]]) { + device const HillshadeDrawableUBO& drawable [[buffer(0)]]) { const float4 position = drawable.matrix * float4(float2(vertx.pos), 0, 1); float2 pos = float2(vertx.texture_pos) / 8192.0; @@ -57,8 +57,8 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const HillshadeDrawableUBO& drawable [[buffer(2)]], - device const HillshadeEvaluatedPropsUBO& props [[buffer(3)]], + device const HillshadeDrawableUBO& drawable [[buffer(0)]], + device const HillshadeEvaluatedPropsUBO& props [[buffer(1)]], texture2d image [[texture(0)]], sampler image_sampler [[sampler(0)]]) { #if defined(OVERDRAW_INSPECTOR) diff --git a/include/mbgl/shaders/mtl/hillshade_prepare.hpp b/include/mbgl/shaders/mtl/hillshade_prepare.hpp index 6024eaef0..107640a8a 100644 --- a/include/mbgl/shaders/mtl/hillshade_prepare.hpp +++ b/include/mbgl/shaders/mtl/hillshade_prepare.hpp @@ -14,15 +14,15 @@ struct ShaderSource static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array uniforms; static const std::array textures; static constexpr auto source = R"( struct VertexStage { - short2 pos [[attribute(0)]]; - short2 texture_pos [[attribute(1)]]; + short2 pos [[attribute(1)]]; + short2 texture_pos [[attribute(2)]]; }; struct FragmentStage { @@ -39,7 +39,7 @@ struct alignas(16) HillshadePrepareDrawableUBO { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const HillshadePrepareDrawableUBO& drawable [[buffer(2)]]) { + device const HillshadePrepareDrawableUBO& drawable [[buffer(0)]]) { const float4 position = drawable.matrix * float4(float2(vertx.pos), 0, 1); @@ -61,7 +61,7 @@ float getElevation(float2 coord, float bias, texture2d im } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const HillshadePrepareDrawableUBO& drawable [[buffer(2)]], + device const HillshadePrepareDrawableUBO& drawable [[buffer(0)]], texture2d image [[texture(0)]], sampler image_sampler [[sampler(0)]]) { #if defined(OVERDRAW_INSPECTOR) diff --git a/include/mbgl/shaders/mtl/line.hpp b/include/mbgl/shaders/mtl/line.hpp index 302260569..9e345842a 100644 --- a/include/mbgl/shaders/mtl/line.hpp +++ b/include/mbgl/shaders/mtl/line.hpp @@ -14,33 +14,33 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array uniforms; static const std::array textures; static constexpr auto source = R"( struct VertexStage { - short2 pos_normal [[attribute(0)]]; - uchar4 data [[attribute(1)]]; + short2 pos_normal [[attribute(5)]]; + uchar4 data [[attribute(6)]]; #if !defined(HAS_UNIFORM_u_color) - float4 color [[attribute(2)]]; + float4 color [[attribute(7)]]; #endif #if !defined(HAS_UNIFORM_u_blur) - float2 blur [[attribute(3)]]; + float2 blur [[attribute(8)]]; #endif #if !defined(HAS_UNIFORM_u_opacity) - float2 opacity [[attribute(4)]]; + float2 opacity [[attribute(9)]]; #endif #if !defined(HAS_UNIFORM_u_gapwidth) - float2 gapwidth [[attribute(5)]]; + float2 gapwidth [[attribute(10)]]; #endif #if !defined(HAS_UNIFORM_u_offset) - float2 offset [[attribute(6)]]; + float2 offset [[attribute(11)]]; #endif #if !defined(HAS_UNIFORM_u_width) - float2 width [[attribute(7)]]; + float2 width [[attribute(12)]]; #endif }; @@ -61,11 +61,27 @@ struct FragmentStage { #endif }; +struct alignas(16) LineDrawableUBO { + float4x4 matrix; + float ratio; + float pad1, pad2, pad3; +}; + +struct alignas(16) LineInterpolationUBO { + float color_t; + float blur_t; + float opacity_t; + float gapwidth_t; + float offset_t; + float width_t; + float pad1, pad2; +}; + FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const LineDynamicUBO& dynamic [[buffer(8)]], - device const LineUBO& line [[buffer(9)]], - device const LinePropertiesUBO& props [[buffer(10)]], - device const LineInterpolationUBO& interp [[buffer(11)]]) { + device const LineDynamicUBO& dynamic [[buffer(0)]], + device const LineDrawableUBO& drawable [[buffer(1)]], + device const LineInterpolationUBO& interp [[buffer(2)]], + device const LineEvaluatedPropsUBO& props [[buffer(4)]]) { #if defined(HAS_UNIFORM_u_gapwidth) const auto gapwidth = props.gapwidth / 2; @@ -112,8 +128,8 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], const float t = 1.0 - abs(u); const float2 offset2 = offset * a_extrude * LINE_NORMAL_SCALE * v_normal.y * float2x2(t, -u, u, t); - const float4 projected_extrude = line.matrix * float4(dist / line.ratio, 0.0, 0.0); - const float4 position = line.matrix * float4(pos + offset2 / line.ratio, 0.0, 1.0) + projected_extrude; + const float4 projected_extrude = drawable.matrix * float4(dist / drawable.ratio, 0.0, 0.0); + const float4 position = drawable.matrix * float4(pos + offset2 / drawable.ratio, 0.0, 1.0) + projected_extrude; // calculate how much the perspective view squishes or stretches the extrude const float extrude_length_without_perspective = length(dist); @@ -138,8 +154,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const LineUBO& line [[buffer(9)]], - device const LinePropertiesUBO& props [[buffer(10)]]) { + device const LineEvaluatedPropsUBO& props [[buffer(4)]]) { #if defined(OVERDRAW_INSPECTOR) return half4(1.0); #endif @@ -173,42 +188,211 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], )"; }; +template <> +struct ShaderSource { + static constexpr auto name = "LineGradientShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array uniforms; + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = R"( +struct VertexStage { + short2 pos_normal [[attribute(5)]]; + uchar4 data [[attribute(6)]]; + float2 blur [[attribute(7)]]; + float2 opacity [[attribute(8)]]; + float2 gapwidth [[attribute(9)]]; + float2 offset [[attribute(10)]]; + float2 width [[attribute(11)]]; +}; + +struct FragmentStage { + float4 position [[position, invariant]]; + float2 width2; + half2 normal; + half gamma_scale; + float lineprogress; + +#if !defined(HAS_UNIFORM_u_blur) + half blur; +#endif +#if !defined(HAS_UNIFORM_u_opacity) + half opacity; +#endif +}; + +struct alignas(16) LineGradientDrawableUBO { + float4x4 matrix; + float ratio; + float pad1, pad2, pad3; +}; + +struct alignas(16) LineGradientInterpolationUBO { + float blur_t; + float opacity_t; + float gapwidth_t; + float offset_t; + float width_t; + float pad1, pad2, pad3; +}; + +FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], + device const LineDynamicUBO& dynamic [[buffer(0)]], + device const LineGradientDrawableUBO& drawable [[buffer(1)]], + device const LineGradientInterpolationUBO& interp [[buffer(2)]], + device const LineEvaluatedPropsUBO& props [[buffer(4)]]) { + +#if !defined(HAS_UNIFORM_u_blur) + const auto blur = unpack_mix_float(vertx.blur, interp.blur_t); +#endif +#if !defined(HAS_UNIFORM_u_opacity) + const auto opacity = unpack_mix_float(vertx.opacity, interp.opacity_t); +#endif +#if defined(HAS_UNIFORM_u_gapwidth) + const auto gapwidth = props.gapwidth; +#else + const auto gapwidth = unpack_mix_float(vertx.gapwidth, interp.gapwidth_t) / 2; +#endif +#if defined(HAS_UNIFORM_u_offset) + const auto offset = props.offset; +#else + const auto offset = unpack_mix_float(vertx.offset, interp.offset_t) * -1; +#endif +#if defined(HAS_UNIFORM_u_width) + const auto width = props.width; +#else + const auto width = unpack_mix_float(vertx.width, interp.width_t); +#endif + + // the distance over which the line edge fades out. + // Retina devices need a smaller distance to avoid aliasing. + const float ANTIALIASING = 1.0 / DEVICE_PIXEL_RATIO / 2.0; + + const float2 a_extrude = float2(vertx.data.xy) - 128.0; + const float a_direction = fmod(float(vertx.data.z), 4.0) - 1.0; + const float v_lineprogress = (floor(float(vertx.data.z) / 4.0) + vertx.data.w * 64.0) * 2.0 / MAX_LINE_DISTANCE; + const float2 pos = floor(float2(vertx.pos_normal) * 0.5); + + // x is 1 if it's a round cap, 0 otherwise + // y is 1 if the normal points up, and -1 if it points down + // We store these in the least significant bit of a_pos_normal + const float2 normal = float2(vertx.pos_normal) - 2.0 * pos; + const float2 v_normal = float2(normal.x, normal.y * 2.0 - 1.0); + + const float halfwidth = width / 2.0; + const float inset = gapwidth + (gapwidth > 0.0 ? ANTIALIASING : 0.0); + const float outset = gapwidth + halfwidth * (gapwidth > 0.0 ? 2.0 : 1.0) + (halfwidth == 0.0 ? 0.0 : ANTIALIASING); + + // Scale the extrusion vector down to a normal and then up by the line width of this vertex. + const float2 dist = outset * a_extrude * LINE_NORMAL_SCALE; + + // Calculate the offset when drawing a line that is to the side of the actual line. + // We do this by creating a vector that points towards the extrude, but rotate + // it when we're drawing round end points (a_direction = -1 or 1) since their + // extrude vector points in another direction. + const float u = 0.5 * a_direction; + const float t = 1.0 - abs(u); + const float2 offset2 = offset * a_extrude * LINE_NORMAL_SCALE * v_normal.y * float2x2(t, -u, u, t); + + const float4 projected_extrude = drawable.matrix * float4(dist / drawable.ratio, 0.0, 0.0); + const float4 position = drawable.matrix * float4(pos + offset2 / drawable.ratio, 0.0, 1.0) + projected_extrude; + + // calculate how much the perspective view squishes or stretches the extrude + const float extrude_length_without_perspective = length(dist); + const float extrude_length_with_perspective = length(projected_extrude.xy / position.w * dynamic.units_to_pixels); + + return { + .position = position, + .width2 = float2(outset, inset), + .normal = half2(v_normal), + .gamma_scale = half(extrude_length_without_perspective / extrude_length_with_perspective), + .lineprogress = v_lineprogress, + +#if !defined(HAS_UNIFORM_u_blur) + .blur = half(blur), +#endif +#if !defined(HAS_UNIFORM_u_opacity) + .opacity = half(opacity), +#endif + }; +} + +half4 fragment fragmentMain(FragmentStage in [[stage_in]], + device const LineEvaluatedPropsUBO& props [[buffer(4)]], + texture2d gradientTexture [[texture(0)]]) { +#if defined(OVERDRAW_INSPECTOR) + return half4(1.0); +#endif + +#if defined(HAS_UNIFORM_u_blur) + const float blur = props.blur; +#else + const float blur = float(in.blur); +#endif +#if defined(HAS_UNIFORM_u_opacity) + const float opacity = props.opacity; +#else + const float opacity = float(in.opacity); +#endif + + // Calculate the distance of the pixel from the line in pixels. + const float dist = length(in.normal) * in.width2.x; + + // Calculate the antialiasing fade factor. This is either when fading in the + // line in case of an offset line (v_width2.y) or when fading out (v_width2.x) + const float blur2 = (blur + 1.0 / DEVICE_PIXEL_RATIO) * in.gamma_scale; + const float alpha = clamp(min(dist - (in.width2.y - blur2), in.width2.x - dist) / blur2, 0.0, 1.0); + + // For gradient lines, v_lineprogress is the ratio along the entire line, + // scaled to [0, 2^15), and the gradient ramp is stored in a texture. + constexpr sampler sampler2d(coord::normalized, filter::linear); + const float4 color = gradientTexture.sample(sampler2d, float2(in.lineprogress, 0.5)); + + return half4(color * (alpha * opacity)); +} +)"; +}; + template <> struct ShaderSource { static constexpr auto name = "LinePatternShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array uniforms; static const std::array textures; static constexpr auto source = R"( struct VertexStage { - short2 pos_normal [[attribute(0)]]; - uchar4 data [[attribute(1)]]; + short2 pos_normal [[attribute(5)]]; + uchar4 data [[attribute(6)]]; #if !defined(HAS_UNIFORM_u_blur) - float2 blur [[attribute(2)]]; + float2 blur [[attribute(7)]]; #endif #if !defined(HAS_UNIFORM_u_opacity) - float2 opacity [[attribute(3)]]; + float2 opacity [[attribute(8)]]; #endif #if !defined(HAS_UNIFORM_u_gapwidth) - float2 gapwidth [[attribute(4)]]; + float2 gapwidth [[attribute(9)]]; #endif #if !defined(HAS_UNIFORM_u_offset) - float2 offset [[attribute(5)]]; + float2 offset [[attribute(10)]]; #endif #if !defined(HAS_UNIFORM_u_width) - float2 width [[attribute(6)]]; + float2 width [[attribute(11)]]; #endif #if !defined(HAS_UNIFORM_u_pattern_from) - ushort4 pattern_from [[attribute(7)]]; + ushort4 pattern_from [[attribute(12)]]; #endif #if !defined(HAS_UNIFORM_u_pattern_to) - ushort4 pattern_to [[attribute(8)]]; + ushort4 pattern_to [[attribute(13)]]; #endif }; @@ -233,7 +417,7 @@ struct FragmentStage { #endif }; -struct alignas(16) LinePatternUBO { +struct alignas(16) LinePatternDrawableUBO { float4x4 matrix; float4 scale; float2 texsize; @@ -241,15 +425,6 @@ struct alignas(16) LinePatternUBO { float fade; }; -struct alignas(16) LinePatternPropertiesUBO { - float blur; - float opacity; - float offset; - float gapwidth; - float width; - float pad1, pad2, pad3; -}; - struct alignas(16) LinePatternInterpolationUBO { float blur_t; float opacity_t; @@ -267,11 +442,11 @@ struct alignas(16) LinePatternTilePropertiesUBO { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const LineDynamicUBO& dynamic [[buffer(9)]], - device const LinePatternUBO& line [[buffer(10)]], - device const LinePatternPropertiesUBO& props [[buffer(11)]], - device const LinePatternInterpolationUBO& interp [[buffer(12)]], - device const LinePatternTilePropertiesUBO& tileProps [[buffer(13)]]) { + device const LineDynamicUBO& dynamic [[buffer(0)]], + device const LinePatternDrawableUBO& drawable [[buffer(1)]], + device const LinePatternInterpolationUBO& interp [[buffer(2)]], + device const LinePatternTilePropertiesUBO& tileProps [[buffer(3)]], + device const LineEvaluatedPropsUBO& props [[buffer(4)]]) { #if defined(HAS_UNIFORM_u_gapwidth) const auto gapwidth = props.gapwidth / 2; @@ -320,8 +495,8 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], const float t = 1.0 - abs(u); const float2 offset2 = offset * a_extrude * LINE_NORMAL_SCALE * v_normal.y * float2x2(t, -u, u, t); - const float4 projected_extrude = line.matrix * float4(dist / line.ratio, 0.0, 0.0); - const float4 position = line.matrix * float4(pos + offset2 / line.ratio, 0.0, 1.0) + projected_extrude; + const float4 projected_extrude = drawable.matrix * float4(dist / drawable.ratio, 0.0, 0.0); + const float4 position = drawable.matrix * float4(pos + offset2 / drawable.ratio, 0.0, 1.0) + projected_extrude; // calculate how much the perspective view squishes or stretches the extrude const float extrude_length_without_perspective = length(dist); @@ -350,9 +525,9 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const LinePatternUBO& line [[buffer(10)]], - device const LinePatternPropertiesUBO& props [[buffer(11)]], - device const LinePatternTilePropertiesUBO& tileProps [[buffer(13)]], + device const LinePatternDrawableUBO& drawable [[buffer(1)]], + device const LinePatternTilePropertiesUBO& tileProps [[buffer(3)]], + device const LineEvaluatedPropsUBO& props [[buffer(4)]], texture2d image0 [[texture(0)]], sampler image0_sampler [[sampler(0)]]) { #if defined(OVERDRAW_INSPECTOR) @@ -385,10 +560,10 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], const float2 pattern_tl_b = pattern_to.xy; const float2 pattern_br_b = pattern_to.zw; - const float pixelRatio = line.scale.x; - const float tileZoomRatio = line.scale.y; - const float fromScale = line.scale.z; - const float toScale = line.scale.w; + const float pixelRatio = drawable.scale.x; + const float tileZoomRatio = drawable.scale.y; + const float fromScale = drawable.scale.z; + const float toScale = drawable.scale.w; const float2 display_size_a = float2((pattern_br_a.x - pattern_tl_a.x) / pixelRatio, (pattern_br_a.y - pattern_tl_a.y) / pixelRatio); const float2 display_size_b = float2((pattern_br_b.x - pattern_tl_b.x) / pixelRatio, (pattern_br_b.y - pattern_tl_b.y) / pixelRatio); @@ -415,10 +590,10 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], // the texture coordinate const float y_a = 0.5 + (in.normal.y * clamp(in.width2.x, 0.0, (pattern_size_a.y + 2.0) / 2.0) / pattern_size_a.y); const float y_b = 0.5 + (in.normal.y * clamp(in.width2.x, 0.0, (pattern_size_b.y + 2.0) / 2.0) / pattern_size_b.y); - const float2 pos_a = mix(pattern_tl_a / line.texsize, pattern_br_a / line.texsize, float2(x_a, y_a)); - const float2 pos_b = mix(pattern_tl_b / line.texsize, pattern_br_b / line.texsize, float2(x_b, y_b)); + const float2 pos_a = mix(pattern_tl_a / drawable.texsize, pattern_br_a / drawable.texsize, float2(x_a, y_a)); + const float2 pos_b = mix(pattern_tl_b / drawable.texsize, pattern_br_b / drawable.texsize, float2(x_b, y_b)); - const float4 color = mix(image0.sample(image0_sampler, pos_a), image0.sample(image0_sampler, pos_b), line.fade); + const float4 color = mix(image0.sample(image0_sampler, pos_a), image0.sample(image0_sampler, pos_b), drawable.fade); return half4(color * alpha * opacity); } @@ -431,36 +606,36 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array uniforms; static const std::array textures; static constexpr auto source = R"( struct VertexStage { - short2 pos_normal [[attribute(0)]]; - uchar4 data [[attribute(1)]]; + short2 pos_normal [[attribute(5)]]; + uchar4 data [[attribute(6)]]; #if !defined(HAS_UNIFORM_u_color) - float4 color [[attribute(2)]]; + float4 color [[attribute(7)]]; #endif #if !defined(HAS_UNIFORM_u_blur) - float2 blur [[attribute(3)]]; + float2 blur [[attribute(8)]]; #endif #if !defined(HAS_UNIFORM_u_opacity) - float2 opacity [[attribute(4)]]; + float2 opacity [[attribute(9)]]; #endif #if !defined(HAS_UNIFORM_u_gapwidth) - float2 gapwidth [[attribute(5)]]; + float2 gapwidth [[attribute(10)]]; #endif #if !defined(HAS_UNIFORM_u_offset) - float2 offset [[attribute(6)]]; + float2 offset [[attribute(11)]]; #endif #if !defined(HAS_UNIFORM_u_width) - float2 width [[attribute(7)]]; + float2 width [[attribute(12)]]; #endif #if !defined(HAS_UNIFORM_u_floorwidth) - float2 floorwidth [[attribute(8)]]; + float2 floorwidth [[attribute(13)]]; #endif }; @@ -486,7 +661,7 @@ struct FragmentStage { #endif }; -struct alignas(16) LineSDFUBO { +struct alignas(16) LineSDFDrawableUBO { float4x4 matrix; float2 patternscale_a; float2 patternscale_b; @@ -498,17 +673,6 @@ struct alignas(16) LineSDFUBO { float pad1, pad2, pad3; }; -struct alignas(16) LineSDFPropertiesUBO { - float4 color; - float blur; - float opacity; - float gapwidth; - float offset; - float width; - float floorwidth; - float pad1, pad2; -}; - struct alignas(16) LineSDFInterpolationUBO { float color_t; float blur_t; @@ -521,10 +685,10 @@ struct alignas(16) LineSDFInterpolationUBO { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const LineDynamicUBO& dynamic [[buffer(9)]], - device const LineSDFUBO& line [[buffer(10)]], - device const LineSDFPropertiesUBO& props [[buffer(11)]], - device const LineSDFInterpolationUBO& interp [[buffer(12)]]) { + device const LineDynamicUBO& dynamic [[buffer(0)]], + device const LineSDFDrawableUBO& drawable [[buffer(1)]], + device const LineSDFInterpolationUBO& interp [[buffer(2)]], + device const LineEvaluatedPropsUBO& props [[buffer(4)]]) { #if defined(HAS_UNIFORM_u_gapwidth) const auto gapwidth = props.gapwidth / 2; @@ -578,8 +742,8 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], const float t = 1.0 - abs(u); const float2 offset2 = offset * a_extrude * LINE_NORMAL_SCALE * v_normal.y * float2x2(t, -u, u, t); - const float4 projected_extrude = line.matrix * float4(dist / line.ratio, 0.0, 0.0); - const float4 position = line.matrix * float4(pos + offset2 / line.ratio, 0.0, 1.0) + projected_extrude; + const float4 projected_extrude = drawable.matrix * float4(dist / drawable.ratio, 0.0, 0.0); + const float4 position = drawable.matrix * float4(pos + offset2 / drawable.ratio, 0.0, 1.0) + projected_extrude; // calculate how much the perspective view squishes or stretches the extrude const float extrude_length_without_perspective = length(dist); @@ -590,8 +754,8 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], .width2 = float2(outset, inset), .normal = v_normal, .gamma_scale = half(extrude_length_without_perspective / extrude_length_with_perspective), - .tex_a = float2(linesofar * line.patternscale_a.x / floorwidth, (normal.y * line.patternscale_a.y + line.tex_y_a) * 2.0), - .tex_b = float2(linesofar * line.patternscale_b.x / floorwidth, (normal.y * line.patternscale_b.y + line.tex_y_b) * 2.0), + .tex_a = float2(linesofar * drawable.patternscale_a.x / floorwidth, (normal.y * drawable.patternscale_a.y + drawable.tex_y_a) * 2.0), + .tex_b = float2(linesofar * drawable.patternscale_b.x / floorwidth, (normal.y * drawable.patternscale_b.y + drawable.tex_y_b) * 2.0), #if !defined(HAS_UNIFORM_u_color) .color = unpack_mix_color(vertx.color, interp.color_t), @@ -609,8 +773,8 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const LineSDFUBO& line [[buffer(10)]], - device const LineSDFPropertiesUBO& props [[buffer(11)]], + device const LineSDFDrawableUBO& drawable [[buffer(1)]], + device const LineEvaluatedPropsUBO& props [[buffer(4)]], texture2d image0 [[texture(0)]], sampler image0_sampler [[sampler(0)]]) { #if defined(OVERDRAW_INSPECTOR) @@ -644,10 +808,10 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], const float sdfdist_a = image0.sample(image0_sampler, in.tex_a).a; const float sdfdist_b = image0.sample(image0_sampler, in.tex_b).a; - const float sdfdist = mix(sdfdist_a, sdfdist_b, line.mix); + const float sdfdist = mix(sdfdist_a, sdfdist_b, drawable.mix); const float dist = length(in.normal) * in.width2.x; const float alpha = clamp(min(dist - (in.width2.y - blur2), in.width2.x - dist) / blur2, 0.0, 1.0) * - smoothstep(0.5 - line.sdfgamma / floorwidth, 0.5 + line.sdfgamma / floorwidth, sdfdist); + smoothstep(0.5 - drawable.sdfgamma / floorwidth, 0.5 + drawable.sdfgamma / floorwidth, sdfdist); return half4(color * (alpha * opacity)); } diff --git a/include/mbgl/shaders/mtl/line_gradient.hpp b/include/mbgl/shaders/mtl/line_gradient.hpp deleted file mode 100644 index 86afc4312..000000000 --- a/include/mbgl/shaders/mtl/line_gradient.hpp +++ /dev/null @@ -1,167 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -namespace mbgl { -namespace shaders { - -template <> -struct ShaderSource { - static constexpr auto name = "LineGradientShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array uniforms; - static const std::array textures; - - static constexpr auto source = R"( -struct VertexStage { - short2 pos_normal [[attribute(0)]]; - uchar4 data [[attribute(1)]]; - float2 blur [[attribute(2)]]; - float2 opacity [[attribute(3)]]; - float2 gapwidth [[attribute(4)]]; - float2 offset [[attribute(5)]]; - float2 width [[attribute(6)]]; -}; - -struct FragmentStage { - float4 position [[position, invariant]]; - float2 width2; - half2 normal; - half gamma_scale; - float lineprogress; - -#if !defined(HAS_UNIFORM_u_blur) - half blur; -#endif -#if !defined(HAS_UNIFORM_u_opacity) - half opacity; -#endif -}; - -FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const LineDynamicUBO& dynamic [[buffer(7)]], - device const LineGradientUBO& line [[buffer(8)]], - device const LineGradientPropertiesUBO& props [[buffer(9)]], - device const LineGradientInterpolationUBO& interp [[buffer(10)]]) { - -#if !defined(HAS_UNIFORM_u_blur) - const auto blur = unpack_mix_float(vertx.blur, interp.blur_t); -#endif -#if !defined(HAS_UNIFORM_u_opacity) - const auto opacity = unpack_mix_float(vertx.opacity, interp.opacity_t); -#endif -#if defined(HAS_UNIFORM_u_gapwidth) - const auto gapwidth = props.gapwidth; -#else - const auto gapwidth = unpack_mix_float(vertx.gapwidth, interp.gapwidth_t) / 2; -#endif -#if defined(HAS_UNIFORM_u_offset) - const auto offset = props.offset; -#else - const auto offset = unpack_mix_float(vertx.offset, interp.offset_t) * -1; -#endif -#if defined(HAS_UNIFORM_u_width) - const auto width = props.width; -#else - const auto width = unpack_mix_float(vertx.width, interp.width_t); -#endif - - // the distance over which the line edge fades out. - // Retina devices need a smaller distance to avoid aliasing. - const float ANTIALIASING = 1.0 / DEVICE_PIXEL_RATIO / 2.0; - - const float2 a_extrude = float2(vertx.data.xy) - 128.0; - const float a_direction = fmod(float(vertx.data.z), 4.0) - 1.0; - const float v_lineprogress = (floor(float(vertx.data.z) / 4.0) + vertx.data.w * 64.0) * 2.0 / MAX_LINE_DISTANCE; - const float2 pos = floor(float2(vertx.pos_normal) * 0.5); - - // x is 1 if it's a round cap, 0 otherwise - // y is 1 if the normal points up, and -1 if it points down - // We store these in the least significant bit of a_pos_normal - const float2 normal = float2(vertx.pos_normal) - 2.0 * pos; - const float2 v_normal = float2(normal.x, normal.y * 2.0 - 1.0); - - const float halfwidth = width / 2.0; - const float inset = gapwidth + (gapwidth > 0.0 ? ANTIALIASING : 0.0); - const float outset = gapwidth + halfwidth * (gapwidth > 0.0 ? 2.0 : 1.0) + (halfwidth == 0.0 ? 0.0 : ANTIALIASING); - - // Scale the extrusion vector down to a normal and then up by the line width of this vertex. - const float2 dist = outset * a_extrude * LINE_NORMAL_SCALE; - - // Calculate the offset when drawing a line that is to the side of the actual line. - // We do this by creating a vector that points towards the extrude, but rotate - // it when we're drawing round end points (a_direction = -1 or 1) since their - // extrude vector points in another direction. - const float u = 0.5 * a_direction; - const float t = 1.0 - abs(u); - const float2 offset2 = offset * a_extrude * LINE_NORMAL_SCALE * v_normal.y * float2x2(t, -u, u, t); - - const float4 projected_extrude = line.matrix * float4(dist / line.ratio, 0.0, 0.0); - const float4 position = line.matrix * float4(pos + offset2 / line.ratio, 0.0, 1.0) + projected_extrude; - - // calculate how much the perspective view squishes or stretches the extrude - const float extrude_length_without_perspective = length(dist); - const float extrude_length_with_perspective = length(projected_extrude.xy / position.w * dynamic.units_to_pixels); - - return { - .position = position, - .width2 = float2(outset, inset), - .normal = half2(v_normal), - .gamma_scale = half(extrude_length_without_perspective / extrude_length_with_perspective), - .lineprogress = v_lineprogress, - -#if !defined(HAS_UNIFORM_u_blur) - .blur = half(blur), -#endif -#if !defined(HAS_UNIFORM_u_opacity) - .opacity = half(opacity), -#endif - }; -} - -half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const LineGradientUBO& line [[buffer(8)]], - device const LineGradientPropertiesUBO& props [[buffer(9)]], - texture2d gradientTexture [[texture(0)]]) { -#if defined(OVERDRAW_INSPECTOR) - return half4(1.0); -#endif - -#if defined(HAS_UNIFORM_u_blur) - const float blur = props.blur; -#else - const float blur = float(in.blur); -#endif -#if defined(HAS_UNIFORM_u_opacity) - const float opacity = props.opacity; -#else - const float opacity = float(in.opacity); -#endif - - // Calculate the distance of the pixel from the line in pixels. - const float dist = length(in.normal) * in.width2.x; - - // Calculate the antialiasing fade factor. This is either when fading in the - // line in case of an offset line (v_width2.y) or when fading out (v_width2.x) - const float blur2 = (blur + 1.0 / DEVICE_PIXEL_RATIO) * in.gamma_scale; - const float alpha = clamp(min(dist - (in.width2.y - blur2), in.width2.x - dist) / blur2, 0.0, 1.0); - - // For gradient lines, v_lineprogress is the ratio along the entire line, - // scaled to [0, 2^15), and the gradient ramp is stored in a texture. - constexpr sampler sampler2d(coord::normalized, filter::linear); - const float4 color = gradientTexture.sample(sampler2d, float2(in.lineprogress, 0.5)); - - return half4(color * (alpha * opacity)); -} -)"; -}; - -} // namespace shaders -} // namespace mbgl diff --git a/include/mbgl/shaders/mtl/raster.hpp b/include/mbgl/shaders/mtl/raster.hpp index 463995069..47d6a24b5 100644 --- a/include/mbgl/shaders/mtl/raster.hpp +++ b/include/mbgl/shaders/mtl/raster.hpp @@ -14,16 +14,16 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array uniforms; static const std::array textures; static constexpr auto source = R"( struct VertexStage { - short2 pos [[attribute(0)]]; - short2 texture_pos [[attribute(1)]]; + short2 pos [[attribute(2)]]; + short2 texture_pos [[attribute(3)]]; }; struct FragmentStage { @@ -34,6 +34,9 @@ struct FragmentStage { struct alignas(16) RasterDrawableUBO { float4x4 matrix; +}; + +struct alignas(16) RasterEvaluatedPropsUBO { float3 spin_weights; float2 tl_parent; float scale_parent; @@ -50,7 +53,8 @@ struct alignas(16) RasterDrawableUBO { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const RasterDrawableUBO& drawable [[buffer(2)]]) { + device const RasterDrawableUBO& drawable [[buffer(0)]], + device const RasterEvaluatedPropsUBO& props [[buffer(1)]]) { const float4 position = drawable.matrix * float4(float2(vertx.pos), 0, 1); @@ -59,8 +63,8 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], // as an arbitrarily high number to preserve adequate precision when rendering. // This is also the same value as the EXTENT we are using for our tile buffer pos coordinates, // so math for modifying either is consistent. - const float2 pos0 = (((float2(vertx.texture_pos) / 8192.0) - 0.5) / drawable.buffer_scale ) + 0.5; - const float2 pos1 = (pos0 * drawable.scale_parent) + drawable.tl_parent; + const float2 pos0 = (((float2(vertx.texture_pos) / 8192.0) - 0.5) / props.buffer_scale ) + 0.5; + const float2 pos1 = (pos0 * props.scale_parent) + props.tl_parent; return { .position = position, @@ -70,7 +74,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const RasterDrawableUBO& drawable [[buffer(2)]], + device const RasterEvaluatedPropsUBO& props [[buffer(1)]], texture2d image0 [[texture(0)]], texture2d image1 [[texture(1)]], sampler image0_sampler [[sampler(0)]], @@ -88,26 +92,26 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], if (color1.a > 0.0) { color1.rgb = color1.rgb / color1.a; } - float4 color = mix(color0, color1, drawable.fade_t); - color.a *= drawable.opacity; + float4 color = mix(color0, color1, props.fade_t); + color.a *= props.opacity; float3 rgb = color.rgb; // spin rgb = float3( - dot(rgb, drawable.spin_weights.xyz), - dot(rgb, drawable.spin_weights.zxy), - dot(rgb, drawable.spin_weights.yzx)); + dot(rgb, props.spin_weights.xyz), + dot(rgb, props.spin_weights.zxy), + dot(rgb, props.spin_weights.yzx)); // saturation float average = (color.r + color.g + color.b) / 3.0; - rgb += (average - rgb) * drawable.saturation_factor; + rgb += (average - rgb) * props.saturation_factor; // contrast - rgb = (rgb - 0.5) * drawable.contrast_factor + 0.5; + rgb = (rgb - 0.5) * props.contrast_factor + 0.5; // brightness - float3 high_vec = float3(drawable.brightness_low, drawable.brightness_low, drawable.brightness_low); - float3 low_vec = float3(drawable.brightness_high, drawable.brightness_high, drawable.brightness_high); + float3 high_vec = float3(props.brightness_low, props.brightness_low, props.brightness_low); + float3 low_vec = float3(props.brightness_high, props.brightness_high, props.brightness_high); return half4(half3(mix(high_vec, low_vec, rgb) * color.a), color.a); } diff --git a/include/mbgl/shaders/mtl/shader_program.hpp b/include/mbgl/shaders/mtl/shader_program.hpp index 5b03e82da..88a37fa63 100644 --- a/include/mbgl/shaders/mtl/shader_program.hpp +++ b/include/mbgl/shaders/mtl/shader_program.hpp @@ -13,18 +13,9 @@ namespace mbgl { namespace shaders { -struct AttributeInfo { - constexpr AttributeInfo(std::size_t index_, gfx::AttributeDataType dataType_, std::size_t id_) - : index(index_), - dataType(dataType_), - id(id_) {} - std::size_t index; - gfx::AttributeDataType dataType; - std::size_t id; -}; struct UniformBlockInfo { - constexpr UniformBlockInfo(std::size_t index_, bool vertex_, bool fragment_, std::size_t size_, std::size_t id_) - : index(index_), + constexpr UniformBlockInfo(bool vertex_, bool fragment_, std::size_t size_, std::size_t id_) + : index(id_), vertex(vertex_), fragment(fragment_), size(size_), @@ -35,6 +26,15 @@ struct UniformBlockInfo { std::size_t size; std::size_t id; }; +struct AttributeInfo { + constexpr AttributeInfo(std::size_t index_, gfx::AttributeDataType dataType_, std::size_t id_) + : index(index_), + dataType(dataType_), + id(id_) {} + std::size_t index; + gfx::AttributeDataType dataType; + std::size_t id; +}; struct TextureInfo { constexpr TextureInfo(std::size_t index_, std::size_t id_) : index(index_), diff --git a/include/mbgl/shaders/mtl/symbol_icon.hpp b/include/mbgl/shaders/mtl/symbol_icon.hpp index 8ac0429c9..3df3edc7d 100644 --- a/include/mbgl/shaders/mtl/symbol_icon.hpp +++ b/include/mbgl/shaders/mtl/symbol_icon.hpp @@ -14,21 +14,21 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array uniforms; static const std::array textures; static constexpr auto source = R"( struct VertexStage { - float4 pos_offset [[attribute(0)]]; - float4 data [[attribute(1)]]; - float4 pixeloffset [[attribute(2)]]; - float3 projected_pos [[attribute(3)]]; - float fade_opacity [[attribute(4)]]; + float4 pos_offset [[attribute(5)]]; + float4 data [[attribute(6)]]; + float4 pixeloffset [[attribute(7)]]; + float3 projected_pos [[attribute(8)]]; + float fade_opacity [[attribute(9)]]; #if !defined(HAS_UNIFORM_u_opacity) - float opacity [[attribute(5)]]; + float opacity [[attribute(10)]]; #endif }; @@ -46,11 +46,11 @@ struct FragmentStage { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const SymbolDrawableUBO& drawable [[buffer(6)]], - device const SymbolDynamicUBO& dynamic [[buffer(7)]], - device const SymbolDrawablePaintUBO& paint [[buffer(8)]], - device const SymbolDrawableTilePropsUBO& props [[buffer(9)]], - device const SymbolDrawableInterpolateUBO& interp [[buffer(10)]]) { + device const SymbolDynamicUBO& dynamic [[buffer(0)]], + device const SymbolDrawableUBO& drawable [[buffer(1)]], + device const SymbolTilePropsUBO& tileprops [[buffer(2)]], + device const SymbolInterpolateUBO& interp [[buffer(3)]], + device const SymbolEvaluatedPropsUBO& paint [[buffer(4)]]) { const float2 a_pos = vertx.pos_offset.xy; const float2 a_offset = vertx.pos_offset.zw; @@ -65,18 +65,18 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], const float segment_angle = -vertx.projected_pos[2]; float size; - if (!props.is_size_zoom_constant && !props.is_size_feature_constant) { - size = mix(a_size_min, a_size[1], props.size_t) / 128.0; - } else if (props.is_size_zoom_constant && !props.is_size_feature_constant) { + if (!tileprops.is_size_zoom_constant && !tileprops.is_size_feature_constant) { + size = mix(a_size_min, a_size[1], tileprops.size_t) / 128.0; + } else if (tileprops.is_size_zoom_constant && !tileprops.is_size_feature_constant) { size = a_size_min / 128.0; } else { - size = props.size; + size = tileprops.size; } const float4 projectedPoint = drawable.matrix * float4(a_pos, 0, 1); const float camera_to_anchor_distance = projectedPoint.w; // See comments in symbol_sdf.vertex - const float distance_ratio = props.pitch_with_map ? + const float distance_ratio = tileprops.pitch_with_map ? camera_to_anchor_distance / dynamic.camera_to_center_distance : dynamic.camera_to_center_distance / camera_to_anchor_distance; const float perspective_ratio = clamp( @@ -86,7 +86,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], size *= perspective_ratio; - const float fontScale = props.is_text ? size / 24.0 : size; + const float fontScale = tileprops.is_text ? size / 24.0 : size; float symbol_rotation = 0.0; if (drawable.rotate_symbol) { @@ -123,8 +123,10 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const SymbolDrawableUBO& drawable [[buffer(6)]], - device const SymbolDrawablePaintUBO& paint [[buffer(8)]], + device const SymbolDynamicUBO& dynamic [[buffer(0)]], + device const SymbolDrawableUBO& drawable [[buffer(1)]], + device const SymbolTilePropsUBO& tileprops [[buffer(2)]], + device const SymbolEvaluatedPropsUBO& props [[buffer(4)]], texture2d image [[texture(0)]], sampler image_sampler [[sampler(0)]]) { #if defined(OVERDRAW_INSPECTOR) @@ -132,7 +134,7 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], #endif #if defined(HAS_UNIFORM_u_opacity) - const float opacity = paint.opacity * in.fade_opacity; + const float opacity = (tileprops.is_text ? props.text_opacity : props.icon_opacity) * in.fade_opacity; #else const float opacity = in.opacity; // fade_opacity is baked in for this case #endif diff --git a/include/mbgl/shaders/mtl/symbol_sdf.hpp b/include/mbgl/shaders/mtl/symbol_sdf.hpp index 73a45bcec..8bd224085 100644 --- a/include/mbgl/shaders/mtl/symbol_sdf.hpp +++ b/include/mbgl/shaders/mtl/symbol_sdf.hpp @@ -14,33 +14,33 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array uniforms; static const std::array textures; static constexpr auto source = R"( struct VertexStage { - float4 pos_offset [[attribute(0)]]; - float4 data [[attribute(1)]]; - float4 pixeloffset [[attribute(2)]]; - float3 projected_pos [[attribute(3)]]; - float fade_opacity [[attribute(4)]]; + float4 pos_offset [[attribute(5)]]; + float4 data [[attribute(6)]]; + float4 pixeloffset [[attribute(7)]]; + float3 projected_pos [[attribute(8)]]; + float fade_opacity [[attribute(9)]]; #if !defined(HAS_UNIFORM_u_fill_color) - float4 fill_color [[attribute(5)]]; + float4 fill_color [[attribute(10)]]; #endif #if !defined(HAS_UNIFORM_u_halo_color) - float4 halo_color [[attribute(6)]]; + float4 halo_color [[attribute(11)]]; #endif #if !defined(HAS_UNIFORM_u_opacity) - float opacity [[attribute(7)]]; + float opacity [[attribute(12)]]; #endif #if !defined(HAS_UNIFORM_u_halo_width) - float halo_width [[attribute(8)]]; + float halo_width [[attribute(13)]]; #endif #if !defined(HAS_UNIFORM_u_halo_blur) - float halo_blur [[attribute(9)]]; + float halo_blur [[attribute(14)]]; #endif }; @@ -71,11 +71,11 @@ struct FragmentStage { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const SymbolDrawableUBO& drawable [[buffer(10)]], - device const SymbolDynamicUBO& dynamic [[buffer(11)]], - device const SymbolDrawablePaintUBO& paint [[buffer(12)]], - device const SymbolDrawableTilePropsUBO& props [[buffer(13)]], - device const SymbolDrawableInterpolateUBO& interp [[buffer(14)]]) { + device const SymbolDynamicUBO& dynamic [[buffer(0)]], + device const SymbolDrawableUBO& drawable [[buffer(1)]], + device const SymbolTilePropsUBO& tileprops [[buffer(2)]], + device const SymbolInterpolateUBO& interp [[buffer(3)]], + device const SymbolEvaluatedPropsUBO& props [[buffer(4)]]) { const float2 a_pos = vertx.pos_offset.xy; const float2 a_offset = vertx.pos_offset.zw; @@ -89,12 +89,12 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], const float segment_angle = -vertx.projected_pos[2]; float size; - if (!props.is_size_zoom_constant && !props.is_size_feature_constant) { - size = mix(a_size_min, a_size[1], props.size_t) / 128.0; - } else if (props.is_size_zoom_constant && !props.is_size_feature_constant) { + if (!tileprops.is_size_zoom_constant && !tileprops.is_size_feature_constant) { + size = mix(a_size_min, a_size[1], tileprops.size_t) / 128.0; + } else if (tileprops.is_size_zoom_constant && !tileprops.is_size_feature_constant) { size = a_size_min / 128.0; } else { - size = props.size; + size = tileprops.size; } const float4 projectedPoint = drawable.matrix * float4(a_pos, 0, 1); @@ -105,7 +105,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], // If the label isn't pitched with the map, we do layout in viewport space, // which makes labels in the distance larger relative to the features around // them. We counteract part of that effect by dividing by the perspective ratio. - const float distance_ratio = props.pitch_with_map ? + const float distance_ratio = tileprops.pitch_with_map ? camera_to_anchor_distance / dynamic.camera_to_center_distance : dynamic.camera_to_center_distance / camera_to_anchor_distance; const float perspective_ratio = clamp( @@ -115,7 +115,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], size *= perspective_ratio; - const float fontScale = props.is_text ? size / 24.0 : size; + const float fontScale = tileprops.is_text ? size / 24.0 : size; float symbol_rotation = 0.0; if (drawable.rotate_symbol) { @@ -165,10 +165,10 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const SymbolDrawableUBO& drawable [[buffer(10)]], - device const SymbolDynamicUBO& dynamic [[buffer(11)]], - device const SymbolDrawablePaintUBO& paint [[buffer(12)]], - device const SymbolDrawableTilePropsUBO& props [[buffer(13)]], + device const SymbolDynamicUBO& dynamic [[buffer(0)]], + device const SymbolDrawableUBO& drawable [[buffer(1)]], + device const SymbolTilePropsUBO& tileprops [[buffer(2)]], + device const SymbolEvaluatedPropsUBO& props [[buffer(4)]], texture2d image [[texture(0)]], sampler image_sampler [[sampler(0)]]) { #if defined(OVERDRAW_INSPECTOR) @@ -176,36 +176,36 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], #endif #if defined(HAS_UNIFORM_u_fill_color) - const half4 fill_color = half4(paint.fill_color); + const half4 fill_color = half4(tileprops.is_text ? props.text_fill_color : props.icon_fill_color); #else const half4 fill_color = in.fill_color; #endif #if defined(HAS_UNIFORM_u_halo_color) - const half4 halo_color = half4(paint.halo_color); + const half4 halo_color = half4(tileprops.is_text ? props.text_halo_color : props.icon_halo_color); #else const half4 halo_color = in.halo_color; #endif #if defined(HAS_UNIFORM_u_opacity) - const float opacity = paint.opacity; + const float opacity = tileprops.is_text ? props.text_opacity : props.icon_opacity; #else const float opacity = in.opacity; #endif #if defined(HAS_UNIFORM_u_halo_width) - const float halo_width = paint.halo_width; + const float halo_width = tileprops.is_text ? props.text_halo_width : props.icon_halo_width; #else const float halo_width = in.halo_width; #endif #if defined(HAS_UNIFORM_u_halo_blur) - const float halo_blur = paint.halo_blur; + const float halo_blur = tileprops.is_text ? props.text_halo_blur : props.icon_halo_blur; #else const float halo_blur = in.halo_blur; #endif const float EDGE_GAMMA = 0.105 / DEVICE_PIXEL_RATIO; const float fontGamma = in.fontScale * drawable.gamma_scale; - const half4 color = props.is_halo ? halo_color : fill_color; - const float gamma = ((props.is_halo ? (halo_blur * 1.19 / SDF_PX) : 0) + EDGE_GAMMA) / fontGamma; - const float buff = props.is_halo ? (6.0 - halo_width / in.fontScale) / SDF_PX : (256.0 - 64.0) / 256.0; + const half4 color = tileprops.is_halo ? halo_color : fill_color; + const float gamma = ((tileprops.is_halo ? (halo_blur * 1.19 / SDF_PX) : 0) + EDGE_GAMMA) / fontGamma; + const float buff = tileprops.is_halo ? (6.0 - halo_width / in.fontScale) / SDF_PX : (256.0 - 64.0) / 256.0; const float dist = image.sample(image_sampler, float2(in.tex)).a; const float gamma_scaled = gamma * in.gamma_scale; const float alpha = smoothstep(buff - gamma_scaled, buff + gamma_scaled, dist); diff --git a/include/mbgl/shaders/mtl/symbol_text_and_icon.hpp b/include/mbgl/shaders/mtl/symbol_text_and_icon.hpp index a56e664da..3daff244c 100644 --- a/include/mbgl/shaders/mtl/symbol_text_and_icon.hpp +++ b/include/mbgl/shaders/mtl/symbol_text_and_icon.hpp @@ -14,9 +14,9 @@ struct ShaderSource static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array uniforms; static const std::array textures; static constexpr auto source = R"( @@ -24,25 +24,25 @@ struct ShaderSource #define ICON 0.0 struct VertexStage { - float4 pos_offset [[attribute(0)]]; - float4 data [[attribute(1)]]; - float3 projected_pos [[attribute(2)]]; - float fade_opacity [[attribute(3)]]; + float4 pos_offset [[attribute(5)]]; + float4 data [[attribute(6)]]; + float3 projected_pos [[attribute(7)]]; + float fade_opacity [[attribute(8)]]; #if !defined(HAS_UNIFORM_u_fill_color) - float4 fill_color [[attribute(4)]]; + float4 fill_color [[attribute(9)]]; #endif #if !defined(HAS_UNIFORM_u_halo_color) - float4 halo_color [[attribute(5)]]; + float4 halo_color [[attribute(10)]]; #endif #if !defined(HAS_UNIFORM_u_opacity) - float opacity [[attribute(6)]]; + float opacity [[attribute(11)]]; #endif #if !defined(HAS_UNIFORM_u_halo_width) - float halo_width [[attribute(7)]]; + float halo_width [[attribute(12)]]; #endif #if !defined(HAS_UNIFORM_u_halo_blur) - float halo_blur [[attribute(8)]]; + float halo_blur [[attribute(13)]]; #endif }; @@ -75,11 +75,11 @@ struct FragmentStage { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const SymbolDrawableUBO& drawable [[buffer(9)]], - device const SymbolDynamicUBO& dynamic [[buffer(10)]], - device const SymbolDrawablePaintUBO& paint [[buffer(11)]], - device const SymbolDrawableTilePropsUBO& props [[buffer(12)]], - device const SymbolDrawableInterpolateUBO& interp [[buffer(13)]]) { + device const SymbolDynamicUBO& dynamic [[buffer(0)]], + device const SymbolDrawableUBO& drawable [[buffer(1)]], + device const SymbolTilePropsUBO& tileprops [[buffer(2)]], + device const SymbolInterpolateUBO& interp [[buffer(3)]], + device const SymbolEvaluatedPropsUBO& props [[buffer(4)]]) { const float2 a_pos = vertx.pos_offset.xy; const float2 a_offset = vertx.pos_offset.zw; @@ -93,12 +93,12 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], const float segment_angle = -vertx.projected_pos[2]; float size; - if (!props.is_size_zoom_constant && !props.is_size_feature_constant) { - size = mix(a_size_min, a_size[1], props.size_t) / 128.0; - } else if (props.is_size_zoom_constant && !props.is_size_feature_constant) { + if (!tileprops.is_size_zoom_constant && !tileprops.is_size_feature_constant) { + size = mix(a_size_min, a_size[1], tileprops.size_t) / 128.0; + } else if (tileprops.is_size_zoom_constant && !tileprops.is_size_feature_constant) { size = a_size_min / 128.0; } else { - size = props.size; + size = tileprops.size; } const float4 projectedPoint = drawable.matrix * float4(a_pos, 0, 1); @@ -109,7 +109,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], // If the label isn't pitched with the map, we do layout in viewport space, // which makes labels in the distance larger relative to the features around // them. We counteract part of that effect by dividing by the perspective ratio. - const float distance_ratio = props.pitch_with_map ? + const float distance_ratio = tileprops.pitch_with_map ? camera_to_anchor_distance / dynamic.camera_to_center_distance : dynamic.camera_to_center_distance / camera_to_anchor_distance; const float perspective_ratio = clamp( @@ -175,10 +175,10 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const SymbolDrawableUBO& drawable [[buffer(9)]], - device const SymbolDynamicUBO& dynamic [[buffer(10)]], - device const SymbolDrawablePaintUBO& paint [[buffer(11)]], - device const SymbolDrawableTilePropsUBO& props [[buffer(12)]], + device const SymbolDynamicUBO& dynamic [[buffer(0)]], + device const SymbolDrawableUBO& drawable [[buffer(1)]], + device const SymbolTilePropsUBO& tileprops [[buffer(2)]], + device const SymbolEvaluatedPropsUBO& props [[buffer(4)]], texture2d glyph_image [[texture(0)]], texture2d icon_image [[texture(1)]], sampler glyph_sampler [[sampler(0)]], @@ -188,27 +188,27 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], #endif #if defined(HAS_UNIFORM_u_fill_color) - const half4 fill_color = half4(paint.fill_color); + const half4 fill_color = half4(tileprops.is_text ? props.text_fill_color : props.icon_fill_color); #else const half4 fill_color = in.fill_color; #endif #if defined(HAS_UNIFORM_u_halo_color) - const half4 halo_color = half4(paint.halo_color); + const half4 halo_color = half4(tileprops.is_text ? props.text_halo_color : props.icon_halo_color); #else const half4 halo_color = in.halo_color; #endif #if defined(HAS_UNIFORM_u_opacity) - const half opacity = half(paint.opacity); + const half opacity = half(tileprops.is_text ? props.text_opacity : props.icon_opacity); #else const half opacity = in.opacity; #endif #if defined(HAS_UNIFORM_u_halo_width) - const half halo_width = half(paint.halo_width); + const half halo_width = half(tileprops.is_text ? props.text_halo_width : props.icon_halo_width); #else const half halo_width = in.halo_width; #endif #if defined(HAS_UNIFORM_u_halo_blur) - const half halo_blur = half(paint.halo_blur); + const half halo_blur = half(tileprops.is_text ? props.text_halo_blur : props.icon_halo_blur); #else const half halo_blur = in.halo_blur; #endif @@ -219,10 +219,10 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], } const float EDGE_GAMMA = 0.105 / DEVICE_PIXEL_RATIO; - const half4 color = props.is_halo ? halo_color : fill_color; + const half4 color = tileprops.is_halo ? halo_color : fill_color; const float fontGamma = in.fontScale * drawable.gamma_scale; - const float gamma = ((props.is_halo ? (halo_blur * 1.19 / SDF_PX) : 0) + EDGE_GAMMA) / fontGamma; - const float buff = props.is_halo ? (6.0 - halo_width / in.fontScale) / SDF_PX : (256.0 - 64.0) / 256.0; + const float gamma = ((tileprops.is_halo ? (halo_blur * 1.19 / SDF_PX) : 0) + EDGE_GAMMA) / fontGamma; + const float buff = tileprops.is_halo ? (6.0 - halo_width / in.fontScale) / SDF_PX : (256.0 - 64.0) / 256.0; const float dist = glyph_image.sample(glyph_sampler, float2(in.tex)).a; const float gamma_scaled = gamma * in.gamma_scale; const float alpha = smoothstep(buff - gamma_scaled, buff + gamma_scaled, dist); diff --git a/include/mbgl/shaders/mtl/widevector.hpp b/include/mbgl/shaders/mtl/widevector.hpp index e02b08f70..d20d55657 100644 --- a/include/mbgl/shaders/mtl/widevector.hpp +++ b/include/mbgl/shaders/mtl/widevector.hpp @@ -14,14 +14,14 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexTri_wideVecPerf"; static constexpr auto fragmentMainFunction = "fragmentTri_wideVecPerf"; - static constexpr std::array attributes{ - AttributeInfo{0, gfx::AttributeDataType::Float3, idWideVectorScreenPos}, - AttributeInfo{1, gfx::AttributeDataType::Float4, idWideVectorColor}, - AttributeInfo{2, gfx::AttributeDataType::Int, idWideVectorIndex}}; static constexpr std::array uniforms{ - UniformBlockInfo{3, true, false, sizeof(WideVectorUniformsUBO), idWideVectorUniformsUBO}, - UniformBlockInfo{4, true, false, sizeof(WideVectorUniformWideVecUBO), idWideVectorUniformWideVecUBO}, + UniformBlockInfo{true, false, sizeof(WideVectorUniformsUBO), idWideVectorUniformsUBO}, + UniformBlockInfo{true, false, sizeof(WideVectorUniformWideVecUBO), idWideVectorUniformWideVecUBO}, }; + static constexpr std::array attributes{ + AttributeInfo{wideVectorUBOCount + 0, gfx::AttributeDataType::Float3, idWideVectorScreenPos}, + AttributeInfo{wideVectorUBOCount + 1, gfx::AttributeDataType::Float4, idWideVectorColor}, + AttributeInfo{wideVectorUBOCount + 2, gfx::AttributeDataType::Int, idWideVectorIndex}}; static constexpr std::array instanceAttributes{ AttributeInfo{5, gfx::AttributeDataType::Float3, idWideVectorInstanceCenter}, AttributeInfo{5, gfx::AttributeDataType::Float4, idWideVectorInstanceColor}, @@ -112,9 +112,9 @@ typedef struct struct VertexTriWideVecB { // x, y offset around the center - float3 screenPos [[attribute(0)]]; - float4 color [[attribute(1)]]; - int index [[attribute(2)]]; + float3 screenPos [[attribute(2)]]; + float4 color [[attribute(3)]]; + int index [[attribute(4)]]; }; // Wide vector vertex passed to fragment shader (new version) @@ -221,8 +221,8 @@ constant constexpr float4 discardPt(0,0,-1e6,NAN); // Performance version of wide vector shader vertex ProjVertexTriWideVecPerf vertexTri_wideVecPerf( thread const VertexTriWideVecB vert [[ stage_in ]], - constant Uniforms &uniforms [[ buffer(3) ]], - constant UniformWideVec &wideVec [[ buffer(4) ]], + constant Uniforms &uniforms [[ buffer(0) ]], + constant UniformWideVec &wideVec [[ buffer(1) ]], uint instanceID [[ instance_id ]], constant VertexTriWideVecInstance *wideVecInsts [[ buffer(5) ]]) { @@ -563,7 +563,7 @@ vertex ProjVertexTriWideVecPerf vertexTri_wideVecPerf( // Fragment shader that takes the back of the globe into account fragment float4 fragmentTri_wideVecPerf( ProjVertexTriWideVecPerf vert [[stage_in]], - constant Uniforms &uniforms [[ buffer(3) ]]) + constant Uniforms &uniforms [[ buffer(0) ]]) { float patternAlpha = 1.0; diff --git a/include/mbgl/shaders/raster_layer_ubo.hpp b/include/mbgl/shaders/raster_layer_ubo.hpp index 4a8f20d26..7f978193e 100644 --- a/include/mbgl/shaders/raster_layer_ubo.hpp +++ b/include/mbgl/shaders/raster_layer_ubo.hpp @@ -7,6 +7,10 @@ namespace shaders { struct alignas(16) RasterDrawableUBO { std::array matrix; +}; +static_assert(sizeof(RasterDrawableUBO) == 64); + +struct alignas(16) RasterEvaluatedPropsUBO { std::array spin_weights; std::array tl_parent; float scale_parent; @@ -19,11 +23,11 @@ struct alignas(16) RasterDrawableUBO { float contrast_factor; float pad1, pad2; }; -static_assert(sizeof(RasterDrawableUBO) == 128); -static_assert(sizeof(RasterDrawableUBO) % 16 == 0); +static_assert(sizeof(RasterEvaluatedPropsUBO) == 64); enum { idRasterDrawableUBO, + idRasterEvaluatedPropsUBO, rasterUBOCount }; diff --git a/include/mbgl/shaders/shader_defines.hpp b/include/mbgl/shaders/shader_defines.hpp index 6984ead50..f393fb379 100644 --- a/include/mbgl/shaders/shader_defines.hpp +++ b/include/mbgl/shaders/shader_defines.hpp @@ -34,19 +34,12 @@ static constexpr auto maxUBOCountPerShader = std::max({static_cast(backg static_cast(customSymbolUBOCount), static_cast(debugUBOCount), static_cast(fillUBOCount), - static_cast(fillOutlineUBOCount), - static_cast(fillPatternUBOCount), - static_cast(fillOutlinePatternUBOCount), - static_cast(fillOutlineTriangulatedUBOCount), static_cast(fillExtrusionUBOCount), static_cast(heatmapUBOCount), static_cast(heatmapTextureUBOCount), static_cast(hillshadeUBOCount), static_cast(hillshadePrepareUBOCount), static_cast(lineUBOCount), - static_cast(lineGradientUBOCount), - static_cast(linePatternUBOCount), - static_cast(lineSDFUBOCount), static_cast(rasterUBOCount), static_cast(symbolUBOCount), static_cast(wideVectorUBOCount)}); diff --git a/include/mbgl/shaders/symbol_layer_ubo.hpp b/include/mbgl/shaders/symbol_layer_ubo.hpp index 82376a5c6..5c15e64c9 100644 --- a/include/mbgl/shaders/symbol_layer_ubo.hpp +++ b/include/mbgl/shaders/symbol_layer_ubo.hpp @@ -5,31 +5,15 @@ namespace mbgl { namespace shaders { -/// Evaluated properties that depend on the tile -struct alignas(16) SymbolDrawableTilePropsUBO { - /* 0 */ /*bool*/ int is_text; - /* 4 */ /*bool*/ int is_halo; - /* 8 */ /*bool*/ int pitch_with_map; - /* 12 */ /*bool*/ int is_size_zoom_constant; - /* 16 */ /*bool*/ int is_size_feature_constant; - /* 20 */ float size_t; - /* 24 */ float size; - /* 28 */ float padding; - /* 32 */ +/// Dynamic UBO +struct alignas(16) SymbolDynamicUBO { + /* 0 */ float fade_change; + /* 4 */ float camera_to_center_distance; + /* 8 */ float aspect_ratio; + /* 12 */ float pad; + /* 16 */ }; -static_assert(sizeof(SymbolDrawableTilePropsUBO) == 2 * 16); - -/// Attribute interpolations -struct alignas(16) SymbolDrawableInterpolateUBO { - /* 0 */ float fill_color_t; - /* 4 */ float halo_color_t; - /* 8 */ float opacity_t; - /* 12 */ float halo_width_t; - /* 16 */ float halo_blur_t; - /* 20 */ float pad1, pad2, pad3; - /* 32 */ -}; -static_assert(sizeof(SymbolDrawableInterpolateUBO) == 32); +static_assert(sizeof(SymbolDynamicUBO) == 16); struct alignas(16) SymbolDrawableUBO { /* 0 */ std::array matrix; @@ -47,34 +31,56 @@ struct alignas(16) SymbolDrawableUBO { }; static_assert(sizeof(SymbolDrawableUBO) == 14 * 16); -/// Dynamic UBO -struct alignas(16) SymbolDynamicUBO { - /* 0 */ float fade_change; - /* 4 */ float camera_to_center_distance; - /* 8 */ float aspect_ratio; - /* 12 */ float pad; - /* 16 */ +/// Evaluated properties that depend on the tile +struct alignas(16) SymbolTilePropsUBO { + /* 0 */ /*bool*/ int is_text; + /* 4 */ /*bool*/ int is_halo; + /* 8 */ /*bool*/ int pitch_with_map; + /* 12 */ /*bool*/ int is_size_zoom_constant; + /* 16 */ /*bool*/ int is_size_feature_constant; + /* 20 */ float size_t; + /* 24 */ float size; + /* 28 */ float padding; + /* 32 */ }; -static_assert(sizeof(SymbolDynamicUBO) == 16); +static_assert(sizeof(SymbolTilePropsUBO) == 2 * 16); + +/// Attribute interpolations +struct alignas(16) SymbolInterpolateUBO { + /* 0 */ float fill_color_t; + /* 4 */ float halo_color_t; + /* 8 */ float opacity_t; + /* 12 */ float halo_width_t; + /* 16 */ float halo_blur_t; + /* 20 */ float pad1, pad2, pad3; + /* 32 */ +}; +static_assert(sizeof(SymbolInterpolateUBO) == 32); /// Evaluated properties that do not depend on the tile -struct alignas(16) SymbolDrawablePaintUBO { - /* 0 */ Color fill_color; - /* 16 */ Color halo_color; - /* 32 */ float opacity; - /* 36 */ float halo_width; - /* 40 */ float halo_blur; - /* 44 */ float padding; - /* 48 */ +struct alignas(16) SymbolEvaluatedPropsUBO { + /* 0 */ Color text_fill_color; + /* 16 */ Color text_halo_color; + /* 32 */ float text_opacity; + /* 36 */ float text_halo_width; + /* 40 */ float text_halo_blur; + /* 44 */ float pad1; + /* 48 */ Color icon_fill_color; + /* 64 */ Color icon_halo_color; + /* 80 */ float icon_opacity; + /* 84 */ float icon_halo_width; + /* 88 */ float icon_halo_blur; + /* 92 */ float pad2; + /* 96 */ }; -static_assert(sizeof(SymbolDrawablePaintUBO) == 3 * 16); +static_assert(sizeof(SymbolEvaluatedPropsUBO) == 6 * 16); enum { - idSymbolDrawableUBO, idSymbolDynamicUBO, - idSymbolDrawablePaintUBO, - idSymbolDrawableTilePropsUBO, - idSymbolDrawableInterpolateUBO, + idSymbolDrawableUBO, + idSymbolTilePropsUBO, + idSymbolInterpolateUBO, + idSymbolEvaluatedPropsUBO, symbolUBOCount }; diff --git a/shaders/drawable.background.fragment.glsl b/shaders/drawable.background.fragment.glsl index 2993d8989..383012d37 100644 --- a/shaders/drawable.background.fragment.glsl +++ b/shaders/drawable.background.fragment.glsl @@ -1,10 +1,11 @@ layout (std140) uniform BackgroundLayerUBO { highp vec4 u_color; - highp vec4 u_opacity_pad3; + highp float u_opacity; + highp float layer_pad1, layer_pad2, layer_pad3; }; void main() { - fragColor = u_color * u_opacity_pad3.x; + fragColor = u_color * u_opacity; #ifdef OVERDRAW_INSPECTOR fragColor = vec4(1.0); #endif diff --git a/shaders/drawable.background_pattern.fragment.glsl b/shaders/drawable.background_pattern.fragment.glsl index ac49a616c..707f3cf06 100644 --- a/shaders/drawable.background_pattern.fragment.glsl +++ b/shaders/drawable.background_pattern.fragment.glsl @@ -1,4 +1,4 @@ -layout (std140) uniform BackgroundLayerUBO { +layout (std140) uniform BackgroundPatternLayerUBO { highp vec2 u_pattern_tl_a; highp vec2 u_pattern_br_a; highp vec2 u_pattern_tl_b; @@ -6,14 +6,11 @@ layout (std140) uniform BackgroundLayerUBO { highp vec2 u_texsize; highp vec2 u_pattern_size_a; highp vec2 u_pattern_size_b; - highp vec2 u_pixel_coord_upper; - highp vec2 u_pixel_coord_lower; - highp float u_tile_units_to_pixels; highp float u_scale_a; highp float u_scale_b; highp float u_mix; highp float u_opacity; - highp float pad; + highp float layer_pad1, layer_pad2; }; uniform sampler2D u_image; diff --git a/shaders/drawable.background_pattern.vertex.glsl b/shaders/drawable.background_pattern.vertex.glsl index eda93326d..982d370bd 100644 --- a/shaders/drawable.background_pattern.vertex.glsl +++ b/shaders/drawable.background_pattern.vertex.glsl @@ -1,7 +1,11 @@ -layout (std140) uniform BackgroundDrawableUBO { +layout (std140) uniform BackgroundPatternDrawableUBO { highp mat4 u_matrix; + highp vec2 u_pixel_coord_upper; + highp vec2 u_pixel_coord_lower; + highp float u_tile_units_to_pixels; + highp float drawable_pad1, drawable_pad2, drawable_pad3; }; -layout (std140) uniform BackgroundLayerUBO { +layout (std140) uniform BackgroundPatternLayerUBO { highp vec2 u_pattern_tl_a; highp vec2 u_pattern_br_a; highp vec2 u_pattern_tl_b; @@ -9,14 +13,11 @@ layout (std140) uniform BackgroundLayerUBO { highp vec2 u_texsize; highp vec2 u_pattern_size_a; highp vec2 u_pattern_size_b; - highp vec2 u_pixel_coord_upper; - highp vec2 u_pixel_coord_lower; - highp float u_tile_units_to_pixels; highp float u_scale_a; highp float u_scale_b; highp float u_mix; highp float u_opacity; - highp float pad; + highp float layer_pad1, layer_pad2; }; layout (location = 0) in vec2 a_pos; diff --git a/shaders/drawable.circle.fragment.glsl b/shaders/drawable.circle.fragment.glsl index dac5a252e..afb58420e 100644 --- a/shaders/drawable.circle.fragment.glsl +++ b/shaders/drawable.circle.fragment.glsl @@ -10,7 +10,7 @@ layout (std140) uniform CircleEvaluatedPropsUBO { lowp float u_stroke_opacity; bool u_scale_with_map; bool u_pitch_with_map; - lowp float pad0_; + lowp float props_pad1; }; #pragma mapbox: define highp vec4 color diff --git a/shaders/drawable.circle.vertex.glsl b/shaders/drawable.circle.vertex.glsl index 5e6c784c6..d86057e20 100644 --- a/shaders/drawable.circle.vertex.glsl +++ b/shaders/drawable.circle.vertex.glsl @@ -4,13 +4,13 @@ out vec3 v_data; layout (std140) uniform CircleDrawableUBO { highp mat4 u_matrix; highp vec2 u_extrude_scale; - lowp vec2 pad2_; + lowp vec2 drawable_pad1; }; layout (std140) uniform CirclePaintParamsUBO { highp float u_camera_to_center_distance; - lowp float pad3_; - lowp vec2 pad4_; + lowp float params_pad1; + lowp vec2 params_pad2; }; layout (std140) uniform CircleEvaluatedPropsUBO { @@ -23,7 +23,7 @@ layout (std140) uniform CircleEvaluatedPropsUBO { lowp float u_stroke_opacity; bool u_scale_with_map; bool u_pitch_with_map; - lowp float pad0_; + lowp float props_pad1; }; layout (std140) uniform CircleInterpolateUBO { @@ -34,7 +34,7 @@ layout (std140) uniform CircleInterpolateUBO { lowp float u_stroke_color_t; lowp float u_stroke_width_t; lowp float u_stroke_opacity_t; - lowp float pad1_; + lowp float interp_pad1; }; #pragma mapbox: define highp vec4 color diff --git a/shaders/drawable.custom.symbol_icon.vertex.glsl b/shaders/drawable.custom.symbol_icon.vertex.glsl index b912f515e..3343923b6 100644 --- a/shaders/drawable.custom.symbol_icon.vertex.glsl +++ b/shaders/drawable.custom.symbol_icon.vertex.glsl @@ -13,7 +13,7 @@ layout(std140) uniform CustomSymbolIconParametersUBO { bool u_pitch_with_map; highp float u_camera_to_center_distance; highp float u_aspect_ratio; - highp float pad0, pad1, pad3; + highp float params_pad1, params_pad2, params_pad3; }; out vec2 v_tex; diff --git a/shaders/drawable.fill.fragment.glsl b/shaders/drawable.fill.fragment.glsl index 36cc6be0b..2acc814b8 100644 --- a/shaders/drawable.fill.fragment.glsl +++ b/shaders/drawable.fill.fragment.glsl @@ -1,14 +1,15 @@ -layout (std140) uniform FillEvaluatedPropsUBO { - highp vec4 u_color; - highp float u_opacity; - highp float padding_props1; - highp float padding_props2; - highp float padding_props3; -}; layout (std140) uniform FillInterpolateUBO { highp float u_color_t; highp float u_opacity_t; - highp float pad_interp_1, pad_interp_2; + highp float interp_pad1, interp_pad2; +}; +layout (std140) uniform FillEvaluatedPropsUBO { + highp vec4 u_color; + highp vec4 u_outline_color; + highp float u_opacity; + highp float u_fade; + highp float u_width; + highp float props_pad1; }; #pragma mapbox: define highp vec4 color diff --git a/shaders/drawable.fill.vertex.glsl b/shaders/drawable.fill.vertex.glsl index 9ac467c8e..a47c00116 100644 --- a/shaders/drawable.fill.vertex.glsl +++ b/shaders/drawable.fill.vertex.glsl @@ -1,17 +1,18 @@ layout (std140) uniform FillDrawableUBO { highp mat4 u_matrix; }; -layout (std140) uniform FillEvaluatedPropsUBO { - highp vec4 u_color; - highp float u_opacity; - highp float padding_props1; - highp float padding_props2; - highp float padding_props3; -}; layout (std140) uniform FillInterpolateUBO { highp float u_color_t; highp float u_opacity_t; - highp float pad_interp_1, pad_interp_2; + highp float interp_pad1, interp_pad2; +}; +layout (std140) uniform FillEvaluatedPropsUBO { + highp vec4 u_color; + highp vec4 u_outline_color; + highp float u_opacity; + highp float u_fade; + highp float u_width; + highp float props_pad1; }; layout (location = 0) in vec2 a_pos; diff --git a/shaders/drawable.fill_extrusion.vertex.glsl b/shaders/drawable.fill_extrusion.vertex.glsl index 13b599bdd..00e302f4a 100644 --- a/shaders/drawable.fill_extrusion.vertex.glsl +++ b/shaders/drawable.fill_extrusion.vertex.glsl @@ -2,7 +2,29 @@ layout (location = 0) in vec2 a_pos; layout (location = 1) in vec4 a_normal_ed; out vec4 v_color; -layout (std140) uniform FillExtrusionDrawableTilePropsUBO { +layout (std140) uniform FillExtrusionDrawableUBO { + highp mat4 u_matrix; + highp vec4 u_scale; + highp vec2 u_texsize; + highp vec2 u_pixel_coord_upper; + highp vec2 u_pixel_coord_lower; + highp float u_height_factor; + highp float drawable_pad1; +}; +layout (std140) uniform FillExtrusionPropsUBO { + highp vec4 u_color; + highp vec3 u_lightcolor; + highp float props_pad1; + highp vec3 u_lightpos; + highp float u_base; + highp float u_height; + highp float u_lightintensity; + highp float u_vertical_gradient; + highp float u_opacity; + highp float u_fade; + highp float props_pad2, props_pad3, props_pad4; +}; +layout (std140) uniform FillExtrusionTilePropsUBO { highp vec4 u_pattern_from; highp vec4 u_pattern_to; }; @@ -12,31 +34,8 @@ layout (std140) uniform FillExtrusionInterpolateUBO { highp float u_color_t; highp float u_pattern_from_t; highp float u_pattern_to_t; - highp float u_pad_interp1, u_pad_interp2, u_pad_interp3; + highp float interp_pad1, interp_pad2, interp_pad3; }; -layout (std140) uniform FillExtrusionDrawableUBO { - highp mat4 u_matrix; - highp vec4 u_scale; - highp vec2 u_texsize; - highp vec2 u_pixel_coord_upper; - highp vec2 u_pixel_coord_lower; - highp float u_height_factor; - highp float u_pad_drawable; -}; -layout (std140) uniform FillExtrusionDrawablePropsUBO { - highp vec4 u_color; - highp vec3 u_lightcolor; - highp float u_pad1; - highp vec3 u_lightpos; - highp float u_base; - highp float u_height; - highp float u_lightintensity; - highp float u_vertical_gradient; - highp float u_opacity; - highp float u_fade; - highp float u_pad_props2, u_pad_props3, u_pad_props4; -}; - #pragma mapbox: define highp float base #pragma mapbox: define highp float height #pragma mapbox: define highp vec4 color diff --git a/shaders/drawable.fill_extrusion_pattern.fragment.glsl b/shaders/drawable.fill_extrusion_pattern.fragment.glsl index 0ccad3d59..110759f80 100644 --- a/shaders/drawable.fill_extrusion_pattern.fragment.glsl +++ b/shaders/drawable.fill_extrusion_pattern.fragment.glsl @@ -2,7 +2,29 @@ in vec2 v_pos_a; in vec2 v_pos_b; in vec4 v_lighting; -layout (std140) uniform FillExtrusionDrawableTilePropsUBO { +layout (std140) uniform FillExtrusionDrawableUBO { + highp mat4 u_matrix; + highp vec4 u_scale; + highp vec2 u_texsize; + highp vec2 u_pixel_coord_upper; + highp vec2 u_pixel_coord_lower; + highp float u_height_factor; + highp float drawable_pad1; +}; +layout (std140) uniform FillExtrusionPropsUBO { + highp vec4 u_color; + highp vec3 u_lightcolor; + highp float props_pad1; + highp vec3 u_lightpos; + highp float u_base; + highp float u_height; + highp float u_lightintensity; + highp float u_vertical_gradient; + highp float u_opacity; + highp float u_fade; + highp float props_pad2, props_pad3, props_pad4; +}; +layout (std140) uniform FillExtrusionTilePropsUBO { highp vec4 u_pattern_from; highp vec4 u_pattern_to; }; @@ -12,29 +34,7 @@ layout (std140) uniform FillExtrusionInterpolateUBO { highp float u_color_t; highp float u_pattern_from_t; highp float u_pattern_to_t; - highp float u_pad_interp1, u_pad_interp2, u_pad_interp3; -}; -layout (std140) uniform FillExtrusionDrawableUBO { - highp mat4 u_matrix; - highp vec4 u_scale; - highp vec2 u_texsize; - highp vec2 u_pixel_coord_upper; - highp vec2 u_pixel_coord_lower; - highp float u_height_factor; - highp float u_pad_drawable; -}; -layout (std140) uniform FillExtrusionDrawablePropsUBO { - highp vec4 u_color; - highp vec3 u_lightcolor; - highp float u_pad1; - highp vec3 u_lightpos; - highp float u_base; - highp float u_height; - highp float u_lightintensity; - highp float u_vertical_gradient; - highp float u_opacity; - highp float u_fade; - highp float u_pad_props2, u_pad_props3, u_pad_props4; + highp float interp_pad1, interp_pad2, interp_pad3; }; uniform sampler2D u_image; diff --git a/shaders/drawable.fill_extrusion_pattern.vertex.glsl b/shaders/drawable.fill_extrusion_pattern.vertex.glsl index 5c852dcc1..767f779a4 100644 --- a/shaders/drawable.fill_extrusion_pattern.vertex.glsl +++ b/shaders/drawable.fill_extrusion_pattern.vertex.glsl @@ -5,7 +5,29 @@ out vec2 v_pos_a; out vec2 v_pos_b; out vec4 v_lighting; -layout (std140) uniform FillExtrusionDrawableTilePropsUBO { +layout (std140) uniform FillExtrusionDrawableUBO { + highp mat4 u_matrix; + highp vec4 u_scale; + highp vec2 u_texsize; + highp vec2 u_pixel_coord_upper; + highp vec2 u_pixel_coord_lower; + highp float u_height_factor; + highp float drawable_pad1; +}; +layout (std140) uniform FillExtrusionPropsUBO { + highp vec4 u_color; + highp vec3 u_lightcolor; + highp float props_pad1; + highp vec3 u_lightpos; + highp float u_base; + highp float u_height; + highp float u_lightintensity; + highp float u_vertical_gradient; + highp float u_opacity; + highp float u_fade; + highp float props_pad2, props_pad3, props_pad4; +}; +layout (std140) uniform FillExtrusionTilePropsUBO { highp vec4 u_pattern_from; highp vec4 u_pattern_to; }; @@ -15,29 +37,7 @@ layout (std140) uniform FillExtrusionInterpolateUBO { highp float u_color_t; highp float u_pattern_from_t; highp float u_pattern_to_t; - highp float u_pad_interp1, u_pad_interp2, u_pad_interp3; -}; -layout (std140) uniform FillExtrusionDrawableUBO { - highp mat4 u_matrix; - highp vec4 u_scale; - highp vec2 u_texsize; - highp vec2 u_pixel_coord_upper; - highp vec2 u_pixel_coord_lower; - highp float u_height_factor; - highp float u_pad_drawable; -}; -layout (std140) uniform FillExtrusionDrawablePropsUBO { - highp vec4 u_color; - highp vec3 u_lightcolor; - highp float u_pad1; - highp vec3 u_lightpos; - highp float u_base; - highp float u_height; - highp float u_lightintensity; - highp float u_vertical_gradient; - highp float u_opacity; - highp float u_fade; - highp float u_pad_props2, u_pad_props3, u_pad_props4; + highp float interp_pad1, interp_pad2, interp_pad3; }; #pragma mapbox: define lowp float base diff --git a/shaders/drawable.fill_outline.fragment.glsl b/shaders/drawable.fill_outline.fragment.glsl index 44b3b20df..a9b53443e 100644 --- a/shaders/drawable.fill_outline.fragment.glsl +++ b/shaders/drawable.fill_outline.fragment.glsl @@ -1,15 +1,16 @@ -layout (std140) uniform FillOutlineEvaluatedPropsUBO { - highp vec4 u_outline_color; - highp float u_opacity; - highp float padding_props1; - highp float padding_props2; - highp float padding_props3; -}; layout (std140) uniform FillOutlineInterpolateUBO { highp float u_outline_color_t; highp float u_opacity_t; - highp float u_padding_interp1; - highp float u_padding_interp2; + highp float interp_pad1; + highp float interp_pad2; +}; +layout (std140) uniform FillEvaluatedPropsUBO { + highp vec4 u_color; + highp vec4 u_outline_color; + highp float u_opacity; + highp float u_fade; + highp float u_width; + highp float props_pad1; }; in vec2 v_pos; diff --git a/shaders/drawable.fill_outline.vertex.glsl b/shaders/drawable.fill_outline.vertex.glsl index 3af22f32b..e3d484e55 100644 --- a/shaders/drawable.fill_outline.vertex.glsl +++ b/shaders/drawable.fill_outline.vertex.glsl @@ -1,20 +1,21 @@ layout (std140) uniform FillOutlineDrawableUBO { highp mat4 u_matrix; highp vec2 u_world; - highp vec2 pad; -}; -layout (std140) uniform FillOutlineEvaluatedPropsUBO { - highp vec4 u_outline_color; - highp float u_opacity; - highp float padding_props1; - highp float padding_props2; - highp float padding_props3; + highp vec2 drawable_pad1; }; layout (std140) uniform FillOutlineInterpolateUBO { highp float u_outline_color_t; highp float u_opacity_t; - highp float u_padding_interp1; - highp float u_padding_interp2; + highp float interp_pad1; + highp float interp_pad2; +}; +layout (std140) uniform FillEvaluatedPropsUBO { + highp vec4 u_color; + highp vec4 u_outline_color; + highp float u_opacity; + highp float u_fade; + highp float u_width; + highp float props_pad1; }; layout (location = 0) in vec2 a_pos; diff --git a/shaders/drawable.fill_outline_pattern.fragment.glsl b/shaders/drawable.fill_outline_pattern.fragment.glsl index eff75cd08..fdb1009d0 100644 --- a/shaders/drawable.fill_outline_pattern.fragment.glsl +++ b/shaders/drawable.fill_outline_pattern.fragment.glsl @@ -6,21 +6,23 @@ layout (std140) uniform FillOutlinePatternDrawableUBO { highp vec2 u_pixel_coord_lower; highp vec2 u_texsize; }; -layout (std140) uniform FillOutlinePatternEvaluatedPropsUBO { - highp float u_opacity; - highp float u_fade; - highp float padding_props1; - highp float padding_props2; +layout (std140) uniform FillOutlinePatternTilePropsUBO { + highp vec4 u_pattern_from; + highp vec4 u_pattern_to; }; layout (std140) uniform FillOutlinePatternInterpolateUBO { highp float u_pattern_from_t; highp float u_pattern_to_t; highp float u_opacity_t; - highp float pad1; + highp float interp_pad1; }; -layout (std140) uniform FillOutlinePatternTilePropsUBO { - highp vec4 u_pattern_from; - highp vec4 u_pattern_to; +layout (std140) uniform FillEvaluatedPropsUBO { + highp vec4 u_color; + highp vec4 u_outline_color; + highp float u_opacity; + highp float u_fade; + highp float u_width; + highp float props_pad1; }; uniform sampler2D u_image; diff --git a/shaders/drawable.fill_outline_pattern.vertex.glsl b/shaders/drawable.fill_outline_pattern.vertex.glsl index 785fe032f..f11fe5fa2 100644 --- a/shaders/drawable.fill_outline_pattern.vertex.glsl +++ b/shaders/drawable.fill_outline_pattern.vertex.glsl @@ -6,21 +6,23 @@ layout (std140) uniform FillOutlinePatternDrawableUBO { highp vec2 u_pixel_coord_lower; highp vec2 u_texsize; }; -layout (std140) uniform FillOutlinePatternEvaluatedPropsUBO { - highp float u_opacity; - highp float u_fade; - highp float padding_props1; - highp float padding_props2; +layout (std140) uniform FillOutlinePatternTilePropsUBO { + highp vec4 u_pattern_from; + highp vec4 u_pattern_to; }; layout (std140) uniform FillOutlinePatternInterpolateUBO { highp float u_pattern_from_t; highp float u_pattern_to_t; highp float u_opacity_t; - highp float pad1; + highp float interp_pad1; }; -layout (std140) uniform FillOutlinePatternTilePropsUBO { - highp vec4 u_pattern_from; - highp vec4 u_pattern_to; +layout (std140) uniform FillEvaluatedPropsUBO { + highp vec4 u_color; + highp vec4 u_outline_color; + highp float u_opacity; + highp float u_fade; + highp float u_width; + highp float props_pad1; }; layout (location = 0) in vec2 a_pos; diff --git a/shaders/drawable.fill_outline_triangulated.fragment.glsl b/shaders/drawable.fill_outline_triangulated.fragment.glsl index 8e7abe316..88ca6f1ac 100644 --- a/shaders/drawable.fill_outline_triangulated.fragment.glsl +++ b/shaders/drawable.fill_outline_triangulated.fragment.glsl @@ -1,8 +1,10 @@ -layout (std140) uniform FillOutlineTriangulatedPropertiesUBO { +layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_color; - lowp float u_opacity; - mediump float u_width; - highp vec2 pad1; + highp vec4 u_outline_color; + highp float u_opacity; + highp float u_fade; + highp float u_width; + highp float props_pad1; }; in float v_width; @@ -19,7 +21,7 @@ void main() { float blur2 = (1.0 / DEVICE_PIXEL_RATIO) * v_gamma_scale; float alpha = clamp(min(dist + blur2, v_width - dist) / blur2, 0.0, 1.0); - fragColor = u_color * (alpha * u_opacity); + fragColor = u_outline_color * (alpha * u_opacity); #ifdef OVERDRAW_INSPECTOR fragColor = vec4(1.0); diff --git a/shaders/drawable.fill_outline_triangulated.vertex.glsl b/shaders/drawable.fill_outline_triangulated.vertex.glsl index c2d60d5b2..db0c4d917 100644 --- a/shaders/drawable.fill_outline_triangulated.vertex.glsl +++ b/shaders/drawable.fill_outline_triangulated.vertex.glsl @@ -13,14 +13,15 @@ layout (std140) uniform FillOutlineTriangulatedDrawableUBO { highp mat4 u_matrix; highp vec2 u_units_to_pixels; mediump float u_ratio; - lowp float pad0; + lowp float drawable_pad1; }; - -layout (std140) uniform FillOutlineTriangulatedPropertiesUBO { +layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_color; - lowp float u_opacity; - mediump float u_width; - highp vec2 pad1; + highp vec4 u_outline_color; + highp float u_opacity; + highp float u_fade; + highp float u_width; + highp float props_pad1; }; out vec2 v_normal; diff --git a/shaders/drawable.fill_pattern.fragment.glsl b/shaders/drawable.fill_pattern.fragment.glsl index 86decc73a..20be632b4 100644 --- a/shaders/drawable.fill_pattern.fragment.glsl +++ b/shaders/drawable.fill_pattern.fragment.glsl @@ -4,24 +4,26 @@ layout (std140) uniform FillPatternDrawableUBO { highp vec2 u_pixel_coord_upper; highp vec2 u_pixel_coord_lower; highp vec2 u_texsize; - highp float pad1; - highp float pad2; + highp float drawable_pad1; + highp float drawable_pad2; }; -layout (std140) uniform FillPatternEvaluatedPropsUBO { - highp float u_opacity; - highp float u_fade; - highp float padding_props1; - highp float padding_props2; +layout (std140) uniform FillPatternTilePropsUBO { + highp vec4 u_pattern_from; + highp vec4 u_pattern_to; }; layout (std140) uniform FillPatternInterpolateUBO { highp float u_pattern_from_t; highp float u_pattern_to_t; highp float u_opacity_t; - highp float u_padding_interp1; + highp float interp_pad1; }; -layout (std140) uniform FillPatternTilePropsUBO { - highp vec4 u_pattern_from; - highp vec4 u_pattern_to; +layout (std140) uniform FillEvaluatedPropsUBO { + highp vec4 u_color; + highp vec4 u_outline_color; + highp float u_opacity; + highp float u_fade; + highp float u_width; + highp float props_pad1; }; uniform sampler2D u_image; diff --git a/shaders/drawable.fill_pattern.vertex.glsl b/shaders/drawable.fill_pattern.vertex.glsl index dd0a4b070..f44da587d 100644 --- a/shaders/drawable.fill_pattern.vertex.glsl +++ b/shaders/drawable.fill_pattern.vertex.glsl @@ -4,24 +4,26 @@ layout (std140) uniform FillPatternDrawableUBO { highp vec2 u_pixel_coord_upper; highp vec2 u_pixel_coord_lower; highp vec2 u_texsize; - highp float pad1; - highp float pad2; + highp float drawable_pad1; + highp float drawable_pad2; }; -layout (std140) uniform FillPatternEvaluatedPropsUBO { - highp float u_opacity; - highp float u_fade; - highp float padding_props1; - highp float padding_props2; +layout (std140) uniform FillPatternTilePropsUBO { + highp vec4 u_pattern_from; + highp vec4 u_pattern_to; }; layout (std140) uniform FillPatternInterpolateUBO { highp float u_pattern_from_t; highp float u_pattern_to_t; highp float u_opacity_t; - highp float u_padding_interp1; + highp float interp_pad1; }; -layout (std140) uniform FillPatternTilePropsUBO { - highp vec4 u_pattern_from; - highp vec4 u_pattern_to; +layout (std140) uniform FillEvaluatedPropsUBO { + highp vec4 u_color; + highp vec4 u_outline_color; + highp float u_opacity; + highp float u_fade; + highp float u_width; + highp float props_pad1; }; layout (location = 0) in vec2 a_pos; diff --git a/shaders/drawable.heatmap.fragment.glsl b/shaders/drawable.heatmap.fragment.glsl index 4c501fca7..d98ce5b8d 100644 --- a/shaders/drawable.heatmap.fragment.glsl +++ b/shaders/drawable.heatmap.fragment.glsl @@ -4,7 +4,7 @@ layout (std140) uniform HeatmapEvaluatedPropsUBO { highp float u_weight; highp float u_radius; highp float u_intensity; - lowp float pad0_; + lowp float props_pad1; }; #pragma mapbox: define highp float weight diff --git a/shaders/drawable.heatmap.vertex.glsl b/shaders/drawable.heatmap.vertex.glsl index 539651b11..d769d5ef4 100644 --- a/shaders/drawable.heatmap.vertex.glsl +++ b/shaders/drawable.heatmap.vertex.glsl @@ -4,21 +4,21 @@ out vec2 v_extrude; layout (std140) uniform HeatmapDrawableUBO { highp mat4 u_matrix; highp float u_extrude_scale; - lowp float pad1_; - lowp vec2 pad2_; + lowp float drawable_pad1; + lowp vec2 drawable_pad2; }; layout (std140) uniform HeatmapEvaluatedPropsUBO { highp float u_weight; highp float u_radius; highp float u_intensity; - lowp float pad0_; + lowp float props_pad1; }; layout (std140) uniform HeatmapInterpolateUBO { lowp float u_weight_t; lowp float u_radius_t; - lowp vec2 pad3_; + lowp vec2 interp_pad1; }; #pragma mapbox: define highp float weight diff --git a/shaders/drawable.heatmap_texture.fragment.glsl b/shaders/drawable.heatmap_texture.fragment.glsl index 5113da190..0edacf1af 100644 --- a/shaders/drawable.heatmap_texture.fragment.glsl +++ b/shaders/drawable.heatmap_texture.fragment.glsl @@ -2,11 +2,11 @@ in vec2 v_pos; uniform sampler2D u_image; uniform sampler2D u_color_ramp; -layout (std140) uniform HeatmapTextureDrawableUBO { +layout (std140) uniform HeatmapTexturePropsUBO { highp mat4 u_matrix; highp vec2 u_world; highp float u_opacity; - lowp float pad0_; + lowp float props_pad1; }; void main() { diff --git a/shaders/drawable.heatmap_texture.vertex.glsl b/shaders/drawable.heatmap_texture.vertex.glsl index fa6a2edad..3b6e26d72 100644 --- a/shaders/drawable.heatmap_texture.vertex.glsl +++ b/shaders/drawable.heatmap_texture.vertex.glsl @@ -1,11 +1,11 @@ layout (location = 0) in vec2 a_pos; out vec2 v_pos; -layout (std140) uniform HeatmapTextureDrawableUBO { +layout (std140) uniform HeatmapTexturePropsUBO { highp mat4 u_matrix; highp vec2 u_world; highp float u_opacity; - lowp float pad0_; + lowp float props_pad1; }; void main() { diff --git a/shaders/drawable.line.fragment.glsl b/shaders/drawable.line.fragment.glsl index bb7e9dbb3..9d80d25f7 100644 --- a/shaders/drawable.line.fragment.glsl +++ b/shaders/drawable.line.fragment.glsl @@ -1,19 +1,7 @@ -layout (std140) uniform LineUBO { +layout (std140) uniform LineDrawableUBO { highp mat4 u_matrix; mediump float u_ratio; - lowp float pad2, pad3, pad4; -}; - -layout (std140) uniform LinePropertiesUBO { - highp vec4 u_color; - lowp float u_blur; - lowp float u_opacity; - mediump float u_gapwidth; - lowp float u_offset; - mediump float u_width; - - highp float pad5; - highp vec2 pad6; + lowp float drawable_pad1, drawable_pad2, drawable_pad3; }; layout (std140) uniform LineInterpolationUBO { @@ -23,8 +11,19 @@ layout (std140) uniform LineInterpolationUBO { lowp float u_gapwidth_t; lowp float u_offset_t; lowp float u_width_t; + highp vec2 interp_pad1; +}; - highp vec2 pad7; +layout (std140) uniform LineEvaluatedPropsUBO { + highp vec4 u_color; + lowp float u_blur; + lowp float u_opacity; + mediump float u_gapwidth; + lowp float u_offset; + mediump float u_width; + lowp float u_floorwidth; + highp float props_pad1; + highp float props_pad2; }; in vec2 v_width2; diff --git a/shaders/drawable.line.vertex.glsl b/shaders/drawable.line.vertex.glsl index b44a9bd3b..32d43d856 100644 --- a/shaders/drawable.line.vertex.glsl +++ b/shaders/drawable.line.vertex.glsl @@ -11,25 +11,13 @@ layout (location = 1) in vec4 a_data; layout (std140) uniform LineDynamicUBO { highp vec2 u_units_to_pixels; - lowp float pad0, pad1; + lowp float dynamic_pad1, dynamic_pad2; }; -layout (std140) uniform LineUBO { +layout (std140) uniform LineDrawableUBO { highp mat4 u_matrix; mediump float u_ratio; - lowp float pad2, pad3, pad4; -}; - -layout (std140) uniform LinePropertiesUBO { - highp vec4 u_color; - lowp float u_blur; - lowp float u_opacity; - mediump float u_gapwidth; - lowp float u_offset; - mediump float u_width; - - highp float pad5; - highp vec2 pad6; + lowp float drawable_pad1, drawable_pad2, drawable_pad3; }; layout (std140) uniform LineInterpolationUBO { @@ -39,8 +27,19 @@ layout (std140) uniform LineInterpolationUBO { lowp float u_gapwidth_t; lowp float u_offset_t; lowp float u_width_t; + highp vec2 interp_pad1; +}; - highp vec2 pad7; +layout (std140) uniform LineEvaluatedPropsUBO { + highp vec4 u_color; + lowp float u_blur; + lowp float u_opacity; + mediump float u_gapwidth; + lowp float u_offset; + mediump float u_width; + lowp float u_floorwidth; + highp float props_pad1; + highp float props_pad2; }; out vec2 v_normal; diff --git a/shaders/drawable.line_gradient.fragment.glsl b/shaders/drawable.line_gradient.fragment.glsl index 03b306401..f8bec3110 100644 --- a/shaders/drawable.line_gradient.fragment.glsl +++ b/shaders/drawable.line_gradient.fragment.glsl @@ -1,18 +1,7 @@ -layout (std140) uniform LineGradientUBO { +layout (std140) uniform LineGradientDrawableUBO { highp mat4 u_matrix; mediump float u_ratio; - lowp float pad2, pad3, pad4; -}; - -layout (std140) uniform LineGradientPropertiesUBO { - lowp float u_blur; - lowp float u_opacity; - mediump float u_gapwidth; - lowp float u_offset; - mediump float u_width; - - highp float pad5; - highp vec2 pad6; + lowp float drawable_pad1, drawable_pad2, drawable_pad3; }; layout (std140) uniform LineGradientInterpolationUBO { @@ -21,9 +10,20 @@ layout (std140) uniform LineGradientInterpolationUBO { lowp float u_gapwidth_t; lowp float u_offset_t; lowp float u_width_t; + highp float interp_pad1; + highp vec2 interp_pad2; +}; - highp float pad7; - highp vec2 pad8; +layout (std140) uniform LineEvaluatedPropsUBO { + highp vec4 u_color; + lowp float u_blur; + lowp float u_opacity; + mediump float u_gapwidth; + lowp float u_offset; + mediump float u_width; + lowp float u_floorwidth; + highp float props_pad1; + highp float props_pad2; }; uniform sampler2D u_image; diff --git a/shaders/drawable.line_gradient.vertex.glsl b/shaders/drawable.line_gradient.vertex.glsl index 5e212cd59..38ae13910 100644 --- a/shaders/drawable.line_gradient.vertex.glsl +++ b/shaders/drawable.line_gradient.vertex.glsl @@ -15,24 +15,13 @@ layout (location = 1) in vec4 a_data; layout (std140) uniform LineDynamicUBO { highp vec2 u_units_to_pixels; - lowp float pad0, pad1; + lowp float dynamic_pad1, dynamic_pad2; }; -layout (std140) uniform LineGradientUBO { +layout (std140) uniform LineGradientDrawableUBO { highp mat4 u_matrix; mediump float u_ratio; - lowp float pad2, pad3, pad4; -}; - -layout (std140) uniform LineGradientPropertiesUBO { - lowp float u_blur; - lowp float u_opacity; - mediump float u_gapwidth; - lowp float u_offset; - mediump float u_width; - - highp float pad5; - highp vec2 pad6; + lowp float drawable_pad1, drawable_pad2, drawable_pad3; }; layout (std140) uniform LineGradientInterpolationUBO { @@ -41,9 +30,20 @@ layout (std140) uniform LineGradientInterpolationUBO { lowp float u_gapwidth_t; lowp float u_offset_t; lowp float u_width_t; + highp float interp_pad1; + highp vec2 interp_pad2; +}; - highp float pad7; - highp vec2 pad8; +layout (std140) uniform LineEvaluatedPropsUBO { + highp vec4 u_color; + lowp float u_blur; + lowp float u_opacity; + mediump float u_gapwidth; + lowp float u_offset; + mediump float u_width; + lowp float u_floorwidth; + highp float props_pad1; + highp float props_pad2; }; out vec2 v_normal; diff --git a/shaders/drawable.line_pattern.fragment.glsl b/shaders/drawable.line_pattern.fragment.glsl index e049d70a4..cbe9b11f7 100644 --- a/shaders/drawable.line_pattern.fragment.glsl +++ b/shaders/drawable.line_pattern.fragment.glsl @@ -1,4 +1,4 @@ -layout (std140) uniform LinePatternUBO { +layout (std140) uniform LinePatternDrawableUBO { highp mat4 u_matrix; mediump vec4 u_scale; highp vec2 u_texsize; @@ -6,22 +6,6 @@ layout (std140) uniform LinePatternUBO { highp float u_fade; }; -layout (std140) uniform LinePatternPropertiesUBO { - lowp float u_blur; - lowp float u_opacity; - lowp float u_offset; - mediump float u_gapwidth; - mediump float u_width; - - highp float pad2; - highp vec2 pad3; -}; - -layout (std140) uniform LinePatternTilePropertiesUBO { - lowp vec4 u_pattern_from; - lowp vec4 u_pattern_to; -}; - layout (std140) uniform LinePatternInterpolationUBO { lowp float u_blur_t; lowp float u_opacity_t; @@ -30,8 +14,24 @@ layout (std140) uniform LinePatternInterpolationUBO { lowp float u_width_t; lowp float u_pattern_from_t; lowp float u_pattern_to_t; + highp float interp_pad1; +}; - highp float pad4; +layout (std140) uniform LinePatternTilePropertiesUBO { + lowp vec4 u_pattern_from; + lowp vec4 u_pattern_to; +}; + +layout (std140) uniform LineEvaluatedPropsUBO { + highp vec4 u_color; + lowp float u_blur; + lowp float u_opacity; + mediump float u_gapwidth; + lowp float u_offset; + mediump float u_width; + lowp float u_floorwidth; + highp float props_pad1; + highp float props_pad2; }; uniform sampler2D u_image; diff --git a/shaders/drawable.line_pattern.vertex.glsl b/shaders/drawable.line_pattern.vertex.glsl index e69bdd4bc..714440ad7 100644 --- a/shaders/drawable.line_pattern.vertex.glsl +++ b/shaders/drawable.line_pattern.vertex.glsl @@ -15,10 +15,10 @@ layout (location = 1) in vec4 a_data; layout (std140) uniform LineDynamicUBO { highp vec2 u_units_to_pixels; - lowp float pad0, pad1; + lowp float dynamic_pad1, dynamic_pad2; }; -layout (std140) uniform LinePatternUBO { +layout (std140) uniform LinePatternDrawableUBO { highp mat4 u_matrix; mediump vec4 u_scale; highp vec2 u_texsize; @@ -26,22 +26,6 @@ layout (std140) uniform LinePatternUBO { highp float u_fade; }; -layout (std140) uniform LinePatternPropertiesUBO { - lowp float u_blur; - lowp float u_opacity; - lowp float u_offset; - mediump float u_gapwidth; - mediump float u_width; - - highp float pad2; - highp vec2 pad3; -}; - -layout (std140) uniform LinePatternTilePropertiesUBO { - lowp vec4 u_pattern_from; - lowp vec4 u_pattern_to; -}; - layout (std140) uniform LinePatternInterpolationUBO { lowp float u_blur_t; lowp float u_opacity_t; @@ -50,8 +34,24 @@ layout (std140) uniform LinePatternInterpolationUBO { lowp float u_width_t; lowp float u_pattern_from_t; lowp float u_pattern_to_t; + highp float interp_pad1; +}; - highp float pad4; +layout (std140) uniform LinePatternTilePropertiesUBO { + lowp vec4 u_pattern_from; + lowp vec4 u_pattern_to; +}; + +layout (std140) uniform LineEvaluatedPropsUBO { + highp vec4 u_color; + lowp float u_blur; + lowp float u_opacity; + mediump float u_gapwidth; + lowp float u_offset; + mediump float u_width; + lowp float u_floorwidth; + highp float props_pad1; + highp float props_pad2; }; out vec2 v_normal; diff --git a/shaders/drawable.line_sdf.fragment.glsl b/shaders/drawable.line_sdf.fragment.glsl index 140b0c472..23405efd6 100644 --- a/shaders/drawable.line_sdf.fragment.glsl +++ b/shaders/drawable.line_sdf.fragment.glsl @@ -1,5 +1,5 @@ -layout (std140) uniform LineSDFUBO { +layout (std140) uniform LineSDFDrawableUBO { highp mat4 u_matrix; highp vec2 u_patternscale_a; highp vec2 u_patternscale_b; @@ -8,20 +8,7 @@ layout (std140) uniform LineSDFUBO { highp float u_tex_y_b; highp float u_sdfgamma; highp float u_mix; - - lowp float pad2, pad3, pad4; -}; - -layout (std140) uniform LineSDFPropertiesUBO { - highp vec4 u_color; - lowp float u_blur; - lowp float u_opacity; - mediump float u_gapwidth; - lowp float u_offset; - mediump float u_width; - lowp float u_floorwidth; - - highp vec2 pad5; + lowp float drawable_pad1, drawable_pad2, drawable_pad3; }; layout (std140) uniform LineSDFInterpolationUBO { @@ -32,8 +19,19 @@ layout (std140) uniform LineSDFInterpolationUBO { lowp float u_offset_t; lowp float u_width_t; lowp float u_floorwidth_t; + highp float interp_pad1; +}; - highp float pad6; +layout (std140) uniform LineEvaluatedPropsUBO { + highp vec4 u_color; + lowp float u_blur; + lowp float u_opacity; + mediump float u_gapwidth; + lowp float u_offset; + mediump float u_width; + lowp float u_floorwidth; + highp float props_pad1; + highp float props_pad2; }; uniform sampler2D u_image; diff --git a/shaders/drawable.line_sdf.vertex.glsl b/shaders/drawable.line_sdf.vertex.glsl index 7008e79e2..63cbd5127 100644 --- a/shaders/drawable.line_sdf.vertex.glsl +++ b/shaders/drawable.line_sdf.vertex.glsl @@ -15,10 +15,10 @@ layout (location = 1) in vec4 a_data; layout (std140) uniform LineDynamicUBO { highp vec2 u_units_to_pixels; - lowp float pad0, pad1; + lowp float dynamic_pad1, dynamic_pad2; }; -layout (std140) uniform LineSDFUBO { +layout (std140) uniform LineSDFDrawableUBO { highp mat4 u_matrix; highp vec2 u_patternscale_a; highp vec2 u_patternscale_b; @@ -27,19 +27,7 @@ layout (std140) uniform LineSDFUBO { highp float u_tex_y_b; highp float u_sdfgamma; highp float u_mix; - lowp float pad2, pad3, pad4; -}; - -layout (std140) uniform LineSDFPropertiesUBO { - highp vec4 u_color; - lowp float u_blur; - lowp float u_opacity; - mediump float u_gapwidth; - lowp float u_offset; - mediump float u_width; - lowp float u_floorwidth; - - highp vec2 pad5; + lowp float drawable_pad1, drawable_pad2, drawable_pad3; }; layout (std140) uniform LineSDFInterpolationUBO { @@ -50,8 +38,19 @@ layout (std140) uniform LineSDFInterpolationUBO { lowp float u_offset_t; lowp float u_width_t; lowp float u_floorwidth_t; + highp float interp_pad1; +}; - highp float pad6; +layout (std140) uniform LineEvaluatedPropsUBO { + highp vec4 u_color; + lowp float u_blur; + lowp float u_opacity; + mediump float u_gapwidth; + lowp float u_offset; + mediump float u_width; + lowp float u_floorwidth; + highp float props_pad1; + highp float props_pad2; }; out vec2 v_normal; diff --git a/shaders/drawable.raster.fragment.glsl b/shaders/drawable.raster.fragment.glsl index bc16dfd27..4264906f1 100644 --- a/shaders/drawable.raster.fragment.glsl +++ b/shaders/drawable.raster.fragment.glsl @@ -1,5 +1,4 @@ -layout (std140) uniform RasterDrawableUBO { - highp mat4 u_matrix; +layout (std140) uniform RasterEvaluatedPropsUBO { highp vec3 u_spin_weights; highp vec2 u_tl_parent; highp float u_scale_parent; @@ -10,8 +9,8 @@ layout (std140) uniform RasterDrawableUBO { highp float u_brightness_high; highp float u_saturation_factor; highp float u_contrast_factor; - highp float pad1; - highp float pad2; + highp float props_pad1; + highp float props_pad2; }; uniform sampler2D u_image0; uniform sampler2D u_image1; diff --git a/shaders/drawable.raster.vertex.glsl b/shaders/drawable.raster.vertex.glsl index 9cb2fce74..d227fb05f 100644 --- a/shaders/drawable.raster.vertex.glsl +++ b/shaders/drawable.raster.vertex.glsl @@ -1,5 +1,7 @@ layout (std140) uniform RasterDrawableUBO { highp mat4 u_matrix; +}; +layout (std140) uniform RasterEvaluatedPropsUBO { highp vec3 u_spin_weights; highp vec2 u_tl_parent; highp float u_scale_parent; @@ -10,8 +12,8 @@ layout (std140) uniform RasterDrawableUBO { highp float u_brightness_high; highp float u_saturation_factor; highp float u_contrast_factor; - highp float pad1; - highp float pad2; + highp float props_pad1; + highp float props_pad2; }; layout (location = 0) in vec2 a_pos; diff --git a/shaders/drawable.symbol_icon.fragment.glsl b/shaders/drawable.symbol_icon.fragment.glsl index 235217be1..e7cd065e2 100644 --- a/shaders/drawable.symbol_icon.fragment.glsl +++ b/shaders/drawable.symbol_icon.fragment.glsl @@ -1,21 +1,38 @@ uniform sampler2D u_texture; -layout (std140) uniform SymbolDrawablePaintUBO { - highp vec4 u_fill_color; - highp vec4 u_halo_color; - highp float u_opacity; - highp float u_halo_width; - highp float u_halo_blur; - highp float u_padding; -}; - -layout (std140) uniform SymbolDrawableInterpolateUBO { +layout (std140) uniform SymbolInterpolateUBO { highp float u_fill_color_t; highp float u_halo_color_t; highp float u_opacity_t; highp float u_halo_width_t; highp float u_halo_blur_t; - highp float u_pad4,u_pad5,u_pad6; + highp float interp_pad1, interp_pad2,interp_pad3; +}; + +layout (std140) uniform SymbolTilePropsUBO { + bool u_is_text; + bool u_is_halo; + bool u_pitch_with_map; + bool u_is_size_zoom_constant; + bool u_is_size_feature_constant; + highp float u_size_t; // used to interpolate between zoom stops when size is a composite function + highp float u_size; // used when size is both zoom and feature constant + bool tileprops_pad1; +}; + +layout (std140) uniform SymbolEvaluatedPropsUBO { + highp vec4 u_text_fill_color; + highp vec4 u_text_halo_color; + highp float u_text_opacity; + highp float u_text_halo_width; + highp float u_text_halo_blur; + highp float props_pad1; + highp vec4 u_icon_fill_color; + highp vec4 u_icon_halo_color; + highp float u_icon_opacity; + highp float u_icon_halo_width; + highp float u_icon_halo_blur; + highp float props_pad2; }; in vec2 v_tex; @@ -24,6 +41,8 @@ in float v_fade_opacity; #pragma mapbox: define lowp float opacity void main() { + highp float u_opacity = u_is_text ? u_text_opacity : u_icon_opacity; + #pragma mapbox: initialize lowp float opacity lowp float alpha = opacity * v_fade_opacity; diff --git a/shaders/drawable.symbol_icon.vertex.glsl b/shaders/drawable.symbol_icon.vertex.glsl index bd902925f..95bd7ea31 100644 --- a/shaders/drawable.symbol_icon.vertex.glsl +++ b/shaders/drawable.symbol_icon.vertex.glsl @@ -4,6 +4,13 @@ layout (location = 2) in vec4 a_pixeloffset; layout (location = 3) in vec3 a_projected_pos; layout (location = 4) in float a_fade_opacity; +layout (std140) uniform SymbolDynamicUBO { + highp float u_fade_change; + highp float u_camera_to_center_distance; + highp float u_aspect_ratio; + highp float dynamic_pad1; +}; + layout (std140) uniform SymbolDrawableUBO { highp mat4 u_matrix; highp mat4 u_label_plane_matrix; @@ -14,26 +21,10 @@ layout (std140) uniform SymbolDrawableUBO { highp float u_gamma_scale; bool u_rotate_symbol; - highp vec2 u_pad1; + highp vec2 drawable_pad1; }; -layout (std140) uniform SymbolDynamicUBO { - highp float u_fade_change; - highp float u_camera_to_center_distance; - highp float u_aspect_ratio; - highp float pad0; -}; - -layout (std140) uniform SymbolDrawablePaintUBO { - highp vec4 u_fill_color; - highp vec4 u_halo_color; - highp float u_opacity; - highp float u_halo_width; - highp float u_halo_blur; - highp float u_padding; -}; - -layout (std140) uniform SymbolDrawableTilePropsUBO { +layout (std140) uniform SymbolTilePropsUBO { bool u_is_text; bool u_is_halo; bool u_pitch_with_map; @@ -41,16 +32,31 @@ layout (std140) uniform SymbolDrawableTilePropsUBO { bool u_is_size_feature_constant; highp float u_size_t; // used to interpolate between zoom stops when size is a composite function highp float u_size; // used when size is both zoom and feature constant - bool u_pad3; + bool tileprops_pad1; }; -layout (std140) uniform SymbolDrawableInterpolateUBO { +layout (std140) uniform SymbolInterpolateUBO { highp float u_fill_color_t; highp float u_halo_color_t; highp float u_opacity_t; highp float u_halo_width_t; highp float u_halo_blur_t; - highp float u_pad4,u_pad5,u_pad6; + highp float interp_pad1, interp_pad2, interp_pad3; +}; + +layout (std140) uniform SymbolEvaluatedPropsUBO { + highp vec4 u_text_fill_color; + highp vec4 u_text_halo_color; + highp float u_text_opacity; + highp float u_text_halo_width; + highp float u_text_halo_blur; + highp float props_pad1; + highp vec4 u_icon_fill_color; + highp vec4 u_icon_halo_color; + highp float u_icon_opacity; + highp float u_icon_halo_width; + highp float u_icon_halo_blur; + highp float props_pad2; }; out vec2 v_tex; @@ -59,6 +65,8 @@ out float v_fade_opacity; #pragma mapbox: define lowp float opacity void main() { + highp float u_opacity = u_is_text ? u_text_opacity : u_icon_opacity; + #pragma mapbox: initialize lowp float opacity vec2 a_pos = a_pos_offset.xy; diff --git a/shaders/drawable.symbol_sdf.fragment.glsl b/shaders/drawable.symbol_sdf.fragment.glsl index a96bc3c25..1ed1867ec 100644 --- a/shaders/drawable.symbol_sdf.fragment.glsl +++ b/shaders/drawable.symbol_sdf.fragment.glsl @@ -1,5 +1,12 @@ #define SDF_PX 8.0 +layout (std140) uniform SymbolDynamicUBO { + highp float u_fade_change; + highp float u_camera_to_center_distance; + highp float u_aspect_ratio; + highp float dynamic_pad1; +}; + layout (std140) uniform SymbolDrawableUBO { highp mat4 u_matrix; highp mat4 u_label_plane_matrix; @@ -10,26 +17,10 @@ layout (std140) uniform SymbolDrawableUBO { highp float u_gamma_scale; bool u_rotate_symbol; - highp vec2 u_pad1; + highp vec2 drawable_pad1; }; -layout (std140) uniform SymbolDynamicUBO { - highp float u_fade_change; - highp float u_camera_to_center_distance; - highp float u_aspect_ratio; - highp float pad0; -}; - -layout (std140) uniform SymbolDrawablePaintUBO { - highp vec4 u_fill_color; - highp vec4 u_halo_color; - highp float u_opacity; - highp float u_halo_width; - highp float u_halo_blur; - highp float u_padding; -}; - -layout (std140) uniform SymbolDrawableTilePropsUBO { +layout (std140) uniform SymbolTilePropsUBO { bool u_is_text; bool u_is_halo; bool u_pitch_with_map; @@ -37,16 +28,31 @@ layout (std140) uniform SymbolDrawableTilePropsUBO { bool u_is_size_feature_constant; highp float u_size_t; // used to interpolate between zoom stops when size is a composite function highp float u_size; // used when size is both zoom and feature constant - bool u_pad3; + bool tileprops_pad1; }; -layout (std140) uniform SymbolDrawableInterpolateUBO { +layout (std140) uniform SymbolInterpolateUBO { highp float u_fill_color_t; highp float u_halo_color_t; highp float u_opacity_t; highp float u_halo_width_t; highp float u_halo_blur_t; - highp float u_pad4,u_pad5,u_pad6; + highp float interp_pad1, interp_pad2, interp_pad3; +}; + +layout (std140) uniform SymbolEvaluatedPropsUBO { + highp vec4 u_text_fill_color; + highp vec4 u_text_halo_color; + highp float u_text_opacity; + highp float u_text_halo_width; + highp float u_text_halo_blur; + highp float props_pad1; + highp vec4 u_icon_fill_color; + highp vec4 u_icon_halo_color; + highp float u_icon_opacity; + highp float u_icon_halo_width; + highp float u_icon_halo_blur; + highp float props_pad2; }; uniform sampler2D u_texture; @@ -61,6 +67,12 @@ in vec3 v_data1; #pragma mapbox: define lowp float halo_blur void main() { + highp vec4 u_fill_color = u_is_text ? u_text_fill_color : u_icon_fill_color; + highp vec4 u_halo_color = u_is_text ? u_text_halo_color : u_icon_halo_color; + highp float u_opacity = u_is_text ? u_text_opacity : u_icon_opacity; + highp float u_halo_width = u_is_text ? u_text_halo_width : u_icon_halo_width; + highp float u_halo_blur = u_is_text ? u_text_halo_blur : u_icon_halo_blur; + #pragma mapbox: initialize highp vec4 fill_color #pragma mapbox: initialize highp vec4 halo_color #pragma mapbox: initialize lowp float opacity diff --git a/shaders/drawable.symbol_sdf.vertex.glsl b/shaders/drawable.symbol_sdf.vertex.glsl index e7a5d85c5..948fe46ec 100644 --- a/shaders/drawable.symbol_sdf.vertex.glsl +++ b/shaders/drawable.symbol_sdf.vertex.glsl @@ -12,6 +12,13 @@ layout (location = 4) in float a_fade_opacity; // [ text-size(lowerZoomStop, feature), // text-size(upperZoomStop, feature) ] +layout (std140) uniform SymbolDynamicUBO { + highp float u_fade_change; + highp float u_camera_to_center_distance; + highp float u_aspect_ratio; + highp float dynamic_pad1; +}; + layout (std140) uniform SymbolDrawableUBO { highp mat4 u_matrix; highp mat4 u_label_plane_matrix; @@ -22,26 +29,10 @@ layout (std140) uniform SymbolDrawableUBO { highp float u_gamma_scale; bool u_rotate_symbol; - highp vec2 u_pad1; + highp vec2 drawable_pad1; }; -layout (std140) uniform SymbolDynamicUBO { - highp float u_fade_change; - highp float u_camera_to_center_distance; - highp float u_aspect_ratio; - highp float pad0; -}; - -layout (std140) uniform SymbolDrawablePaintUBO { - highp vec4 u_fill_color; - highp vec4 u_halo_color; - highp float u_opacity; - highp float u_halo_width; - highp float u_halo_blur; - highp float u_padding; -}; - -layout (std140) uniform SymbolDrawableTilePropsUBO { +layout (std140) uniform SymbolTilePropsUBO { bool u_is_text; bool u_is_halo; bool u_pitch_with_map; @@ -49,16 +40,31 @@ layout (std140) uniform SymbolDrawableTilePropsUBO { bool u_is_size_feature_constant; highp float u_size_t; // used to interpolate between zoom stops when size is a composite function highp float u_size; // used when size is both zoom and feature constant - bool u_pad3; + bool tileprops_pad1; }; -layout (std140) uniform SymbolDrawableInterpolateUBO { +layout (std140) uniform SymbolInterpolateUBO { highp float u_fill_color_t; highp float u_halo_color_t; highp float u_opacity_t; highp float u_halo_width_t; highp float u_halo_blur_t; - highp float u_pad4,u_pad5,u_pad6; + highp float interp_pad1, interp_pad2, interp_pad3; +}; + +layout (std140) uniform SymbolEvaluatedPropsUBO { + highp vec4 u_text_fill_color; + highp vec4 u_text_halo_color; + highp float u_text_opacity; + highp float u_text_halo_width; + highp float u_text_halo_blur; + highp float props_pad1; + highp vec4 u_icon_fill_color; + highp vec4 u_icon_halo_color; + highp float u_icon_opacity; + highp float u_icon_halo_width; + highp float u_icon_halo_blur; + highp float props_pad2; }; out vec2 v_data0; @@ -71,6 +77,12 @@ out vec3 v_data1; #pragma mapbox: define lowp float halo_blur void main() { + highp vec4 u_fill_color = u_is_text ? u_text_fill_color : u_icon_fill_color; + highp vec4 u_halo_color = u_is_text ? u_text_halo_color : u_icon_halo_color; + highp float u_opacity = u_is_text ? u_text_opacity : u_icon_opacity; + highp float u_halo_width = u_is_text ? u_text_halo_width : u_icon_halo_width; + highp float u_halo_blur = u_is_text ? u_text_halo_blur : u_icon_halo_blur; + #pragma mapbox: initialize highp vec4 fill_color #pragma mapbox: initialize highp vec4 halo_color #pragma mapbox: initialize lowp float opacity diff --git a/shaders/drawable.symbol_text_and_icon.fragment.glsl b/shaders/drawable.symbol_text_and_icon.fragment.glsl index c956d4daa..fead23007 100644 --- a/shaders/drawable.symbol_text_and_icon.fragment.glsl +++ b/shaders/drawable.symbol_text_and_icon.fragment.glsl @@ -3,6 +3,13 @@ #define SDF 1.0 #define ICON 0.0 +layout (std140) uniform SymbolDynamicUBO { + highp float u_fade_change; + highp float u_camera_to_center_distance; + highp float u_aspect_ratio; + highp float dynamic_pad1; +}; + layout (std140) uniform SymbolDrawableUBO { highp mat4 u_matrix; highp mat4 u_label_plane_matrix; @@ -13,26 +20,10 @@ layout (std140) uniform SymbolDrawableUBO { highp float u_gamma_scale; bool u_rotate_symbol; - highp vec2 u_pad1; + highp vec2 drawable_pad1; }; -layout (std140) uniform SymbolDynamicUBO { - highp float u_fade_change; - highp float u_camera_to_center_distance; - highp float u_aspect_ratio; - highp float pad0; -}; - -layout (std140) uniform SymbolDrawablePaintUBO { - highp vec4 u_fill_color; - highp vec4 u_halo_color; - highp float u_opacity; - highp float u_halo_width; - highp float u_halo_blur; - highp float u_padding; -}; - -layout (std140) uniform SymbolDrawableTilePropsUBO { +layout (std140) uniform SymbolTilePropsUBO { bool u_is_text; bool u_is_halo; bool u_pitch_with_map; @@ -40,16 +31,31 @@ layout (std140) uniform SymbolDrawableTilePropsUBO { bool u_is_size_feature_constant; highp float u_size_t; // used to interpolate between zoom stops when size is a composite function highp float u_size; // used when size is both zoom and feature constant - bool u_pad3; + bool tileprops_pad1; }; -layout (std140) uniform SymbolDrawableInterpolateUBO { +layout (std140) uniform SymbolInterpolateUBO { highp float u_fill_color_t; highp float u_halo_color_t; highp float u_opacity_t; highp float u_halo_width_t; highp float u_halo_blur_t; - highp float u_pad4,u_pad5,u_pad6; + highp float interp_pad1, interp_pad2,interp_pad3; +}; + +layout (std140) uniform SymbolEvaluatedPropsUBO { + highp vec4 u_text_fill_color; + highp vec4 u_text_halo_color; + highp float u_text_opacity; + highp float u_text_halo_width; + highp float u_text_halo_blur; + highp float props_pad1; + highp vec4 u_icon_fill_color; + highp vec4 u_icon_halo_color; + highp float u_icon_opacity; + highp float u_icon_halo_width; + highp float u_icon_halo_blur; + highp float props_pad2; }; uniform sampler2D u_texture; @@ -65,6 +71,12 @@ in vec4 v_data1; #pragma mapbox: define lowp float halo_blur void main() { + highp vec4 u_fill_color = u_is_text ? u_text_fill_color : u_icon_fill_color; + highp vec4 u_halo_color = u_is_text ? u_text_halo_color : u_icon_halo_color; + highp float u_opacity = u_is_text ? u_text_opacity : u_icon_opacity; + highp float u_halo_width = u_is_text ? u_text_halo_width : u_icon_halo_width; + highp float u_halo_blur = u_is_text ? u_text_halo_blur : u_icon_halo_blur; + #pragma mapbox: initialize highp vec4 fill_color #pragma mapbox: initialize highp vec4 halo_color #pragma mapbox: initialize lowp float opacity diff --git a/shaders/drawable.symbol_text_and_icon.vertex.glsl b/shaders/drawable.symbol_text_and_icon.vertex.glsl index 9390c584a..0eb5b70fd 100644 --- a/shaders/drawable.symbol_text_and_icon.vertex.glsl +++ b/shaders/drawable.symbol_text_and_icon.vertex.glsl @@ -11,6 +11,13 @@ layout (location = 3) in float a_fade_opacity; // [ text-size(lowerZoomStop, feature), // text-size(upperZoomStop, feature) ] +layout (std140) uniform SymbolDynamicUBO { + highp float u_fade_change; + highp float u_camera_to_center_distance; + highp float u_aspect_ratio; + highp float dynamic_pad1; +}; + layout (std140) uniform SymbolDrawableUBO { highp mat4 u_matrix; highp mat4 u_label_plane_matrix; @@ -21,26 +28,10 @@ layout (std140) uniform SymbolDrawableUBO { highp float u_gamma_scale; bool u_rotate_symbol; - highp vec2 u_pad1; + highp vec2 drawable_pad1; }; -layout (std140) uniform SymbolDynamicUBO { - highp float u_fade_change; - highp float u_camera_to_center_distance; - highp float u_aspect_ratio; - highp float pad0; -}; - -layout (std140) uniform SymbolDrawablePaintUBO { - highp vec4 u_fill_color; - highp vec4 u_halo_color; - highp float u_opacity; - highp float u_halo_width; - highp float u_halo_blur; - highp float u_padding; -}; - -layout (std140) uniform SymbolDrawableTilePropsUBO { +layout (std140) uniform SymbolTilePropsUBO { bool u_is_text; bool u_is_halo; bool u_pitch_with_map; @@ -48,16 +39,31 @@ layout (std140) uniform SymbolDrawableTilePropsUBO { bool u_is_size_feature_constant; highp float u_size_t; // used to interpolate between zoom stops when size is a composite function highp float u_size; // used when size is both zoom and feature constant - bool u_pad3; + bool tileprops_pad1; }; -layout (std140) uniform SymbolDrawableInterpolateUBO { +layout (std140) uniform SymbolInterpolateUBO { highp float u_fill_color_t; highp float u_halo_color_t; highp float u_opacity_t; highp float u_halo_width_t; highp float u_halo_blur_t; - highp float u_pad4,u_pad5,u_pad6; + highp float interp_pad1, interp_pad2, interp_pad3; +}; + +layout (std140) uniform SymbolEvaluatedPropsUBO { + highp vec4 u_text_fill_color; + highp vec4 u_text_halo_color; + highp float u_text_opacity; + highp float u_text_halo_width; + highp float u_text_halo_blur; + highp float props_pad1; + highp vec4 u_icon_fill_color; + highp vec4 u_icon_halo_color; + highp float u_icon_opacity; + highp float u_icon_halo_width; + highp float u_icon_halo_blur; + highp float props_pad2; }; out vec4 v_data0; @@ -70,6 +76,12 @@ out vec4 v_data1; #pragma mapbox: define lowp float halo_blur void main() { + highp vec4 u_fill_color = u_is_text ? u_text_fill_color : u_icon_fill_color; + highp vec4 u_halo_color = u_is_text ? u_text_halo_color : u_icon_halo_color; + highp float u_opacity = u_is_text ? u_text_opacity : u_icon_opacity; + highp float u_halo_width = u_is_text ? u_text_halo_width : u_icon_halo_width; + highp float u_halo_blur = u_is_text ? u_text_halo_blur : u_icon_halo_blur; + #pragma mapbox: initialize highp vec4 fill_color #pragma mapbox: initialize highp vec4 halo_color #pragma mapbox: initialize lowp float opacity diff --git a/src/mbgl/gl/drawable_gl.cpp b/src/mbgl/gl/drawable_gl.cpp index f90d35326..2030accbf 100644 --- a/src/mbgl/gl/drawable_gl.cpp +++ b/src/mbgl/gl/drawable_gl.cpp @@ -108,17 +108,9 @@ void DrawableGL::bindUniformBuffers() const { const auto& block = uniformBlocks.get(id); if (!block) continue; const auto& uniformBuffer = getUniformBuffers().get(id); - assert(uniformBuffer && "UBO missing, drawable skipped"); - if (!uniformBuffer) { - using namespace std::string_literals; - const auto tileIDStr = getTileID() ? util::toString(*getTileID()) : ""; - Log::Error(Event::General, - "bindUniformBuffers: UBO "s + util::toString(block->getIndex()) + " not found for " + - util::toString(getID()) + " / " + getName() + " / " + tileIDStr + ". skipping."); - assert(false); - continue; + if (uniformBuffer) { + block->bindBuffer(*uniformBuffer); } - block->bindBuffer(*uniformBuffer); } } } @@ -128,7 +120,9 @@ void DrawableGL::unbindUniformBuffers() const { const auto& uniformBlocks = shader->getUniformBlocks(); for (size_t id = 0; id < uniformBlocks.allocatedSize(); id++) { const auto& block = uniformBlocks.get(id); - if (block) { + if (!block) continue; + const auto& uniformBuffer = getUniformBuffers().get(id); + if (uniformBuffer) { block->unbindBuffer(); } } diff --git a/src/mbgl/gl/layer_group_gl.cpp b/src/mbgl/gl/layer_group_gl.cpp index be1a993ea..3e452e6eb 100644 --- a/src/mbgl/gl/layer_group_gl.cpp +++ b/src/mbgl/gl/layer_group_gl.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -13,6 +14,8 @@ namespace mbgl { namespace gl { +using namespace platform; + TileLayerGroupGL::TileLayerGroupGL(int32_t layerIndex_, std::size_t initialCapacity, std::string name_) : TileLayerGroup(layerIndex_, initialCapacity, std::move(name_)) {} @@ -90,6 +93,8 @@ void TileLayerGroupGL::render(RenderOrchestrator&, PaintParameters& parameters) const auto debugGroupRender = parameters.encoder->createDebugGroup(label_render.c_str()); #endif + bindUniformBuffers(); + visitDrawables([&](gfx::Drawable& drawable) { if (!drawable.getEnabled() || !drawable.hasRenderPass(parameters.pass)) { return; @@ -118,6 +123,31 @@ void TileLayerGroupGL::render(RenderOrchestrator&, PaintParameters& parameters) drawable.draw(parameters); }); + + unbindUniformBuffers(); +} + +void TileLayerGroupGL::bindUniformBuffers() const { + for (size_t id = 0; id < uniformBuffers.allocatedSize(); id++) { + const auto& uniformBuffer = uniformBuffers.get(id); + if (!uniformBuffer) continue; + GLint binding = static_cast(id); + const auto& uniformBufferGL = static_cast(*uniformBuffer); + MBGL_CHECK_ERROR(glBindBufferRange(GL_UNIFORM_BUFFER, + binding, + uniformBufferGL.getID(), + uniformBufferGL.getManagedBuffer().getBindingOffset(), + uniformBufferGL.getSize())); + } +} + +void TileLayerGroupGL::unbindUniformBuffers() const { + for (size_t id = 0; id < uniformBuffers.allocatedSize(); id++) { + const auto& uniformBuffer = uniformBuffers.get(id); + if (!uniformBuffer) continue; + GLint binding = static_cast(id); + MBGL_CHECK_ERROR(glBindBufferBase(GL_UNIFORM_BUFFER, binding, 0)); + } } LayerGroupGL::LayerGroupGL(int32_t layerIndex_, std::size_t initialCapacity, std::string name_) @@ -148,6 +178,8 @@ void LayerGroupGL::render(RenderOrchestrator&, PaintParameters& parameters) { return; } + bindUniformBuffers(); + visitDrawables([&](gfx::Drawable& drawable) { if (!drawable.getEnabled() || !drawable.hasRenderPass(parameters.pass)) { return; @@ -163,6 +195,31 @@ void LayerGroupGL::render(RenderOrchestrator&, PaintParameters& parameters) { drawable.draw(parameters); }); + + unbindUniformBuffers(); +} + +void LayerGroupGL::bindUniformBuffers() const { + for (size_t id = 0; id < uniformBuffers.allocatedSize(); id++) { + const auto& uniformBuffer = uniformBuffers.get(id); + if (!uniformBuffer) continue; + GLint binding = static_cast(id); + const auto& uniformBufferGL = static_cast(*uniformBuffer); + MBGL_CHECK_ERROR(glBindBufferRange(GL_UNIFORM_BUFFER, + binding, + uniformBufferGL.getID(), + uniformBufferGL.getManagedBuffer().getBindingOffset(), + uniformBufferGL.getSize())); + } +} + +void LayerGroupGL::unbindUniformBuffers() const { + for (size_t id = 0; id < uniformBuffers.allocatedSize(); id++) { + const auto& uniformBuffer = uniformBuffers.get(id); + if (!uniformBuffer) continue; + GLint binding = static_cast(id); + MBGL_CHECK_ERROR(glBindBufferBase(GL_UNIFORM_BUFFER, binding, 0)); + } } } // namespace gl diff --git a/src/mbgl/mtl/context.cpp b/src/mbgl/mtl/context.cpp index 511ae3b53..0d1e036de 100644 --- a/src/mbgl/mtl/context.cpp +++ b/src/mbgl/mtl/context.cpp @@ -347,8 +347,8 @@ bool Context::renderTileClippingMasks(gfx::RenderPass& renderPass, layoutDesc->setStride(static_cast(vertexSize)); layoutDesc->setStepFunction(MTL::VertexStepFunctionPerVertex); layoutDesc->setStepRate(1); - vertDesc->attributes()->setObject(attribDesc.get(), 0); - vertDesc->layouts()->setObject(layoutDesc.get(), 0); + vertDesc->attributes()->setObject(attribDesc.get(), ShaderClass::attributes[0].index); + vertDesc->layouts()->setObject(layoutDesc.get(), ShaderClass::attributes[0].index); // Create a render pipeline state, telling Metal how to render the primitives const auto& renderPassDescriptor = mtlRenderPass.getDescriptor(); diff --git a/src/mbgl/mtl/drawable.cpp b/src/mbgl/mtl/drawable.cpp index 9dd20a18c..b305ba036 100644 --- a/src/mbgl/mtl/drawable.cpp +++ b/src/mbgl/mtl/drawable.cpp @@ -387,7 +387,6 @@ void Drawable::bindUniformBuffers(RenderPass& renderPass) const noexcept { const auto& block = uniformBlocks.get(id); if (!block) continue; const auto& uniformBuffer = getUniformBuffers().get(id); - assert(uniformBuffer && "UBO missing, drawable skipped"); if (uniformBuffer) { const auto& buffer = static_cast(*uniformBuffer.get()); const auto& resource = buffer.getBufferResource(); diff --git a/src/mbgl/mtl/layer_group.cpp b/src/mbgl/mtl/layer_group.cpp index 6c1c54566..962c8a91b 100644 --- a/src/mbgl/mtl/layer_group.cpp +++ b/src/mbgl/mtl/layer_group.cpp @@ -1,12 +1,12 @@ #include #include -#include #include #include #include #include #include +#include #include #include #include @@ -35,7 +35,7 @@ void LayerGroup::upload(gfx::UploadPass& uploadPass) { } void LayerGroup::render(RenderOrchestrator&, PaintParameters& parameters) { - if (!enabled) { + if (!enabled || !getDrawableCount() || !parameters.renderPass) { return; } @@ -43,6 +43,11 @@ void LayerGroup::render(RenderOrchestrator&, PaintParameters& parameters) { const auto debugGroup = parameters.encoder->createDebugGroup(getName() + "-render"); #endif + auto& context = static_cast(parameters.context); + auto& renderPass = static_cast(*parameters.renderPass); + + bindUniformBuffers(renderPass); + visitDrawables([&](gfx::Drawable& drawable) { if (!drawable.getEnabled() || !drawable.hasRenderPass(parameters.pass)) { return; @@ -54,6 +59,19 @@ void LayerGroup::render(RenderOrchestrator&, PaintParameters& parameters) { drawable.draw(parameters); }); + + unbindUniformBuffers(renderPass); +} + +void LayerGroup::bindUniformBuffers(RenderPass& renderPass) const noexcept { + for (size_t id = 0; id < uniformBuffers.allocatedSize(); id++) { + const auto& uniformBuffer = uniformBuffers.get(id); + if (!uniformBuffer) continue; + const auto& buffer = static_cast(*uniformBuffer.get()); + const auto& resource = buffer.getBufferResource(); + renderPass.bindVertex(resource, 0, id); + renderPass.bindFragment(resource, 0, id); + } } } // namespace mtl diff --git a/src/mbgl/mtl/renderer_backend.cpp b/src/mbgl/mtl/renderer_backend.cpp index 796d36a20..6af61d9dc 100644 --- a/src/mbgl/mtl/renderer_backend.cpp +++ b/src/mbgl/mtl/renderer_backend.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include diff --git a/src/mbgl/mtl/tile_layer_group.cpp b/src/mbgl/mtl/tile_layer_group.cpp index 678b8953b..174570f59 100644 --- a/src/mbgl/mtl/tile_layer_group.cpp +++ b/src/mbgl/mtl/tile_layer_group.cpp @@ -1,7 +1,6 @@ #include #include -#include #include #include #include @@ -43,7 +42,7 @@ void TileLayerGroup::render(RenderOrchestrator&, PaintParameters& parameters) { } auto& context = static_cast(parameters.context); - auto& renderPass = static_cast(*parameters.renderPass); + auto& renderPass = static_cast(*parameters.renderPass); const auto& encoder = renderPass.getMetalEncoder(); const auto& renderable = renderPass.getDescriptor().renderable; @@ -121,6 +120,8 @@ void TileLayerGroup::render(RenderOrchestrator&, PaintParameters& parameters) { parameters.renderTileClippingMasks(stencilTiles); } + bindUniformBuffers(renderPass); + visitDrawables([&](gfx::Drawable& drawable) { if (!drawable.getEnabled() || !drawable.hasRenderPass(parameters.pass)) { return; @@ -140,6 +141,19 @@ void TileLayerGroup::render(RenderOrchestrator&, PaintParameters& parameters) { drawable.draw(parameters); }); + + unbindUniformBuffers(renderPass); +} + +void TileLayerGroup::bindUniformBuffers(RenderPass& renderPass) const noexcept { + for (size_t id = 0; id < uniformBuffers.allocatedSize(); id++) { + const auto& uniformBuffer = uniformBuffers.get(id); + if (!uniformBuffer) continue; + const auto& buffer = static_cast(*uniformBuffer.get()); + const auto& resource = buffer.getBufferResource(); + renderPass.bindVertex(resource, 0, id); + renderPass.bindFragment(resource, 0, id); + } } } // namespace mtl diff --git a/src/mbgl/renderer/layers/background_layer_tweaker.cpp b/src/mbgl/renderer/layers/background_layer_tweaker.cpp index a7eb61f93..d0c41d329 100644 --- a/src/mbgl/renderer/layers/background_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/background_layer_tweaker.cpp @@ -50,6 +50,35 @@ void BackgroundLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintPara // properties are re-evaluated every time propertiesUpdated = false; + auto& layerUniforms = layerGroup.mutableUniformBuffers(); + + if (hasPattern) { + const Size atlasSize = parameters.patternAtlas.getPixelSize(); + + const BackgroundPatternLayerUBO layerUBO = { + /* .pattern_tl_a = */ util::cast(imagePosA->tl()), + /* .pattern_br_a = */ util::cast(imagePosA->br()), + /* .pattern_tl_b = */ util::cast(imagePosB->tl()), + /* .pattern_br_b = */ util::cast(imagePosB->br()), + /* .texsize = */ {static_cast(atlasSize.width), static_cast(atlasSize.height)}, + /* .pattern_size_a = */ imagePosA->displaySize(), + /* .pattern_size_b = */ imagePosB->displaySize(), + /* .scale_a = */ crossfade.fromScale, + /* .scale_b = */ crossfade.toScale, + /* .mix = */ crossfade.t, + /* .opacity = */ evaluated.get(), + /* .pad1/2 = */ 0, + 0}; + layerUniforms.createOrUpdate(idBackgroundLayerUBO, &layerUBO, context); + } else { + const BackgroundLayerUBO layerUBO = {/* .color = */ evaluated.get(), + /* .opacity = */ evaluated.get(), + /* .pad1/2/3 = */ 0, + 0, + 0}; + layerUniforms.createOrUpdate(idBackgroundLayerUBO, &layerUBO, context); + } + visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { assert(drawable.getTileID()); if (!drawable.getTileID() || !checkTweakDrawable(drawable)) { @@ -64,10 +93,7 @@ void BackgroundLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintPara const auto matrix = getTileMatrix( tileID, parameters, {0.f, 0.f}, TranslateAnchorType::Viewport, false, false, drawable); - const BackgroundDrawableUBO drawableUBO = {/* .matrix = */ util::cast(matrix)}; - - auto& uniforms = drawable.mutableUniformBuffers(); - uniforms.createOrUpdate(idBackgroundDrawableUBO, &drawableUBO, context); + auto& drawableUniforms = drawable.mutableUniformBuffers(); if (hasPattern) { if (const auto& tex = parameters.patternAtlas.texture()) { @@ -76,44 +102,25 @@ void BackgroundLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintPara drawable.setTexture(tex, idBackgroundImageTexture); } - // from BackgroundPatternProgram::layoutUniformValues const int32_t tileSizeAtNearestZoom = static_cast( util::tileSize_D * state.zoomScale(state.getIntegerZoom() - tileID.canonical.z)); const int32_t pixelX = static_cast( tileSizeAtNearestZoom * (tileID.canonical.x + tileID.wrap * state.zoomScale(tileID.canonical.z))); const int32_t pixelY = tileSizeAtNearestZoom * tileID.canonical.y; - const Size atlasSize = parameters.patternAtlas.getPixelSize(); const auto pixToTile = tileID.pixelsToTileUnits(1.0f, state.getIntegerZoom()); - const BackgroundPatternLayerUBO layerUBO = { - /* .pattern_tl_a = */ util::cast(imagePosA->tl()), - /* .pattern_br_a = */ util::cast(imagePosA->br()), - /* .pattern_tl_b = */ util::cast(imagePosB->tl()), - /* .pattern_br_b = */ util::cast(imagePosB->br()), - /* .texsize = */ {static_cast(atlasSize.width), static_cast(atlasSize.height)}, - /* .pattern_size_a = */ imagePosA->displaySize(), - /* .pattern_size_b = */ imagePosB->displaySize(), + const BackgroundPatternDrawableUBO drawableUBO = { + /* .matrix = */ util::cast(matrix), /* .pixel_coord_upper = */ {static_cast(pixelX >> 16), static_cast(pixelY >> 16)}, /* .pixel_coord_lower = */ {static_cast(pixelX & 0xFFFF), static_cast(pixelY & 0xFFFF)}, /* .tile_units_to_pixels = */ (pixToTile != 0) ? 1.0f / pixToTile : 0.0f, - /* .scale_a = */ crossfade.fromScale, - /* .scale_b = */ crossfade.toScale, - /* .mix = */ crossfade.t, - /* .opacity = */ evaluated.get(), - /* .pad1 = */ 0, - }; - uniforms.createOrUpdate(idBackgroundLayerUBO, &layerUBO, context); + /* .pad1/2/3 = */ 0, + 0, + 0}; + drawableUniforms.createOrUpdate(idBackgroundDrawableUBO, &drawableUBO, context); } else { - // UBOs can be shared - if (!backgroundLayerBuffer) { - const BackgroundLayerUBO layerUBO = {/* .color = */ evaluated.get(), - /* .opacity = */ evaluated.get(), - /* .pad1/2/3 = */ 0, - 0, - 0}; - backgroundLayerBuffer = context.createUniformBuffer(&layerUBO, sizeof(layerUBO)); - } - uniforms.set(idBackgroundLayerUBO, backgroundLayerBuffer); + const BackgroundDrawableUBO drawableUBO = {/* .matrix = */ util::cast(matrix)}; + drawableUniforms.createOrUpdate(idBackgroundDrawableUBO, &drawableUBO, context); } }); } diff --git a/src/mbgl/renderer/layers/background_layer_tweaker.hpp b/src/mbgl/renderer/layers/background_layer_tweaker.hpp index 8d970171b..b696e3cd5 100644 --- a/src/mbgl/renderer/layers/background_layer_tweaker.hpp +++ b/src/mbgl/renderer/layers/background_layer_tweaker.hpp @@ -26,9 +26,6 @@ public: ~BackgroundLayerTweaker() override = default; void execute(LayerGroupBase&, const PaintParameters&) override; - -protected: - gfx::UniformBufferPtr backgroundLayerBuffer; }; } // namespace mbgl diff --git a/src/mbgl/renderer/layers/circle_layer_tweaker.cpp b/src/mbgl/renderer/layers/circle_layer_tweaker.cpp index 712b5fa82..6c522ee9a 100644 --- a/src/mbgl/renderer/layers/circle_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/circle_layer_tweaker.cpp @@ -40,7 +40,9 @@ void CircleLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete /* .padding = */ 0, 0, 0}; - context.emplaceOrUpdateUniformBuffer(paintParamsUniformBuffer, &paintParamsUBO); + + auto& layerUniforms = layerGroup.mutableUniformBuffers(); + layerUniforms.createOrUpdate(idCirclePaintParamsUBO, &paintParamsUBO, context); const auto zoom = parameters.state.getZoom(); const bool pitchWithMap = evaluated.get() == AlignmentType::Map; @@ -60,8 +62,9 @@ void CircleLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete /* .pitch_with_map = */ pitchWithMap, /* .padding = */ 0}; context.emplaceOrUpdateUniformBuffer(evaluatedPropsUniformBuffer, &evaluatedPropsUBO); + propertiesUpdated = false; } - propertiesUpdated = false; + layerUniforms.set(idCircleEvaluatedPropsUBO, evaluatedPropsUniformBuffer); visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { assert(drawable.getTileID() || !"Circles only render with tiles"); @@ -70,10 +73,6 @@ void CircleLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete } const UnwrappedTileID tileID = drawable.getTileID()->toUnwrapped(); - auto& uniforms = drawable.mutableUniformBuffers(); - uniforms.set(idCirclePaintParamsUBO, paintParamsUniformBuffer); - uniforms.set(idCircleEvaluatedPropsUBO, evaluatedPropsUniformBuffer); - const auto& translation = evaluated.get(); const auto anchor = evaluated.get(); constexpr bool inViewportPixelUnits = false; // from RenderTile::translatedMatrix @@ -90,7 +89,8 @@ void CircleLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete /* .extrude_scale = */ extrudeScale, /* .padding = */ 0}; - uniforms.createOrUpdate(idCircleDrawableUBO, &drawableUBO, context); + auto& drawableUniforms = drawable.mutableUniformBuffers(); + drawableUniforms.createOrUpdate(idCircleDrawableUBO, &drawableUBO, context); }); } diff --git a/src/mbgl/renderer/layers/circle_layer_tweaker.hpp b/src/mbgl/renderer/layers/circle_layer_tweaker.hpp index bf58bb82d..30a3e7ee1 100644 --- a/src/mbgl/renderer/layers/circle_layer_tweaker.hpp +++ b/src/mbgl/renderer/layers/circle_layer_tweaker.hpp @@ -19,7 +19,6 @@ public: void execute(LayerGroupBase&, const PaintParameters&) override; protected: - gfx::UniformBufferPtr paintParamsUniformBuffer; gfx::UniformBufferPtr evaluatedPropsUniformBuffer; }; diff --git a/src/mbgl/renderer/layers/collision_layer_tweaker.cpp b/src/mbgl/renderer/layers/collision_layer_tweaker.cpp index 53aed5a54..d358c86e9 100644 --- a/src/mbgl/renderer/layers/collision_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/collision_layer_tweaker.cpp @@ -33,6 +33,8 @@ void CollisionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParam const auto debugGroup = parameters.encoder->createDebugGroup(label.c_str()); #endif + propertiesUpdated = false; + visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { if (!drawable.getTileID() || !drawable.getData() || !checkTweakDrawable(drawable)) { return; @@ -62,8 +64,8 @@ void CollisionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParam /*.camera_to_center_distance*/ parameters.state.getCameraToCenterDistance(), /*.overscale_factor*/ static_cast(drawable.getTileID()->overscaleFactor())}; - auto& uniforms = drawable.mutableUniformBuffers(); - uniforms.createOrUpdate(idCollisionUBO, &drawableUBO, context); + auto& drawableUniforms = drawable.mutableUniformBuffers(); + drawableUniforms.createOrUpdate(idCollisionUBO, &drawableUBO, context); }); } diff --git a/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp b/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp index f93da13d0..ebee5a80f 100644 --- a/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp @@ -43,7 +43,7 @@ void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintP // UBO depends on more than just evaluated properties, so we need to update every time, // but the resulting buffer can be shared across all the drawables from the layer. - const FillExtrusionDrawablePropsUBO paramsUBO = { + const FillExtrusionPropsUBO propsUBO = { /* .color = */ constOrDefault(evaluated), /* .light_color = */ FillExtrusionProgram::lightColor(parameters.evaluatedLight), /* .pad = */ 0, @@ -57,7 +57,9 @@ void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintP /* .pad = */ 0, 0, 0}; - context.emplaceOrUpdateUniformBuffer(propsBuffer, ¶msUBO); + auto& layerUniforms = layerGroup.mutableUniformBuffers(); + layerUniforms.createOrUpdate(idFillExtrusionPropsUBO, &propsUBO, context); + propertiesUpdated = false; visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { @@ -66,10 +68,6 @@ void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintP } const UnwrappedTileID tileID = drawable.getTileID()->toUnwrapped(); - - auto& uniforms = drawable.mutableUniformBuffers(); - uniforms.set(idFillExtrusionDrawablePropsUBO, propsBuffer); - const auto& translation = evaluated.get(); const auto anchor = evaluated.get(); constexpr bool inViewportPixelUnits = false; // from RenderTile::translatedMatrix @@ -102,7 +100,8 @@ void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintP /* .height_factor = */ heightFactor, /* .pad = */ 0}; - uniforms.createOrUpdate(idFillExtrusionDrawableUBO, &drawableUBO, context); + auto& drawableUniforms = drawable.mutableUniformBuffers(); + drawableUniforms.createOrUpdate(idFillExtrusionDrawableUBO, &drawableUBO, context); }); } diff --git a/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.hpp b/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.hpp index 6ada99854..7bc7a2d1b 100644 --- a/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.hpp +++ b/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.hpp @@ -20,12 +20,7 @@ public: void execute(LayerGroupBase&, const PaintParameters&) override; private: - gfx::UniformBufferPtr propsBuffer; - -#if MLN_RENDER_BACKEND_METAL - gfx::UniformBufferPtr permutationUniformBuffer; - gfx::UniformBufferPtr expressionUniformBuffer; -#endif // MLN_RENDER_BACKEND_METAL + gfx::UniformBufferPtr evaluatedPropsUniformBuffer; }; } // namespace mbgl diff --git a/src/mbgl/renderer/layers/fill_layer_tweaker.cpp b/src/mbgl/renderer/layers/fill_layer_tweaker.cpp index 625d8a63c..9763a274c 100644 --- a/src/mbgl/renderer/layers/fill_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/fill_layer_tweaker.cpp @@ -40,81 +40,20 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters const auto debugGroup = parameters.encoder->createDebugGroup(label.c_str()); #endif - if (propertiesUpdated) { - fillUniformBufferUpdated = true; - fillOutlineUniformBufferUpdated = true; - fillPatternUniformBufferUpdated = true; - fillOutlinePatternUniformBufferUpdated = true; - fillOutlineTriangulatedUniformBufferUpdated = true; + if (!evaluatedPropsUniformBuffer || propertiesUpdated) { + const FillEvaluatedPropsUBO propsUBO = { + /* .color = */ evaluated.get().constantOr(FillColor::defaultValue()), + /* .outline_color = */ evaluated.get().constantOr(FillOutlineColor::defaultValue()), + /* .opacity = */ evaluated.get().constantOr(FillOpacity::defaultValue()), + /* .fade = */ crossfade.t, + /* .width = */ 1.f, + 0, + }; + context.emplaceOrUpdateUniformBuffer(evaluatedPropsUniformBuffer, &propsUBO); propertiesUpdated = false; } - - const auto UpdateFillUniformBuffers = [&]() { - if (!fillPropsUniformBuffer || fillUniformBufferUpdated) { - const FillEvaluatedPropsUBO paramsUBO = { - /* .color = */ evaluated.get().constantOr(FillColor::defaultValue()), - /* .opacity = */ evaluated.get().constantOr(FillOpacity::defaultValue()), - 0, - 0, - 0, - }; - context.emplaceOrUpdateUniformBuffer(fillPropsUniformBuffer, ¶msUBO); - fillUniformBufferUpdated = false; - } - }; - - const auto UpdateFillOutlineUniformBuffers = [&]() { - if (!fillOutlinePropsUniformBuffer || fillOutlineUniformBufferUpdated) { - const FillOutlineEvaluatedPropsUBO paramsUBO = { - /* .outline_color = */ evaluated.get().constantOr(FillOutlineColor::defaultValue()), - /* .opacity = */ evaluated.get().constantOr(FillOpacity::defaultValue()), - 0, - 0, - 0, - }; - context.emplaceOrUpdateUniformBuffer(fillOutlinePropsUniformBuffer, ¶msUBO); - fillOutlineUniformBufferUpdated = false; - } - }; - - const auto UpdateFillPatternUniformBuffers = [&]() { - if (!fillPatternPropsUniformBuffer || fillPatternUniformBufferUpdated) { - const FillPatternEvaluatedPropsUBO paramsUBO = { - /* .opacity = */ evaluated.get().constantOr(FillOpacity::defaultValue()), - /* .fade = */ crossfade.t, - 0, - 0, - }; - context.emplaceOrUpdateUniformBuffer(fillPatternPropsUniformBuffer, ¶msUBO); - fillPatternUniformBufferUpdated = false; - } - }; - - const auto UpdateFillOutlinePatternUniformBuffers = [&]() { - if (!fillOutlinePatternPropsUniformBuffer || fillOutlinePatternUniformBufferUpdated) { - const FillOutlinePatternEvaluatedPropsUBO paramsUBO = { - /* .opacity = */ evaluated.get().constantOr(FillOpacity::defaultValue()), - /* .fade = */ crossfade.t, - 0, - 0, - }; - context.emplaceOrUpdateUniformBuffer(fillOutlinePatternPropsUniformBuffer, ¶msUBO); - fillOutlinePatternUniformBufferUpdated = false; - } - }; - - const auto UpdateFillOutlineTriangulatedUniformBuffers = [&]() { - if (!fillOutlineTriangulatedUniformBuffer || fillOutlineTriangulatedUniformBufferUpdated) { - const shaders::FillOutlineTriangulatedPropertiesUBO paramsUBO = { - /* .color = */ evaluated.get().constantOr(FillOutlineColor::defaultValue()), - /* .opacity = */ evaluated.get().constantOr(FillOpacity::defaultValue()), - /* .width = */ 1.f, - /* .ratio = */ 0, - 0}; - context.emplaceOrUpdateUniformBuffer(fillOutlineTriangulatedUniformBuffer, ¶msUBO); - fillOutlineTriangulatedUniformBufferUpdated = false; - } - }; + auto& layerUniforms = layerGroup.mutableUniformBuffers(); + layerUniforms.set(idFillEvaluatedPropsUBO, evaluatedPropsUniformBuffer); const auto& translation = evaluated.get(); const auto anchor = evaluated.get(); @@ -150,35 +89,23 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters textureSize = tex->getSize(); } - auto& uniforms = drawable.mutableUniformBuffers(); + auto& drawableUniforms = drawable.mutableUniformBuffers(); switch (static_cast(drawable.getType())) { case RenderFillLayer::FillVariant::Fill: { - UpdateFillUniformBuffers(); - - uniforms.set(idFillEvaluatedPropsUBO, fillPropsUniformBuffer); - const FillDrawableUBO drawableUBO = {/*.matrix=*/util::cast(matrix)}; - uniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context); + drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context); break; } case RenderFillLayer::FillVariant::FillOutline: { - UpdateFillOutlineUniformBuffers(); - - uniforms.set(idFillOutlineEvaluatedPropsUBO, fillOutlinePropsUniformBuffer); - const FillOutlineDrawableUBO drawableUBO = { /*.matrix=*/util::cast(matrix), /*.world=*/{(float)renderableSize.width, (float)renderableSize.height}, /* pad1 */ 0, /* pad2 */ 0}; - uniforms.createOrUpdate(idFillOutlineDrawableUBO, &drawableUBO, context); + drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context); break; } case RenderFillLayer::FillVariant::FillPattern: { - UpdateFillPatternUniformBuffers(); - - uniforms.set(idFillPatternEvaluatedPropsUBO, fillPatternPropsUniformBuffer); - const FillPatternDrawableUBO drawableUBO = { /*.matrix=*/util::cast(matrix), /*.scale=*/{pixelRatio, tileRatio, crossfade.fromScale, crossfade.toScale}, @@ -188,14 +115,10 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters 0, 0, }; - uniforms.createOrUpdate(idFillPatternDrawableUBO, &drawableUBO, context); + drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context); break; } case RenderFillLayer::FillVariant::FillOutlinePattern: { - UpdateFillOutlinePatternUniformBuffers(); - - uniforms.set(idFillOutlinePatternEvaluatedPropsUBO, fillOutlinePatternPropsUniformBuffer); - const FillOutlinePatternDrawableUBO drawableUBO = { /*.matrix=*/util::cast(matrix), /*.scale=*/{pixelRatio, tileRatio, crossfade.fromScale, crossfade.toScale}, @@ -204,20 +127,16 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters /*.pixel_coord_lower=*/{static_cast(pixelX & 0xFFFF), static_cast(pixelY & 0xFFFF)}, /*.texsize=*/{static_cast(textureSize.width), static_cast(textureSize.height)}, }; - uniforms.createOrUpdate(idFillOutlinePatternDrawableUBO, &drawableUBO, context); + drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context); break; } case RenderFillLayer::FillVariant::FillOutlineTriangulated: { - UpdateFillOutlineTriangulatedUniformBuffers(); - - uniforms.set(idFillOutlineTriangulatedPropertiesUBO, fillOutlineTriangulatedUniformBuffer); - - const FillOutlineTriangulatedDrawableUBO drawableUBO{ - /*matrix = */ util::cast(matrix), - /*units_to_pixels = */ {1.0f / parameters.pixelsToGLUnits[0], 1.0f / parameters.pixelsToGLUnits[1]}, - /*ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, parameters.state.getZoom()), + const FillOutlineTriangulatedDrawableUBO drawableUBO = { + /*.matrix=*/util::cast(matrix), + /*.units_to_pixels=*/{1.0f / parameters.pixelsToGLUnits[0], 1.0f / parameters.pixelsToGLUnits[1]}, + /*.ratio=*/1.0f / tileID.pixelsToTileUnits(1.0f, parameters.state.getZoom()), 0}; - uniforms.createOrUpdate(idFillOutlineTriangulatedDrawableUBO, &drawableUBO, context); + drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context); break; } default: { diff --git a/src/mbgl/renderer/layers/fill_layer_tweaker.hpp b/src/mbgl/renderer/layers/fill_layer_tweaker.hpp index 2dc40e3a7..dc67bc4dd 100644 --- a/src/mbgl/renderer/layers/fill_layer_tweaker.hpp +++ b/src/mbgl/renderer/layers/fill_layer_tweaker.hpp @@ -20,18 +20,7 @@ public: void execute(LayerGroupBase&, const PaintParameters&) override; private: - gfx::UniformBufferPtr fillPropsUniformBuffer; - gfx::UniformBufferPtr fillOutlinePropsUniformBuffer; - gfx::UniformBufferPtr fillPatternPropsUniformBuffer; - gfx::UniformBufferPtr fillOutlinePatternPropsUniformBuffer; - gfx::UniformBufferPtr fillOutlineTriangulatedUniformBuffer; - - // Only run each update function once per property update - bool fillUniformBufferUpdated = true; - bool fillOutlineUniformBufferUpdated = true; - bool fillPatternUniformBufferUpdated = true; - bool fillOutlinePatternUniformBufferUpdated = true; - bool fillOutlineTriangulatedUniformBufferUpdated = true; + gfx::UniformBufferPtr evaluatedPropsUniformBuffer; }; } // namespace mbgl diff --git a/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp b/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp index 2c3c925da..ee443e8e0 100644 --- a/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp @@ -33,18 +33,17 @@ void HeatmapLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamet const auto debugGroup = parameters.encoder->createDebugGroup(label.c_str()); #endif - const auto getPropsBuffer = [&]() -> auto& { - if (!evaluatedPropsUniformBuffer || propertiesUpdated) { - const HeatmapEvaluatedPropsUBO evaluatedPropsUBO = { - /* .weight = */ evaluated.get().constantOr(HeatmapWeight::defaultValue()), - /* .radius = */ evaluated.get().constantOr(HeatmapRadius::defaultValue()), - /* .intensity = */ evaluated.get(), - /* .padding = */ 0}; - parameters.context.emplaceOrUpdateUniformBuffer(evaluatedPropsUniformBuffer, &evaluatedPropsUBO); - propertiesUpdated = false; - } - return evaluatedPropsUniformBuffer; - }; + if (!evaluatedPropsUniformBuffer || propertiesUpdated) { + const HeatmapEvaluatedPropsUBO evaluatedPropsUBO = { + /* .weight = */ evaluated.get().constantOr(HeatmapWeight::defaultValue()), + /* .radius = */ evaluated.get().constantOr(HeatmapRadius::defaultValue()), + /* .intensity = */ evaluated.get(), + /* .padding = */ 0}; + parameters.context.emplaceOrUpdateUniformBuffer(evaluatedPropsUniformBuffer, &evaluatedPropsUBO); + propertiesUpdated = false; + } + auto& layerUniforms = layerGroup.mutableUniformBuffers(); + layerUniforms.set(idHeatmapEvaluatedPropsUBO, evaluatedPropsUniformBuffer); visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { if (!drawable.getTileID() || !checkTweakDrawable(drawable)) { @@ -53,9 +52,6 @@ void HeatmapLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamet const UnwrappedTileID tileID = drawable.getTileID()->toUnwrapped(); - auto& uniforms = drawable.mutableUniformBuffers(); - uniforms.set(idHeatmapEvaluatedPropsUBO, getPropsBuffer()); - constexpr bool nearClipped = false; constexpr bool inViewportPixelUnits = false; const auto matrix = getTileMatrix( @@ -65,7 +61,8 @@ void HeatmapLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamet /* .extrude_scale = */ tileID.pixelsToTileUnits(1.0f, static_cast(zoom)), /* .padding = */ {0}}; - uniforms.createOrUpdate(idHeatmapDrawableUBO, &drawableUBO, context); + auto& drawableUniforms = drawable.mutableUniformBuffers(); + drawableUniforms.createOrUpdate(idHeatmapDrawableUBO, &drawableUBO, context); }); } diff --git a/src/mbgl/renderer/layers/heatmap_layer_tweaker.hpp b/src/mbgl/renderer/layers/heatmap_layer_tweaker.hpp index 875c1cd8e..3cd17b31e 100644 --- a/src/mbgl/renderer/layers/heatmap_layer_tweaker.hpp +++ b/src/mbgl/renderer/layers/heatmap_layer_tweaker.hpp @@ -19,11 +19,6 @@ public: protected: gfx::UniformBufferPtr evaluatedPropsUniformBuffer; - -#if MLN_RENDER_BACKEND_METAL - gfx::UniformBufferPtr permutationUniformBuffer; - gfx::UniformBufferPtr expressionUniformBuffer; -#endif // MLN_RENDER_BACKEND_METAL }; } // namespace mbgl diff --git a/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp b/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp index f12002f56..28cc38004 100644 --- a/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp @@ -27,28 +27,19 @@ void HeatmapTextureLayerTweaker::execute(LayerGroupBase& layerGroup, const Paint const auto debugGroup = parameters.encoder->createDebugGroup(label.c_str()); #endif - const auto getDrawableUBO = [&]() -> auto& { - if (!drawableBuffer) { - const auto& size = parameters.staticData.backendSize; - mat4 viewportMat; - matrix::ortho(viewportMat, 0, size.width, size.height, 0, -1, 1); - const HeatmapTextureDrawableUBO drawableUBO = { - /* .matrix = */ util::cast(viewportMat), - /* .world = */ {static_cast(size.width), static_cast(size.height)}, - /* .opacity = */ evaluated.get(), - /* .pad1 = */ 0, - }; - parameters.context.emplaceOrUpdateUniformBuffer(drawableBuffer, &drawableUBO); - } - return drawableBuffer; - }; + propertiesUpdated = false; - visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { - if (!checkTweakDrawable(drawable)) { - return; - } - drawable.mutableUniformBuffers().set(idHeatmapTextureDrawableUBO, getDrawableUBO()); - }); + const auto& size = parameters.staticData.backendSize; + mat4 viewportMat; + matrix::ortho(viewportMat, 0, size.width, size.height, 0, -1, 1); + const HeatmapTexturePropsUBO propsUBO = { + /* .matrix = */ util::cast(viewportMat), + /* .world = */ {static_cast(size.width), static_cast(size.height)}, + /* .opacity = */ evaluated.get(), + /* .pad1 = */ 0, + }; + auto& layerUniforms = layerGroup.mutableUniformBuffers(); + layerUniforms.createOrUpdate(idHeatmapTexturePropsUBO, &propsUBO, parameters.context); } } // namespace mbgl diff --git a/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.hpp b/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.hpp index 350cac89a..cbe2ad08d 100644 --- a/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.hpp +++ b/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.hpp @@ -16,9 +16,6 @@ public: ~HeatmapTextureLayerTweaker() override = default; void execute(LayerGroupBase&, const PaintParameters&) override; - -protected: - gfx::UniformBufferPtr drawableBuffer; }; } // namespace mbgl diff --git a/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp b/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp index bc0b1557c..01d913b5e 100644 --- a/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp @@ -43,17 +43,16 @@ void HillshadeLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParam const auto debugGroup = parameters.encoder->createDebugGroup(label.c_str()); #endif - const auto getPropsBuffer = [&]() -> auto& { - if (!evaluatedPropsUniformBuffer || propertiesUpdated) { - const HillshadeEvaluatedPropsUBO evaluatedPropsUBO = { - /* .highlight = */ evaluated.get(), - /* .shadow = */ evaluated.get(), - /* .accent = */ evaluated.get()}; - parameters.context.emplaceOrUpdateUniformBuffer(evaluatedPropsUniformBuffer, &evaluatedPropsUBO); - propertiesUpdated = false; - } - return evaluatedPropsUniformBuffer; - }; + if (!evaluatedPropsUniformBuffer || propertiesUpdated) { + const HillshadeEvaluatedPropsUBO evaluatedPropsUBO = { + /* .highlight = */ evaluated.get(), + /* .shadow = */ evaluated.get(), + /* .accent = */ evaluated.get()}; + parameters.context.emplaceOrUpdateUniformBuffer(evaluatedPropsUniformBuffer, &evaluatedPropsUBO); + propertiesUpdated = false; + } + auto& layerUniforms = layerGroup.mutableUniformBuffers(); + layerUniforms.set(idHillshadeEvaluatedPropsUBO, evaluatedPropsUniformBuffer); visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { if (!drawable.getTileID() || !checkTweakDrawable(drawable)) { @@ -62,15 +61,13 @@ void HillshadeLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParam const UnwrappedTileID tileID = drawable.getTileID()->toUnwrapped(); - auto& uniforms = drawable.mutableUniformBuffers(); - uniforms.set(idHillshadeEvaluatedPropsUBO, getPropsBuffer()); - const auto matrix = getTileMatrix( tileID, parameters, {0.f, 0.f}, TranslateAnchorType::Viewport, false, false, drawable, true); HillshadeDrawableUBO drawableUBO = {/* .matrix = */ util::cast(matrix), /* .latrange = */ getLatRange(tileID), /* .light = */ getLight(parameters, evaluated)}; - uniforms.createOrUpdate(idHillshadeDrawableUBO, &drawableUBO, parameters.context); + auto& drawableUniforms = drawable.mutableUniformBuffers(); + drawableUniforms.createOrUpdate(idHillshadeDrawableUBO, &drawableUBO, parameters.context); }); } diff --git a/src/mbgl/renderer/layers/hillshade_prepare_layer_tweaker.cpp b/src/mbgl/renderer/layers/hillshade_prepare_layer_tweaker.cpp index fea60775d..2b4ddf8dd 100644 --- a/src/mbgl/renderer/layers/hillshade_prepare_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/hillshade_prepare_layer_tweaker.cpp @@ -37,6 +37,8 @@ void HillshadePrepareLayerTweaker::execute(LayerGroupBase& layerGroup, const Pai const auto debugGroup = parameters.encoder->createDebugGroup(label.c_str()); #endif + propertiesUpdated = false; + visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { if (!drawable.getTileID() || !drawable.getData() || !checkTweakDrawable(drawable)) { return; diff --git a/src/mbgl/renderer/layers/line_layer_tweaker.cpp b/src/mbgl/renderer/layers/line_layer_tweaker.cpp index 0ebde50af..8ffd4c914 100644 --- a/src/mbgl/renderer/layers/line_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/line_layer_tweaker.cpp @@ -16,7 +16,6 @@ #if MLN_RENDER_BACKEND_METAL #include -#include #endif // MLN_RENDER_BACKEND_METAL namespace mbgl { @@ -31,84 +30,27 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters const auto& crossfade = static_cast(*evaluatedProperties).crossfade; // Each property UBO is updated at most once if new evaluated properties were set - if (propertiesUpdated) { - simplePropertiesUpdated = true; - gradientPropertiesUpdated = true; - patternPropertiesUpdated = true; - sdfPropertiesUpdated = true; + if (!evaluatedPropsUniformBuffer || propertiesUpdated) { + const LineEvaluatedPropsUBO propsUBO = { + /*color =*/evaluated.get().constantOr(LineColor::defaultValue()), + /*blur =*/evaluated.get().constantOr(LineBlur::defaultValue()), + /*opacity =*/evaluated.get().constantOr(LineOpacity::defaultValue()), + /*gapwidth =*/evaluated.get().constantOr(LineGapWidth::defaultValue()), + /*offset =*/evaluated.get().constantOr(LineOffset::defaultValue()), + /*width =*/evaluated.get().constantOr(LineWidth::defaultValue()), + /*floorwidth =*/evaluated.get().constantOr(LineFloorWidth::defaultValue()), + 0, + 0}; + context.emplaceOrUpdateUniformBuffer(evaluatedPropsUniformBuffer, &propsUBO); propertiesUpdated = false; } - const auto getLinePropsBuffer = [&]() { - if (!linePropertiesBuffer || simplePropertiesUpdated) { - const LinePropertiesUBO linePropertiesUBO{ - /*color =*/evaluated.get().constantOr(LineColor::defaultValue()), - /*blur =*/evaluated.get().constantOr(LineBlur::defaultValue()), - /*opacity =*/evaluated.get().constantOr(LineOpacity::defaultValue()), - /*gapwidth =*/evaluated.get().constantOr(LineGapWidth::defaultValue()), - /*offset =*/evaluated.get().constantOr(LineOffset::defaultValue()), - /*width =*/evaluated.get().constantOr(LineWidth::defaultValue()), - 0, - 0, - 0}; - context.emplaceOrUpdateUniformBuffer(linePropertiesBuffer, &linePropertiesUBO); - simplePropertiesUpdated = false; - } - return linePropertiesBuffer; - }; - const auto getLineGradientPropsBuffer = [&]() { - if (!lineGradientPropertiesBuffer || gradientPropertiesUpdated) { - const LineGradientPropertiesUBO lineGradientPropertiesUBO{ - /*blur =*/evaluated.get().constantOr(LineBlur::defaultValue()), - /*opacity =*/evaluated.get().constantOr(LineOpacity::defaultValue()), - /*gapwidth =*/evaluated.get().constantOr(LineGapWidth::defaultValue()), - /*offset =*/evaluated.get().constantOr(LineOffset::defaultValue()), - /*width =*/evaluated.get().constantOr(LineWidth::defaultValue()), - 0, - 0, - 0}; - context.emplaceOrUpdateUniformBuffer(lineGradientPropertiesBuffer, &lineGradientPropertiesUBO); - gradientPropertiesUpdated = false; - } - return lineGradientPropertiesBuffer; - }; - const auto getLinePatternPropsBuffer = [&]() { - if (!linePatternPropertiesBuffer || patternPropertiesUpdated) { - const LinePatternPropertiesUBO linePatternPropertiesUBO{ - /*blur =*/evaluated.get().constantOr(LineBlur::defaultValue()), - /*opacity =*/evaluated.get().constantOr(LineOpacity::defaultValue()), - /*offset =*/evaluated.get().constantOr(LineOffset::defaultValue()), - /*gapwidth =*/evaluated.get().constantOr(LineGapWidth::defaultValue()), - /*width =*/evaluated.get().constantOr(LineWidth::defaultValue()), - 0, - 0, - 0}; - context.emplaceOrUpdateUniformBuffer(linePatternPropertiesBuffer, &linePatternPropertiesUBO); - patternPropertiesUpdated = false; - } - return linePatternPropertiesBuffer; - }; - const auto getLineSDFPropsBuffer = [&]() { - if (!lineSDFPropertiesBuffer || sdfPropertiesUpdated) { - const LineSDFPropertiesUBO lineSDFPropertiesUBO{ - /*color =*/evaluated.get().constantOr(LineColor::defaultValue()), - /*blur =*/evaluated.get().constantOr(LineBlur::defaultValue()), - /*opacity =*/evaluated.get().constantOr(LineOpacity::defaultValue()), - /*gapwidth =*/evaluated.get().constantOr(LineGapWidth::defaultValue()), - /*offset =*/evaluated.get().constantOr(LineOffset::defaultValue()), - /*width =*/evaluated.get().constantOr(LineWidth::defaultValue()), - /*floorwidth =*/evaluated.get().constantOr(LineFloorWidth::defaultValue()), - 0, - 0}; - context.emplaceOrUpdateUniformBuffer(lineSDFPropertiesBuffer, &lineSDFPropertiesUBO); - sdfPropertiesUpdated = false; - } - return lineSDFPropertiesBuffer; - }; - const LineDynamicUBO dynamicUBO = { /*units_to_pixels = */ {1.0f / parameters.pixelsToGLUnits[0], 1.0f / parameters.pixelsToGLUnits[1]}, 0, 0}; - context.emplaceOrUpdateUniformBuffer(dynamicBuffer, &dynamicUBO); + + auto& layerUniforms = layerGroup.mutableUniformBuffers(); + layerUniforms.createOrUpdate(idLineDynamicUBO, &dynamicUBO, context); + layerUniforms.set(idLineEvaluatedPropsUBO, evaluatedPropsUniformBuffer); visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { const auto shader = drawable.getShader(); @@ -121,7 +63,7 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters const auto anchor = evaluated.get(); constexpr bool nearClipped = false; constexpr bool inViewportPixelUnits = false; // from RenderTile::translatedMatrix - auto& uniforms = drawable.mutableUniformBuffers(); + auto& drawableUniforms = drawable.mutableUniformBuffers(); const auto matrix = getTileMatrix( tileID, parameters, translation, anchor, nearClipped, inViewportPixelUnits, drawable); @@ -129,34 +71,24 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters const LineType type = static_cast(drawable.getType()); switch (type) { case LineType::Simple: { - const LineUBO lineUBO{/*matrix = */ util::cast(matrix), - /*ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, static_cast(zoom)), - 0, - 0, - 0}; - uniforms.createOrUpdate(idLineUBO, &lineUBO, context); - - // properties UBO - uniforms.set(idLinePropertiesUBO, getLinePropsBuffer()); - - // dynamic UBO - uniforms.set(idLineDynamicUBO, dynamicBuffer); - } break; - - case LineType::Gradient: { - const LineGradientUBO lineGradientUBO{ + const LineDrawableUBO drawableUBO = { /*matrix = */ util::cast(matrix), /*ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, static_cast(zoom)), 0, 0, 0}; - uniforms.createOrUpdate(idLineGradientUBO, &lineGradientUBO, context); + drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, context); + } break; - // properties UBO - uniforms.set(idLineGradientPropertiesUBO, getLineGradientPropsBuffer()); - - // dynamic UBO - uniforms.set(idLineGradientDynamicUBO, dynamicBuffer); + case LineType::Gradient: { + const LineGradientDrawableUBO drawableUBO = { + /*matrix = */ util::cast(matrix), + /*ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, static_cast(zoom)), + 0, + 0, + 0}; + drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, context); + ; } break; case LineType::Pattern: { @@ -164,7 +96,7 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters if (const auto& texture = drawable.getTexture(idLineImageTexture)) { textureSize = texture->getSize(); } - const LinePatternUBO linePatternUBO{ + const LinePatternDrawableUBO drawableUBO = { /*matrix =*/util::cast(matrix), /*scale =*/ {parameters.pixelRatio, @@ -174,14 +106,7 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters /*texsize =*/{static_cast(textureSize.width), static_cast(textureSize.height)}, /*ratio =*/1.0f / tileID.pixelsToTileUnits(1.0f, static_cast(zoom)), /*fade =*/crossfade.t}; - uniforms.createOrUpdate(idLinePatternUBO, &linePatternUBO, context); - - // properties UBO - uniforms.set(idLinePatternPropertiesUBO, getLinePatternPropsBuffer()); - - // dynamic UBO - uniforms.set(idLinePatternDynamicUBO, dynamicBuffer); - + drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, context); } break; case LineType::SDF: { @@ -205,7 +130,7 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters const LinePatternPos& posB = dashPatternTexture.getTo(); const float widthA = posA.width * crossfade.fromScale; const float widthB = posB.width * crossfade.toScale; - const LineSDFUBO lineSDFUBO{ + const LineSDFDrawableUBO drawableUBO{ /* matrix = */ util::cast(matrix), /* patternscale_a = */ {1.0f / tileID.pixelsToTileUnits(widthA, parameters.state.getIntegerZoom()), @@ -222,13 +147,7 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters 0, 0, 0}; - uniforms.createOrUpdate(idLineSDFUBO, &lineSDFUBO, context); - - // properties UBO - uniforms.set(idLineSDFPropertiesUBO, getLineSDFPropsBuffer()); - - // dynamic UBO - uniforms.set(idLineSDFDynamicUBO, dynamicBuffer); + drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, context); } } break; diff --git a/src/mbgl/renderer/layers/line_layer_tweaker.hpp b/src/mbgl/renderer/layers/line_layer_tweaker.hpp index ef156ae73..563bd0780 100644 --- a/src/mbgl/renderer/layers/line_layer_tweaker.hpp +++ b/src/mbgl/renderer/layers/line_layer_tweaker.hpp @@ -18,8 +18,8 @@ class LineLayerTweaker : public LayerTweaker { public: enum class LineType { Simple, - Pattern, Gradient, + Pattern, SDF }; @@ -31,21 +31,7 @@ public: void execute(LayerGroupBase&, const PaintParameters&) override; protected: - gfx::UniformBufferPtr linePropertiesBuffer; - gfx::UniformBufferPtr lineGradientPropertiesBuffer; - gfx::UniformBufferPtr linePatternPropertiesBuffer; - gfx::UniformBufferPtr lineSDFPropertiesBuffer; - gfx::UniformBufferPtr dynamicBuffer; - -#if MLN_RENDER_BACKEND_METAL - gfx::UniformBufferPtr permutationUniformBuffer; - gfx::UniformBufferPtr expressionUniformBuffer; -#endif // MLN_RENDER_BACKEND_METAL - - bool simplePropertiesUpdated = true; - bool gradientPropertiesUpdated = true; - bool patternPropertiesUpdated = true; - bool sdfPropertiesUpdated = true; + gfx::UniformBufferPtr evaluatedPropsUniformBuffer; }; } // namespace mbgl diff --git a/src/mbgl/renderer/layers/raster_layer_tweaker.cpp b/src/mbgl/renderer/layers/raster_layer_tweaker.cpp index 3f7655731..78f83955c 100644 --- a/src/mbgl/renderer/layers/raster_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/raster_layer_tweaker.cpp @@ -20,36 +20,54 @@ void RasterLayerTweaker::execute([[maybe_unused]] LayerGroupBase& layerGroup, [[maybe_unused]] const PaintParameters& parameters) { const auto& evaluated = static_cast(*evaluatedProperties).evaluated; - propertiesUpdated = false; + const auto spinWeights = [](float spin) -> std::array { + spin = util::deg2radf(spin); + const float s = std::sin(spin); + const float c = std::cos(spin); + std::array spin_weights = { + {(2 * c + 1) / 3, (-std::sqrt(3.0f) * s - c + 1) / 3, (std::sqrt(3.0f) * s - c + 1) / 3, 0}}; + return spin_weights; + }; + const auto saturationFactor = [](float saturation) -> float { + if (saturation > 0) { + return 1.f - 1.f / (1.001f - saturation); + } else { + return -saturation; + } + }; + const auto contrastFactor = [](float contrast) -> float { + if (contrast > 0) { + return 1 / (1 - contrast); + } else { + return 1 + contrast; + } + }; + + if (!evaluatedPropsUniformBuffer || propertiesUpdated) { + const RasterEvaluatedPropsUBO propsUBO = { + /*.spin_weigths = */ spinWeights(evaluated.get()), + /*.tl_parent = */ {{0.0f, 0.0f}}, + /*.scale_parent = */ 1.0f, + /*.buffer_scale = */ 1.0f, + /*.fade_t = */ 1.0f, + /*.opacity = */ evaluated.get(), + /*.brightness_low = */ evaluated.get(), + /*.brightness_high = */ evaluated.get(), + /*.saturation_factor = */ saturationFactor(evaluated.get()), + /*.contrast_factor = */ contrastFactor(evaluated.get()), + 0, + 0}; + parameters.context.emplaceOrUpdateUniformBuffer(evaluatedPropsUniformBuffer, &propsUBO); + propertiesUpdated = false; + } + auto& layerUniforms = layerGroup.mutableUniformBuffers(); + layerUniforms.set(idRasterEvaluatedPropsUBO, evaluatedPropsUniformBuffer); visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { if (!checkTweakDrawable(drawable)) { return; } - const auto spinWeights = [](float spin) -> std::array { - spin = util::deg2radf(spin); - const float s = std::sin(spin); - const float c = std::cos(spin); - std::array spin_weights = { - {(2 * c + 1) / 3, (-std::sqrt(3.0f) * s - c + 1) / 3, (std::sqrt(3.0f) * s - c + 1) / 3, 0}}; - return spin_weights; - }; - const auto saturationFactor = [](float saturation) -> float { - if (saturation > 0) { - return 1.f - 1.f / (1.001f - saturation); - } else { - return -saturation; - } - }; - const auto contrastFactor = [](float contrast) -> float { - if (contrast > 0) { - return 1 / (1 - contrast); - } else { - return 1 + contrast; - } - }; - mat4 matrix; if (!drawable.getTileID()) { // this is an image drawable @@ -75,22 +93,9 @@ void RasterLayerTweaker::execute([[maybe_unused]] LayerGroupBase& layerGroup, !parameters.state.isChanging()); } - const RasterDrawableUBO drawableUBO{ - /*.matrix = */ util::cast(matrix), - /*.spin_weigths = */ spinWeights(evaluated.get()), - /*.tl_parent = */ {{0.0f, 0.0f}}, - /*.scale_parent = */ 1.0f, - /*.buffer_scale = */ 1.0f, - /*.fade_t = */ 1.0f, - /*.opacity = */ evaluated.get(), - /*.brightness_low = */ evaluated.get(), - /*.brightness_high = */ evaluated.get(), - /*.saturation_factor = */ saturationFactor(evaluated.get()), - /*.contrast_factor = */ contrastFactor(evaluated.get()), - 0, - 0}; - auto& uniforms = drawable.mutableUniformBuffers(); - uniforms.createOrUpdate(idRasterDrawableUBO, &drawableUBO, parameters.context); + const RasterDrawableUBO drawableUBO{/*.matrix = */ util::cast(matrix)}; + auto& drawableUniforms = drawable.mutableUniformBuffers(); + drawableUniforms.createOrUpdate(idRasterDrawableUBO, &drawableUBO, parameters.context); }); } diff --git a/src/mbgl/renderer/layers/render_circle_layer.cpp b/src/mbgl/renderer/layers/render_circle_layer.cpp index 4f8b270b3..b386f5f35 100644 --- a/src/mbgl/renderer/layers/render_circle_layer.cpp +++ b/src/mbgl/renderer/layers/render_circle_layer.cpp @@ -357,8 +357,8 @@ void RenderCircleLayer::update(gfx::ShaderRegistry& shaders, return false; } - auto& uniforms = drawable.mutableUniformBuffers(); - uniforms.createOrUpdate(idCircleInterpolateUBO, &interpolateUBO, context); + auto& drawableUniforms = drawable.mutableUniformBuffers(); + drawableUniforms.createOrUpdate(idCircleInterpolateUBO, &interpolateUBO, context); return true; }; if (updateTile(renderPass, tileID, std::move(updateExisting))) { @@ -412,8 +412,8 @@ void RenderCircleLayer::update(gfx::ShaderRegistry& shaders, drawable->setTileID(tileID); drawable->setLayerTweaker(layerTweaker); - auto& uniforms = drawable->mutableUniformBuffers(); - uniforms.set(idCircleInterpolateUBO, interpBuffer); + auto& drawableUniforms = drawable->mutableUniformBuffers(); + drawableUniforms.set(idCircleInterpolateUBO, interpBuffer); tileLayerGroup->addDrawable(renderPass, tileID, std::move(drawable)); ++stats.drawablesAdded; diff --git a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp index 0d96259d0..2a230db7b 100644 --- a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp +++ b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp @@ -383,7 +383,7 @@ void RenderFillExtrusionLayer::update(gfx::ShaderRegistry& shaders, 0, 0}; - const FillExtrusionDrawableTilePropsUBO tilePropsUBO = { + const FillExtrusionTilePropsUBO tilePropsUBO = { /* pattern_from = */ patternPosA ? util::cast(patternPosA->tlbr()) : std::array{0}, /* pattern_to = */ patternPosB ? util::cast(patternPosB->tlbr()) : std::array{0}, }; @@ -395,9 +395,9 @@ void RenderFillExtrusionLayer::update(gfx::ShaderRegistry& shaders, return false; } - auto& uniforms = drawable.mutableUniformBuffers(); - uniforms.createOrUpdate(idFillExtrusionDrawableTilePropsUBO, &tilePropsUBO, context); - uniforms.createOrUpdate(idFillExtrusionInterpolateUBO, &interpUBO, context); + auto& drawableUniforms = drawable.mutableUniformBuffers(); + drawableUniforms.createOrUpdate(idFillExtrusionTilePropsUBO, &tilePropsUBO, context); + drawableUniforms.createOrUpdate(idFillExtrusionInterpolateUBO, &interpUBO, context); return true; }; if (updateTile(drawPass, tileID, std::move(updateExisting))) { @@ -510,9 +510,9 @@ void RenderFillExtrusionLayer::update(gfx::ShaderRegistry& shaders, drawable->setTileID(tileID); drawable->setLayerTweaker(layerTweaker); - auto& uniforms = drawable->mutableUniformBuffers(); - uniforms.createOrUpdate(idFillExtrusionDrawableTilePropsUBO, &tilePropsUBO, context); - uniforms.createOrUpdate(idFillExtrusionInterpolateUBO, &interpUBO, context); + auto& drawableUniforms = drawable->mutableUniformBuffers(); + drawableUniforms.createOrUpdate(idFillExtrusionTilePropsUBO, &tilePropsUBO, context); + drawableUniforms.createOrUpdate(idFillExtrusionInterpolateUBO, &interpUBO, context); tileLayerGroup->addDrawable(drawPass, tileID, std::move(drawable)); ++stats.drawablesAdded; diff --git a/src/mbgl/renderer/layers/render_fill_layer.cpp b/src/mbgl/renderer/layers/render_fill_layer.cpp index 29d4000bd..ae29b16df 100644 --- a/src/mbgl/renderer/layers/render_fill_layer.cpp +++ b/src/mbgl/renderer/layers/render_fill_layer.cpp @@ -512,26 +512,25 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders, // If we already have drawables for this tile, update them. auto updateExisting = [&](gfx::Drawable& drawable) { - auto& uniforms = drawable.mutableUniformBuffers(); + auto& drawableUniforms = drawable.mutableUniformBuffers(); switch (static_cast(drawable.getType())) { case FillVariant::Fill: { - uniforms.createOrUpdate(idFillInterpolateUBO, &getFillInterpolateUBO(), context); + drawableUniforms.createOrUpdate(idFillInterpolateUBO, &getFillInterpolateUBO(), context); break; } case FillVariant::FillOutline: { - uniforms.createOrUpdate(idFillOutlineInterpolateUBO, &getFillOutlineInterpolateUBO(), context); + drawableUniforms.createOrUpdate(idFillInterpolateUBO, &getFillOutlineInterpolateUBO(), context); break; } case FillVariant::FillPattern: { - uniforms.createOrUpdate(idFillPatternInterpolateUBO, &getFillPatternInterpolateUBO(), context); - uniforms.createOrUpdate(idFillPatternTilePropsUBO, &getFillPatternTilePropsUBO(), context); + drawableUniforms.createOrUpdate(idFillInterpolateUBO, &getFillPatternInterpolateUBO(), context); + drawableUniforms.createOrUpdate(idFillTilePropsUBO, &getFillPatternTilePropsUBO(), context); break; } case FillVariant::FillOutlinePattern: { - uniforms.createOrUpdate( - idFillOutlinePatternInterpolateUBO, &getFillOutlinePatternInterpolateUBO(), context); - uniforms.createOrUpdate( - idFillOutlinePatternTilePropsUBO, &getFillOutlinePatternTilePropsUBO(), context); + drawableUniforms.createOrUpdate( + idFillInterpolateUBO, &getFillOutlinePatternInterpolateUBO(), context); + drawableUniforms.createOrUpdate(idFillTilePropsUBO, &getFillOutlinePatternTilePropsUBO(), context); break; } case FillVariant::FillOutlineTriangulated: { @@ -659,8 +658,8 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders, drawable->setLayerTweaker(layerTweaker); drawable->setType(static_cast(type)); - auto& uniforms = drawable->mutableUniformBuffers(); - uniforms.createOrUpdate(interpolateUBOId, &interpolateUBO, context); + auto& drawableUniforms = drawable->mutableUniformBuffers(); + drawableUniforms.createOrUpdate(interpolateUBOId, &interpolateUBO, context); fillTileLayerGroup->addDrawable(renderPass, tileID, std::move(drawable)); ++stats.drawablesAdded; } @@ -704,10 +703,8 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders, bucket.sharedBasicLineIndexes, bucket.basicLineSegments.data(), bucket.basicLineSegments.size()); - finish(*outlineBuilder, - idFillOutlineInterpolateUBO, - getFillOutlineInterpolateUBO(), - FillVariant::FillOutline); + finish( + *outlineBuilder, idFillInterpolateUBO, getFillInterpolateUBO(), FillVariant::FillOutline); } } } @@ -719,10 +716,7 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders, bucket.sharedBasicLineIndexes, bucket.basicLineSegments.data(), bucket.basicLineSegments.size()); - finish(*outlineBuilder, - idFillOutlineInterpolateUBO, - getFillOutlineInterpolateUBO(), - FillVariant::FillOutline); + finish(*outlineBuilder, idFillInterpolateUBO, getFillOutlineInterpolateUBO(), FillVariant::FillOutline); } #endif } else { @@ -788,9 +782,9 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders, drawable->setLayerTweaker(layerTweaker); drawable->setType(static_cast(type)); - auto& uniforms = drawable->mutableUniformBuffers(); - uniforms.createOrUpdate(interpolateNameId, &interpolateUBO, context); - uniforms.createOrUpdate(tileUBOId, &tileUBO, context); + auto& drawableUniforms = drawable->mutableUniformBuffers(); + drawableUniforms.createOrUpdate(interpolateNameId, &interpolateUBO, context); + drawableUniforms.createOrUpdate(tileUBOId, &tileUBO, context); fillTileLayerGroup->addDrawable(renderPass, tileID, std::move(drawable)); ++stats.drawablesAdded; } @@ -812,9 +806,9 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders, bucket.triangleSegments.size()); finish(*patternBuilder, - idFillPatternInterpolateUBO, + idFillInterpolateUBO, getFillPatternInterpolateUBO(), - idFillPatternTilePropsUBO, + idFillTilePropsUBO, getFillPatternTilePropsUBO(), FillVariant::FillPattern); } @@ -829,9 +823,9 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders, bucket.basicLineSegments.size()); finish(*outlinePatternBuilder, - idFillOutlinePatternInterpolateUBO, + idFillInterpolateUBO, getFillOutlinePatternInterpolateUBO(), - idFillOutlinePatternTilePropsUBO, + idFillTilePropsUBO, getFillOutlinePatternTilePropsUBO(), FillVariant::FillOutlinePattern); } diff --git a/src/mbgl/renderer/layers/render_heatmap_layer.cpp b/src/mbgl/renderer/layers/render_heatmap_layer.cpp index 355832870..784417d2f 100644 --- a/src/mbgl/renderer/layers/render_heatmap_layer.cpp +++ b/src/mbgl/renderer/layers/render_heatmap_layer.cpp @@ -393,10 +393,10 @@ void RenderHeatmapLayer::update(gfx::ShaderRegistry& shaders, // We assume vertex attributes don't change, and so don't update them to avoid re-uploading // drawable.setVertexAttributes(heatmapVertexAttrs); - auto& uniforms = drawable.mutableUniformBuffers(); + auto& drawableUniforms = drawable.mutableUniformBuffers(); if (auto buffer = getInterpolateBuffer()) { - uniforms.set(idHeatmapInterpolateUBO, std::move(buffer)); + drawableUniforms.set(idHeatmapInterpolateUBO, std::move(buffer)); } }); @@ -459,10 +459,10 @@ void RenderHeatmapLayer::update(gfx::ShaderRegistry& shaders, drawable->setTileID(tileID); drawable->setLayerTweaker(layerTweaker); - auto& uniforms = drawable->mutableUniformBuffers(); + auto& drawableUniforms = drawable->mutableUniformBuffers(); if (auto buffer = getInterpolateBuffer()) { - uniforms.set(idHeatmapInterpolateUBO, std::move(buffer)); + drawableUniforms.set(idHeatmapInterpolateUBO, std::move(buffer)); } tileLayerGroup->addDrawable(renderPass, tileID, std::move(drawable)); diff --git a/src/mbgl/renderer/layers/render_line_layer.cpp b/src/mbgl/renderer/layers/render_line_layer.cpp index 19f377bed..161a04a37 100644 --- a/src/mbgl/renderer/layers/render_line_layer.cpp +++ b/src/mbgl/renderer/layers/render_line_layer.cpp @@ -560,19 +560,18 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders, case LineLayerTweaker::LineType::Gradient: { drawableUniforms.createOrUpdate( - idLineGradientInterpolationUBO, &getLineGradientInterpolationUBO(), context); + idLineInterpolationUBO, &getLineGradientInterpolationUBO(), context); } break; case LineLayerTweaker::LineType::Pattern: { - drawableUniforms.createOrUpdate( - idLinePatternInterpolationUBO, &getLinePatternInterpolationUBO(), context); + drawableUniforms.createOrUpdate(idLineInterpolationUBO, &getLinePatternInterpolationUBO(), context); drawableUniforms.createOrUpdate( - idLinePatternTilePropertiesUBO, &getLinePatternTilePropertiesUBO(), context); + idLineTilePropertiesUBO, &getLinePatternTilePropertiesUBO(), context); } break; case LineLayerTweaker::LineType::SDF: { - drawableUniforms.createOrUpdate(idLineSDFInterpolationUBO, &getLineSDFInterpolationUBO(), context); + drawableUniforms.createOrUpdate(idLineInterpolationUBO, &getLineSDFInterpolationUBO(), context); } break; default: { @@ -631,7 +630,7 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders, drawable->setLayerTweaker(layerTweaker); drawable->setData(std::make_unique(cap)); drawable->mutableUniformBuffers().createOrUpdate( - idLineSDFInterpolationUBO, &getLineSDFInterpolationUBO(), context); + idLineInterpolationUBO, &getLineSDFInterpolationUBO(), context); tileLayerGroup->addDrawable(renderPass, tileID, std::move(drawable)); ++stats.drawablesAdded; @@ -679,9 +678,9 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders, drawable->setTileID(tileID); drawable->setLayerTweaker(layerTweaker); drawable->mutableUniformBuffers().createOrUpdate( - idLinePatternInterpolationUBO, &getLinePatternInterpolationUBO(), context); + idLineInterpolationUBO, &getLinePatternInterpolationUBO(), context); drawable->mutableUniformBuffers().createOrUpdate( - idLinePatternTilePropertiesUBO, &getLinePatternTilePropertiesUBO(), context); + idLineTilePropertiesUBO, &getLinePatternTilePropertiesUBO(), context); tileLayerGroup->addDrawable(renderPass, tileID, std::move(drawable)); ++stats.drawablesAdded; @@ -729,7 +728,7 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders, drawable->setTileID(tileID); drawable->setLayerTweaker(layerTweaker); drawable->mutableUniformBuffers().createOrUpdate( - idLineGradientInterpolationUBO, &getLineGradientInterpolationUBO(), context); + idLineInterpolationUBO, &getLineGradientInterpolationUBO(), context); tileLayerGroup->addDrawable(renderPass, tileID, std::move(drawable)); ++stats.drawablesAdded; diff --git a/src/mbgl/renderer/layers/render_symbol_layer.cpp b/src/mbgl/renderer/layers/render_symbol_layer.cpp index 0203d0ba0..f5275ab63 100644 --- a/src/mbgl/renderer/layers/render_symbol_layer.cpp +++ b/src/mbgl/renderer/layers/render_symbol_layer.cpp @@ -733,7 +733,7 @@ auto getInterpFactor(const SymbolBucket::PaintProperties& paintProps, bool isTex return std::get(getProperty(paintProps, isText)->interpolationFactor(currentZoom)); } -SymbolDrawableInterpolateUBO buildInterpUBO(const SymbolBucket::PaintProperties& paint, const bool t, const float z) { +SymbolInterpolateUBO buildInterpUBO(const SymbolBucket::PaintProperties& paint, const bool t, const float z) { return {/* .fill_color_t = */ getInterpFactor(paint, t, z), /* .halo_color_t = */ getInterpFactor(paint, t, z), /* .opacity_t = */ getInterpFactor(paint, t, z), @@ -744,9 +744,9 @@ SymbolDrawableInterpolateUBO buildInterpUBO(const SymbolBucket::PaintProperties& 0}; } -SymbolDrawableTilePropsUBO buildTileUBO(const SymbolBucket& bucket, - const gfx::SymbolDrawableData& drawData, - const float currentZoom) { +SymbolTilePropsUBO buildTileUBO(const SymbolBucket& bucket, + const gfx::SymbolDrawableData& drawData, + const float currentZoom) { const bool isText = (drawData.symbolType == SymbolType::Text); const ZoomEvaluatedSize size = isText ? bucket.textSizeBinder->evaluateForZoom(currentZoom) : bucket.iconSizeBinder->evaluateForZoom(currentZoom); @@ -838,25 +838,25 @@ void updateTileDrawable(gfx::Drawable& drawable, // This property can be set after the initial appearance of the tile, as part of the layout process. drawData.bucketVariablePlacement = bucket.hasVariablePlacement; - auto& uniforms = drawable.mutableUniformBuffers(); + auto& drawableUniforms = drawable.mutableUniformBuffers(); // Create or update the shared interpolation UBO gfx::UniformBufferPtr& interpUBO = isText ? textInterpUBO : iconInterpUBO; if (interpUBO) { - uniforms.set(idSymbolDrawableInterpolateUBO, interpUBO); + drawableUniforms.set(idSymbolInterpolateUBO, interpUBO); } else { const auto ubo = buildInterpUBO(paintProps, isText, currentZoom); - interpUBO = uniforms.get(idSymbolDrawableInterpolateUBO); + interpUBO = drawableUniforms.get(idSymbolInterpolateUBO); if (interpUBO) { interpUBO->update(&ubo, sizeof(ubo)); } else { interpUBO = context.createUniformBuffer(&ubo, sizeof(ubo)); - uniforms.set(idSymbolDrawableInterpolateUBO, interpUBO); + drawableUniforms.set(idSymbolInterpolateUBO, interpUBO); } } const auto tileUBO = buildTileUBO(bucket, drawData, currentZoom); - uniforms.createOrUpdate(idSymbolDrawableTilePropsUBO, &tileUBO, context); + drawableUniforms.createOrUpdate(idSymbolTilePropsUBO, &tileUBO, context); const auto& buffer = isText ? bucket.text : (sdfIcons ? bucket.sdfIcon : bucket.icon); const auto vertexCount = buffer.vertices().elements(); @@ -1351,9 +1351,9 @@ void RenderSymbolLayer::update(gfx::ShaderRegistry& shaders, const auto tileUBO = buildTileUBO(bucket, *drawData, currentZoom); drawable->setData(std::move(drawData)); - auto& uniforms = drawable->mutableUniformBuffers(); - uniforms.createOrUpdate(idSymbolDrawableTilePropsUBO, &tileUBO, context); - uniforms.set(idSymbolDrawableInterpolateUBO, interpUBO); + auto& drawableUniforms = drawable->mutableUniformBuffers(); + drawableUniforms.createOrUpdate(idSymbolTilePropsUBO, &tileUBO, context); + drawableUniforms.set(idSymbolInterpolateUBO, interpUBO); tileLayerGroup->addDrawable(passes, tileID, std::move(drawable)); ++stats.drawablesAdded; diff --git a/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp b/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp index fd0d1b25d..d3722851e 100644 --- a/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp @@ -40,19 +40,6 @@ std::array toArray(const Size& s) { return util::cast(std::array{s.width, s.height}); } -SymbolDrawablePaintUBO buildPaintUBO(bool isText, const SymbolPaintProperties::PossiblyEvaluated& evaluated) { - return { - /*.fill_color=*/isText ? constOrDefault(evaluated) : constOrDefault(evaluated), - /*.halo_color=*/ - isText ? constOrDefault(evaluated) : constOrDefault(evaluated), - /*.opacity=*/isText ? constOrDefault(evaluated) : constOrDefault(evaluated), - /*.halo_width=*/ - isText ? constOrDefault(evaluated) : constOrDefault(evaluated), - /*.halo_blur=*/isText ? constOrDefault(evaluated) : constOrDefault(evaluated), - /*.padding=*/0, - }; -} - } // namespace void SymbolLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) { @@ -69,9 +56,20 @@ void SymbolLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete const auto debugGroup = parameters.encoder->createDebugGroup(label.c_str()); #endif - if (propertiesUpdated) { - textPropertiesUpdated = true; - iconPropertiesUpdated = true; + if (!evaluatedPropsUniformBuffer || propertiesUpdated) { + const SymbolEvaluatedPropsUBO propsUBO = {/*.text_fill_color=*/constOrDefault(evaluated), + /*.text_halo_color=*/constOrDefault(evaluated), + /*.text_opacity=*/constOrDefault(evaluated), + /*.text_halo_width=*/constOrDefault(evaluated), + /*.text_halo_blur=*/constOrDefault(evaluated), + 0, + /*.icon_fill_color=*/constOrDefault(evaluated), + /*.icon_halo_color=*/constOrDefault(evaluated), + /*.icon_opacity=*/constOrDefault(evaluated), + /*.icon_halo_width=*/constOrDefault(evaluated), + /*.icon_halo_blur=*/constOrDefault(evaluated), + 0}; + context.emplaceOrUpdateUniformBuffer(evaluatedPropsUniformBuffer, &propsUBO); propertiesUpdated = false; } @@ -82,11 +80,9 @@ void SymbolLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete /*.aspect_ratio=*/state.getSize().aspectRatio(), 0}; - if (!dynamicBuffer) { - dynamicBuffer = parameters.context.createUniformBuffer(&dynamicUBO, sizeof(dynamicUBO)); - } else { - dynamicBuffer->update(&dynamicUBO, sizeof(dynamicUBO)); - } + auto& layerUniforms = layerGroup.mutableUniformBuffers(); + layerUniforms.createOrUpdate(idSymbolDynamicUBO, &dynamicUBO, context); + layerUniforms.set(idSymbolEvaluatedPropsUBO, evaluatedPropsUniformBuffer); visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { if (!drawable.getTileID() || !drawable.getData()) { @@ -97,16 +93,6 @@ void SymbolLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete const auto& symbolData = static_cast(*drawable.getData()); const auto isText = (symbolData.symbolType == SymbolType::Text); - if (isText && (!textPaintBuffer || textPropertiesUpdated)) { - const auto props = buildPaintUBO(true, evaluated); - textPaintBuffer = parameters.context.createUniformBuffer(&props, sizeof(props)); - textPropertiesUpdated = false; - } else if (!isText && (!iconPaintBuffer || iconPropertiesUpdated)) { - const auto props = buildPaintUBO(false, evaluated); - iconPaintBuffer = parameters.context.createUniformBuffer(&props, sizeof(props)); - iconPropertiesUpdated = false; - } - // from RenderTile::translatedMatrix const auto translate = isText ? evaluated.get() : evaluated.get(); const auto anchor = isText ? evaluated.get() @@ -153,11 +139,8 @@ void SymbolLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete /*.pad=*/{0}, }; - auto& uniforms = drawable.mutableUniformBuffers(); - uniforms.createOrUpdate(idSymbolDrawableUBO, &drawableUBO, context); - - uniforms.set(idSymbolDynamicUBO, dynamicBuffer); - uniforms.set(idSymbolDrawablePaintUBO, isText ? textPaintBuffer : iconPaintBuffer); + auto& drawableUniforms = drawable.mutableUniformBuffers(); + drawableUniforms.createOrUpdate(idSymbolDrawableUBO, &drawableUBO, context); }); } diff --git a/src/mbgl/renderer/layers/symbol_layer_tweaker.hpp b/src/mbgl/renderer/layers/symbol_layer_tweaker.hpp index ce06420ee..0c0d1030c 100644 --- a/src/mbgl/renderer/layers/symbol_layer_tweaker.hpp +++ b/src/mbgl/renderer/layers/symbol_layer_tweaker.hpp @@ -20,17 +20,7 @@ public: void execute(LayerGroupBase&, const PaintParameters&) override; private: - gfx::UniformBufferPtr textPaintBuffer; - gfx::UniformBufferPtr iconPaintBuffer; - gfx::UniformBufferPtr dynamicBuffer; - - bool textPropertiesUpdated = false; - bool iconPropertiesUpdated = false; - -#if MLN_RENDER_BACKEND_METAL - gfx::UniformBufferPtr permutationUniformBuffer; - gfx::UniformBufferPtr expressionUniformBuffer; -#endif // MLN_RENDER_BACKEND_METAL + gfx::UniformBufferPtr evaluatedPropsUniformBuffer; }; } // namespace mbgl diff --git a/src/mbgl/renderer/sources/render_tile_source.cpp b/src/mbgl/renderer/sources/render_tile_source.cpp index 57fdcc86d..b46267c53 100644 --- a/src/mbgl/renderer/sources/render_tile_source.cpp +++ b/src/mbgl/renderer/sources/render_tile_source.cpp @@ -143,8 +143,8 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr [&](TileLayerGroup* tileLayerGroup, const OverscaledTileID& tileID, const DebugUBO& debugUBO) -> size_t { auto updatedCount = tileLayerGroup->visitDrawables(renderPass, tileID, [&](gfx::Drawable& drawable) { // update existing drawable - auto& uniforms = drawable.mutableUniformBuffers(); - uniforms.createOrUpdate(idDebugUBO, &debugUBO, context); + auto& drawableUniforms = drawable.mutableUniformBuffers(); + drawableUniforms.createOrUpdate(idDebugUBO, &debugUBO, context); }); return updatedCount; }; @@ -172,8 +172,8 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr debugBuilder->flush(context); for (auto& drawable : debugBuilder->clearDrawables()) { drawable->setTileID(tileID); - auto& uniforms = drawable->mutableUniformBuffers(); - uniforms.createOrUpdate(idDebugUBO, &debugUBO, context); + auto& drawableUniforms = drawable->mutableUniformBuffers(); + drawableUniforms.createOrUpdate(idDebugUBO, &debugUBO, context); tileLayerGroup->addDrawable(renderPass, tileID, std::move(drawable)); } @@ -184,7 +184,7 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr const auto addPolylineDrawable = [&](TileLayerGroup* tileLayerGroup, const RenderTile& tile) { class PolylineDrawableTweaker : public gfx::DrawableTweaker { public: - PolylineDrawableTweaker(const shaders::LinePropertiesUBO& properties) + PolylineDrawableTweaker(const shaders::LineEvaluatedPropsUBO& properties) : linePropertiesUBO(properties) {} ~PolylineDrawableTweaker() override = default; @@ -208,29 +208,28 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr 0, 0}; - const shaders::LineUBO lineUBO{/*matrix = */ util::cast(matrix), - /*ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, zoom), - 0, - 0, - 0}; - - const shaders::LineInterpolationUBO lineInterpolationUBO{/*color_t =*/0.f, - /*blur_t =*/0.f, - /*opacity_t =*/0.f, - /*gapwidth_t =*/0.f, - /*offset_t =*/0.f, - /*width_t =*/0.f, - 0, - 0}; - auto& uniforms = drawable.mutableUniformBuffers(); - uniforms.createOrUpdate(idLineDynamicUBO, &dynamicUBO, parameters.context); - uniforms.createOrUpdate(idLineUBO, &lineUBO, parameters.context); - uniforms.createOrUpdate(idLinePropertiesUBO, &linePropertiesUBO, parameters.context); - uniforms.createOrUpdate(idLineInterpolationUBO, &lineInterpolationUBO, parameters.context); + const shaders::LineDrawableUBO drawableUBO = {/*matrix = */ util::cast(matrix), + /*ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, zoom), + 0, + 0, + 0}; + const shaders::LineInterpolationUBO lineInterpolationUBO = {/*color_t =*/0.f, + /*blur_t =*/0.f, + /*opacity_t =*/0.f, + /*gapwidth_t =*/0.f, + /*offset_t =*/0.f, + /*width_t =*/0.f, + 0, + 0}; + auto& drawableUniforms = drawable.mutableUniformBuffers(); + drawableUniforms.createOrUpdate(idLineDynamicUBO, &dynamicUBO, parameters.context); + drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, parameters.context); + drawableUniforms.createOrUpdate(idLineInterpolationUBO, &lineInterpolationUBO, parameters.context); + drawableUniforms.createOrUpdate(idLineEvaluatedPropsUBO, &linePropertiesUBO, parameters.context); }; private: - shaders::LinePropertiesUBO linePropertiesUBO; + shaders::LineEvaluatedPropsUBO linePropertiesUBO; }; GeometryCoordinates coords{{0, 0}, {util::EXTENT, 0}, {util::EXTENT, util::EXTENT}, {0, util::EXTENT}, {0, 0}}; @@ -244,15 +243,15 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr polylineBuilder->addPolyline(coords, options); // create line tweaker - const shaders::LinePropertiesUBO linePropertiesUBO{/*color*/ Color::red(), - /*blur*/ 0.f, - /*opacity*/ 1.f, - /*gapwidth*/ 0.f, - /*offset*/ 0.f, - /*width*/ 4.f, - 0, - 0, - 0}; + const shaders::LineEvaluatedPropsUBO linePropertiesUBO = {/*color*/ Color::red(), + /*blur*/ 0.f, + /*opacity*/ 1.f, + /*gapwidth*/ 0.f, + /*offset*/ 0.f, + /*width*/ 4.f, + /*floorwidth*/ 0, + 0, + 0}; auto tweaker = std::make_shared(linePropertiesUBO); // finish diff --git a/src/mbgl/shaders/gl/shader_info.cpp b/src/mbgl/shaders/gl/shader_info.cpp index 8e2724d8d..6432342bd 100644 --- a/src/mbgl/shaders/gl/shader_info.cpp +++ b/src/mbgl/shaders/gl/shader_info.cpp @@ -5,44 +5,50 @@ namespace mbgl { namespace shaders { -AttributeInfo::AttributeInfo(std::string_view name_, std::size_t id_) - : name(name_), - id(id_) {} - UniformBlockInfo::UniformBlockInfo(std::string_view name_, std::size_t id_) : name(name_), id(id_), binding(id_) {} +AttributeInfo::AttributeInfo(std::string_view name_, std::size_t id_) + : name(name_), + id(id_) {} + TextureInfo::TextureInfo(std::string_view name_, std::size_t id_) : name(name_), id(id_) {} // Background -const std::vector ShaderInfo::attributes = { - AttributeInfo{"a_pos", idBackgroundPosVertexAttribute}, -}; const std::vector ShaderInfo::uniformBlocks = { UniformBlockInfo{"BackgroundDrawableUBO", idBackgroundDrawableUBO}, UniformBlockInfo{"BackgroundLayerUBO", idBackgroundLayerUBO}, }; +const std::vector ShaderInfo::attributes = { + AttributeInfo{"a_pos", idBackgroundPosVertexAttribute}, +}; const std::vector ShaderInfo::textures = {}; // Background Pattern +const std::vector + ShaderInfo::uniformBlocks = { + UniformBlockInfo{"BackgroundPatternDrawableUBO", idBackgroundDrawableUBO}, + UniformBlockInfo{"BackgroundPatternLayerUBO", idBackgroundLayerUBO}, +}; const std::vector ShaderInfo::attributes = { AttributeInfo{"a_pos", idBackgroundPosVertexAttribute}, }; -const std::vector - ShaderInfo::uniformBlocks = { - UniformBlockInfo{"BackgroundDrawableUBO", idBackgroundDrawableUBO}, - UniformBlockInfo{"BackgroundLayerUBO", idBackgroundLayerUBO}, -}; const std::vector ShaderInfo::textures = { TextureInfo{"u_image", idBackgroundImageTexture}, }; // Circle +const std::vector ShaderInfo::uniformBlocks = { + UniformBlockInfo{"CircleDrawableUBO", idCircleDrawableUBO}, + UniformBlockInfo{"CirclePaintParamsUBO", idCirclePaintParamsUBO}, + UniformBlockInfo{"CircleEvaluatedPropsUBO", idCircleEvaluatedPropsUBO}, + UniformBlockInfo{"CircleInterpolateUBO", idCircleInterpolateUBO}, +}; const std::vector ShaderInfo::attributes = { AttributeInfo{"a_pos", idCirclePosVertexAttribute}, AttributeInfo{"a_color", idCircleColorVertexAttribute}, @@ -53,15 +59,13 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = { - UniformBlockInfo{"CircleDrawableUBO", idCircleDrawableUBO}, - UniformBlockInfo{"CirclePaintParamsUBO", idCirclePaintParamsUBO}, - UniformBlockInfo{"CircleEvaluatedPropsUBO", idCircleEvaluatedPropsUBO}, - UniformBlockInfo{"CircleInterpolateUBO", idCircleInterpolateUBO}, -}; const std::vector ShaderInfo::textures = {}; // Collision Box +const std::vector ShaderInfo::uniformBlocks = + { + UniformBlockInfo{"CollisionBoxUBO", idCollisionUBO}, +}; const std::vector ShaderInfo::attributes = { AttributeInfo{"a_pos", idCollisionPosVertexAttribute}, AttributeInfo{"a_anchor_pos", idCollisionAnchorPosVertexAttribute}, @@ -69,96 +73,99 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = - { - UniformBlockInfo{"CollisionBoxUBO", idCollisionUBO}, -}; const std::vector ShaderInfo::textures = {}; // Collision Circle +const std::vector + ShaderInfo::uniformBlocks = { + UniformBlockInfo{"CollisionCircleUBO", idCollisionUBO}, +}; const std::vector ShaderInfo::attributes = { AttributeInfo{"a_pos", idCollisionPosVertexAttribute}, AttributeInfo{"a_anchor_pos", idCollisionAnchorPosVertexAttribute}, AttributeInfo{"a_extrude", idCollisionExtrudeVertexAttribute}, AttributeInfo{"a_placed", idCollisionPlacedVertexAttribute}, }; -const std::vector - ShaderInfo::uniformBlocks = { - UniformBlockInfo{"CollisionCircleUBO", idCollisionUBO}, -}; const std::vector ShaderInfo::textures = {}; // Custom Symbol Icon -const std::vector ShaderInfo::attributes = { - AttributeInfo{"a_pos", idCustomSymbolPosVertexAttribute}, - AttributeInfo{"a_tex", idCustomSymbolTexVertexAttribute}, -}; const std::vector ShaderInfo::uniformBlocks = { UniformBlockInfo{"CustomSymbolIconDrawableUBO", idCustomSymbolDrawableUBO}, UniformBlockInfo{"CustomSymbolIconParametersUBO", idCustomSymbolParametersUBO}, }; +const std::vector ShaderInfo::attributes = { + AttributeInfo{"a_pos", idCustomSymbolPosVertexAttribute}, + AttributeInfo{"a_tex", idCustomSymbolTexVertexAttribute}, +}; const std::vector ShaderInfo::textures = { TextureInfo{"u_texture", idCustomSymbolImageTexture}, }; // Debug -const std::vector ShaderInfo::attributes = { - AttributeInfo{"a_pos", idDebugPosVertexAttribute}, -}; const std::vector ShaderInfo::uniformBlocks = { UniformBlockInfo{"DebugUBO", idDebugUBO}, }; +const std::vector ShaderInfo::attributes = { + AttributeInfo{"a_pos", idDebugPosVertexAttribute}, +}; const std::vector ShaderInfo::textures = { TextureInfo{"u_overlay", idDebugOverlayTexture}, }; // Fill +const std::vector ShaderInfo::uniformBlocks = { + UniformBlockInfo{"FillDrawableUBO", idFillDrawableUBO}, + UniformBlockInfo{"FillInterpolateUBO", idFillInterpolateUBO}, + UniformBlockInfo{"FillEvaluatedPropsUBO", idFillEvaluatedPropsUBO}, +}; const std::vector ShaderInfo::attributes = { AttributeInfo{"a_pos", idFillPosVertexAttribute}, AttributeInfo{"a_color", idFillColorVertexAttribute}, AttributeInfo{"a_opacity", idFillOpacityVertexAttribute}, }; -const std::vector ShaderInfo::uniformBlocks = { - UniformBlockInfo{"FillDrawableUBO", idFillDrawableUBO}, - UniformBlockInfo{"FillEvaluatedPropsUBO", idFillEvaluatedPropsUBO}, - UniformBlockInfo{"FillInterpolateUBO", idFillInterpolateUBO}, -}; const std::vector ShaderInfo::textures = {}; // Fill Outline +const std::vector ShaderInfo::uniformBlocks = + { + UniformBlockInfo{"FillOutlineDrawableUBO", idFillDrawableUBO}, + UniformBlockInfo{"FillOutlineInterpolateUBO", idFillInterpolateUBO}, + UniformBlockInfo{"FillEvaluatedPropsUBO", idFillEvaluatedPropsUBO}, +}; const std::vector ShaderInfo::attributes = { AttributeInfo{"a_pos", idFillPosVertexAttribute}, AttributeInfo{"a_outline_color", idFillOutlineColorVertexAttribute}, AttributeInfo{"a_opacity", idFillOpacityVertexAttribute}, }; -const std::vector ShaderInfo::uniformBlocks = - { - UniformBlockInfo{"FillOutlineDrawableUBO", idFillOutlineDrawableUBO}, - UniformBlockInfo{"FillOutlineEvaluatedPropsUBO", idFillOutlineEvaluatedPropsUBO}, - UniformBlockInfo{"FillOutlineInterpolateUBO", idFillOutlineInterpolateUBO}, -}; const std::vector ShaderInfo::textures = {}; // Fill Pattern +const std::vector ShaderInfo::uniformBlocks = + { + UniformBlockInfo{"FillPatternDrawableUBO", idFillDrawableUBO}, + UniformBlockInfo{"FillPatternTilePropsUBO", idFillTilePropsUBO}, + UniformBlockInfo{"FillPatternInterpolateUBO", idFillInterpolateUBO}, + UniformBlockInfo{"FillEvaluatedPropsUBO", idFillEvaluatedPropsUBO}, +}; const std::vector ShaderInfo::attributes = { AttributeInfo{"a_pos", idFillPosVertexAttribute}, AttributeInfo{"a_opacity", idFillOpacityVertexAttribute}, AttributeInfo{"a_pattern_from", idFillPatternFromVertexAttribute}, AttributeInfo{"a_pattern_to", idFillPatternToVertexAttribute}, }; -const std::vector ShaderInfo::uniformBlocks = - { - UniformBlockInfo{"FillPatternDrawableUBO", idFillPatternDrawableUBO}, - UniformBlockInfo{"FillPatternTilePropsUBO", idFillPatternTilePropsUBO}, - UniformBlockInfo{"FillPatternEvaluatedPropsUBO", idFillPatternEvaluatedPropsUBO}, - UniformBlockInfo{"FillPatternInterpolateUBO", idFillPatternInterpolateUBO}, -}; const std::vector ShaderInfo::textures = { TextureInfo{"u_image", idFillImageTexture}, }; // Fill Outline Pattern +const std::vector + ShaderInfo::uniformBlocks = { + UniformBlockInfo{"FillOutlinePatternDrawableUBO", idFillDrawableUBO}, + UniformBlockInfo{"FillOutlinePatternTilePropsUBO", idFillTilePropsUBO}, + UniformBlockInfo{"FillOutlinePatternInterpolateUBO", idFillInterpolateUBO}, + UniformBlockInfo{"FillEvaluatedPropsUBO", idFillEvaluatedPropsUBO}, +}; const std::vector ShaderInfo::attributes = { AttributeInfo{"a_pos", idFillPosVertexAttribute}, @@ -166,32 +173,32 @@ const std::vector ShaderInfo - ShaderInfo::uniformBlocks = { - UniformBlockInfo{"FillOutlinePatternDrawableUBO", idFillOutlinePatternDrawableUBO}, - UniformBlockInfo{"FillOutlinePatternTilePropsUBO", idFillOutlinePatternTilePropsUBO}, - UniformBlockInfo{"FillOutlinePatternEvaluatedPropsUBO", idFillOutlinePatternEvaluatedPropsUBO}, - UniformBlockInfo{"FillOutlinePatternInterpolateUBO", idFillOutlinePatternInterpolateUBO}, -}; const std::vector ShaderInfo::textures = { TextureInfo{"u_image", idFillImageTexture}, }; // Fill Outline Triangulated +const std::vector + ShaderInfo::uniformBlocks = { + UniformBlockInfo{"FillOutlineTriangulatedDrawableUBO", idFillDrawableUBO}, + UniformBlockInfo{"FillEvaluatedPropsUBO", idFillEvaluatedPropsUBO}, +}; const std::vector ShaderInfo::attributes = { AttributeInfo{"a_pos_normal", idLinePosNormalVertexAttribute}, AttributeInfo{"a_data", idLineDataVertexAttribute}, }; -const std::vector - ShaderInfo::uniformBlocks = { - UniformBlockInfo{"FillOutlineTriangulatedDrawableUBO", idFillOutlineTriangulatedDrawableUBO}, - UniformBlockInfo{"FillOutlineTriangulatedPropertiesUBO", idFillOutlineTriangulatedPropertiesUBO}, -}; const std::vector ShaderInfo::textures = {}; // Fill Extrusion +const std::vector + ShaderInfo::uniformBlocks = { + UniformBlockInfo{"FillExtrusionDrawableUBO", idFillExtrusionDrawableUBO}, + UniformBlockInfo{"FillExtrusionPropsUBO", idFillExtrusionPropsUBO}, + UniformBlockInfo{"FillExtrusionTilePropsUBO", idFillExtrusionTilePropsUBO}, + UniformBlockInfo{"FillExtrusionInterpolateUBO", idFillExtrusionInterpolateUBO}, +}; const std::vector ShaderInfo::attributes = { AttributeInfo{"a_pos", idFillExtrusionPosVertexAttribute}, AttributeInfo{"a_normal_ed", idFillExtrusionNormalEdVertexAttribute}, @@ -199,16 +206,16 @@ const std::vector ShaderInfo - ShaderInfo::uniformBlocks = { - UniformBlockInfo{"FillExtrusionDrawableUBO", idFillExtrusionDrawableUBO}, - UniformBlockInfo{"FillExtrusionDrawablePropsUBO", idFillExtrusionDrawablePropsUBO}, - UniformBlockInfo{"FillExtrusionDrawableTilePropsUBO", idFillExtrusionDrawableTilePropsUBO}, - UniformBlockInfo{"FillExtrusionInterpolateUBO", idFillExtrusionInterpolateUBO}, -}; const std::vector ShaderInfo::textures = {}; // Fill Extrusion Pattern +const std::vector + ShaderInfo::uniformBlocks = { + UniformBlockInfo{"FillExtrusionDrawableUBO", idFillExtrusionDrawableUBO}, + UniformBlockInfo{"FillExtrusionPropsUBO", idFillExtrusionPropsUBO}, + UniformBlockInfo{"FillExtrusionTilePropsUBO", idFillExtrusionTilePropsUBO}, + UniformBlockInfo{"FillExtrusionInterpolateUBO", idFillExtrusionInterpolateUBO}, +}; const std::vector ShaderInfo::attributes = { AttributeInfo{"a_pos", idFillExtrusionPosVertexAttribute}, @@ -218,37 +225,30 @@ const std::vector AttributeInfo{"a_pattern_from", idFillExtrusionPatternFromVertexAttribute}, AttributeInfo{"a_pattern_to", idFillExtrusionPatternToVertexAttribute}, }; -const std::vector - ShaderInfo::uniformBlocks = { - UniformBlockInfo{"FillExtrusionDrawableUBO", idFillExtrusionDrawableUBO}, - UniformBlockInfo{"FillExtrusionDrawablePropsUBO", idFillExtrusionDrawablePropsUBO}, - UniformBlockInfo{"FillExtrusionDrawableTilePropsUBO", idFillExtrusionDrawableTilePropsUBO}, - UniformBlockInfo{"FillExtrusionInterpolateUBO", idFillExtrusionInterpolateUBO}, -}; const std::vector ShaderInfo::textures = { TextureInfo{"u_image", idFillExtrusionImageTexture}, }; // Heatmap -const std::vector ShaderInfo::attributes = { - AttributeInfo{"a_pos", idHeatmapPosVertexAttribute}, - AttributeInfo{"a_weight", idHeatmapWeightVertexAttribute}, - AttributeInfo{"a_radius", idHeatmapRadiusVertexAttribute}, -}; const std::vector ShaderInfo::uniformBlocks = { UniformBlockInfo{"HeatmapDrawableUBO", idHeatmapDrawableUBO}, UniformBlockInfo{"HeatmapEvaluatedPropsUBO", idHeatmapEvaluatedPropsUBO}, UniformBlockInfo{"HeatmapInterpolateUBO", idHeatmapInterpolateUBO}, }; +const std::vector ShaderInfo::attributes = { + AttributeInfo{"a_pos", idHeatmapPosVertexAttribute}, + AttributeInfo{"a_weight", idHeatmapWeightVertexAttribute}, + AttributeInfo{"a_radius", idHeatmapRadiusVertexAttribute}, +}; const std::vector ShaderInfo::textures = {}; // Heatmap Texture -const std::vector ShaderInfo::attributes = { - AttributeInfo{"a_pos", idHeatmapPosVertexAttribute}, -}; const std::vector ShaderInfo::uniformBlocks = { - UniformBlockInfo{"HeatmapTextureDrawableUBO", idHeatmapTextureDrawableUBO}, + UniformBlockInfo{"HeatmapTexturePropsUBO", idHeatmapTexturePropsUBO}, +}; +const std::vector ShaderInfo::attributes = { + AttributeInfo{"a_pos", idHeatmapPosVertexAttribute}, }; const std::vector ShaderInfo::textures = { TextureInfo{"u_image", idHeatmapImageTexture}, @@ -256,32 +256,38 @@ const std::vector ShaderInfo ShaderInfo::attributes = { - AttributeInfo{"a_pos", idHillshadePosVertexAttribute}, - AttributeInfo{"a_texture_pos", idHillshadeTexturePosVertexAttribute}, -}; const std::vector ShaderInfo::uniformBlocks = { UniformBlockInfo{"HillshadePrepareDrawableUBO", idHillshadePrepareDrawableUBO}, }; +const std::vector ShaderInfo::attributes = { + AttributeInfo{"a_pos", idHillshadePosVertexAttribute}, + AttributeInfo{"a_texture_pos", idHillshadeTexturePosVertexAttribute}, +}; const std::vector ShaderInfo::textures = { TextureInfo{"u_image", idHillshadeImageTexture}, }; // Hillshade -const std::vector ShaderInfo::attributes = { - AttributeInfo{"a_pos", idHillshadePosVertexAttribute}, - AttributeInfo{"a_texture_pos", idHillshadeTexturePosVertexAttribute}, -}; const std::vector ShaderInfo::uniformBlocks = { UniformBlockInfo{"HillshadeDrawableUBO", idHillshadeDrawableUBO}, UniformBlockInfo{"HillshadeEvaluatedPropsUBO", idHillshadeEvaluatedPropsUBO}, }; +const std::vector ShaderInfo::attributes = { + AttributeInfo{"a_pos", idHillshadePosVertexAttribute}, + AttributeInfo{"a_texture_pos", idHillshadeTexturePosVertexAttribute}, +}; const std::vector ShaderInfo::textures = { TextureInfo{"u_image", idHillshadeImageTexture}, }; // Line +const std::vector ShaderInfo::uniformBlocks = { + UniformBlockInfo{"LineDynamicUBO", idLineDynamicUBO}, + UniformBlockInfo{"LineDrawableUBO", idLineDrawableUBO}, + UniformBlockInfo{"LineInterpolationUBO", idLineInterpolationUBO}, + UniformBlockInfo{"LineEvaluatedPropsUBO", idLineEvaluatedPropsUBO}, +}; const std::vector ShaderInfo::attributes = { AttributeInfo{"a_pos_normal", idLinePosNormalVertexAttribute}, AttributeInfo{"a_data", idLineDataVertexAttribute}, @@ -292,15 +298,16 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = { - UniformBlockInfo{"LineDynamicUBO", idLineDynamicUBO}, - UniformBlockInfo{"LineUBO", idLineUBO}, - UniformBlockInfo{"LinePropertiesUBO", idLinePropertiesUBO}, - UniformBlockInfo{"LineInterpolationUBO", idLineInterpolationUBO}, -}; const std::vector ShaderInfo::textures = {}; // Line Gradient +const std::vector ShaderInfo::uniformBlocks = + { + UniformBlockInfo{"LineDynamicUBO", idLineDynamicUBO}, + UniformBlockInfo{"LineGradientDrawableUBO", idLineDrawableUBO}, + UniformBlockInfo{"LineGradientInterpolationUBO", idLineInterpolationUBO}, + UniformBlockInfo{"LineEvaluatedPropsUBO", idLineEvaluatedPropsUBO}, +}; const std::vector ShaderInfo::attributes = { AttributeInfo{"a_pos_normal", idLinePosNormalVertexAttribute}, AttributeInfo{"a_data", idLineDataVertexAttribute}, @@ -310,18 +317,19 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = - { - UniformBlockInfo{"LineDynamicUBO", idLineDynamicUBO}, - UniformBlockInfo{"LineGradientUBO", idLineGradientUBO}, - UniformBlockInfo{"LineGradientPropertiesUBO", idLineGradientPropertiesUBO}, - UniformBlockInfo{"LineGradientInterpolationUBO", idLineGradientInterpolationUBO}, -}; const std::vector ShaderInfo::textures = { TextureInfo{"u_image", idLineImageTexture}, }; // Line Pattern +const std::vector ShaderInfo::uniformBlocks = + { + UniformBlockInfo{"LineDynamicUBO", idLineDynamicUBO}, + UniformBlockInfo{"LinePatternDrawableUBO", idLineDrawableUBO}, + UniformBlockInfo{"LinePatternInterpolationUBO", idLineInterpolationUBO}, + UniformBlockInfo{"LinePatternTilePropertiesUBO", idLineTilePropertiesUBO}, + UniformBlockInfo{"LineEvaluatedPropsUBO", idLineEvaluatedPropsUBO}, +}; const std::vector ShaderInfo::attributes = { AttributeInfo{"a_pos_normal", idLinePosNormalVertexAttribute}, AttributeInfo{"a_data", idLineDataVertexAttribute}, @@ -333,19 +341,17 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = - { - UniformBlockInfo{"LineDynamicUBO", idLineDynamicUBO}, - UniformBlockInfo{"LinePatternUBO", idLinePatternUBO}, - UniformBlockInfo{"LinePatternPropertiesUBO", idLinePatternPropertiesUBO}, - UniformBlockInfo{"LinePatternInterpolationUBO", idLinePatternInterpolationUBO}, - UniformBlockInfo{"LinePatternTilePropertiesUBO", idLinePatternTilePropertiesUBO}, -}; const std::vector ShaderInfo::textures = { TextureInfo{"u_image", idLineImageTexture}, }; // Line SDF +const std::vector ShaderInfo::uniformBlocks = { + UniformBlockInfo{"LineDynamicUBO", idLineDynamicUBO}, + UniformBlockInfo{"LineSDFDrawableUBO", idLineDrawableUBO}, + UniformBlockInfo{"LineSDFInterpolationUBO", idLineInterpolationUBO}, + UniformBlockInfo{"LineEvaluatedPropsUBO", idLineEvaluatedPropsUBO}, +}; const std::vector ShaderInfo::attributes = { AttributeInfo{"a_pos_normal", idLinePosNormalVertexAttribute}, AttributeInfo{"a_data", idLineDataVertexAttribute}, @@ -357,30 +363,32 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = { - UniformBlockInfo{"LineDynamicUBO", idLineDynamicUBO}, - UniformBlockInfo{"LineSDFUBO", idLineSDFUBO}, - UniformBlockInfo{"LineSDFPropertiesUBO", idLineSDFPropertiesUBO}, - UniformBlockInfo{"LineSDFInterpolationUBO", idLineSDFInterpolationUBO}, -}; const std::vector ShaderInfo::textures = { TextureInfo{"u_image", idLineImageTexture}, }; // Raster +const std::vector ShaderInfo::uniformBlocks = { + UniformBlockInfo{"RasterDrawableUBO", idRasterDrawableUBO}, + UniformBlockInfo{"RasterEvaluatedPropsUBO", idRasterEvaluatedPropsUBO}, +}; const std::vector ShaderInfo::attributes = { AttributeInfo{"a_pos", idRasterPosVertexAttribute}, AttributeInfo{"a_texture_pos", idRasterTexturePosVertexAttribute}, }; -const std::vector ShaderInfo::uniformBlocks = { - UniformBlockInfo{"RasterDrawableUBO", idRasterDrawableUBO}, -}; const std::vector ShaderInfo::textures = { TextureInfo{"u_image0", idRasterImage0Texture}, TextureInfo{"u_image1", idRasterImage0Texture}, }; // Symbol Icon +const std::vector ShaderInfo::uniformBlocks = { + UniformBlockInfo{"SymbolDynamicUBO", idSymbolDynamicUBO}, + UniformBlockInfo{"SymbolDrawableUBO", idSymbolDrawableUBO}, + UniformBlockInfo{"SymbolTilePropsUBO", idSymbolTilePropsUBO}, + UniformBlockInfo{"SymbolInterpolateUBO", idSymbolInterpolateUBO}, + UniformBlockInfo{"SymbolEvaluatedPropsUBO", idSymbolEvaluatedPropsUBO}, +}; const std::vector ShaderInfo::attributes = { AttributeInfo{"a_pos_offset", idSymbolPosOffsetVertexAttribute}, AttributeInfo{"a_data", idSymbolDataVertexAttribute}, @@ -389,18 +397,19 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = { - UniformBlockInfo{"SymbolDrawableUBO", idSymbolDrawableUBO}, - UniformBlockInfo{"SymbolDynamicUBO", idSymbolDynamicUBO}, - UniformBlockInfo{"SymbolDrawablePaintUBO", idSymbolDrawablePaintUBO}, - UniformBlockInfo{"SymbolDrawableTilePropsUBO", idSymbolDrawableTilePropsUBO}, - UniformBlockInfo{"SymbolDrawableInterpolateUBO", idSymbolDrawableInterpolateUBO}, -}; const std::vector ShaderInfo::textures = { TextureInfo{"u_texture", idSymbolImageTexture}, }; // Symbol SDF +const std::vector + ShaderInfo::uniformBlocks = { + UniformBlockInfo{"SymbolDynamicUBO", idSymbolDynamicUBO}, + UniformBlockInfo{"SymbolDrawableUBO", idSymbolDrawableUBO}, + UniformBlockInfo{"SymbolTilePropsUBO", idSymbolTilePropsUBO}, + UniformBlockInfo{"SymbolInterpolateUBO", idSymbolInterpolateUBO}, + UniformBlockInfo{"SymbolEvaluatedPropsUBO", idSymbolEvaluatedPropsUBO}, +}; const std::vector ShaderInfo::attributes = { AttributeInfo{"a_pos_offset", idSymbolPosOffsetVertexAttribute}, AttributeInfo{"a_data", idSymbolDataVertexAttribute}, @@ -413,19 +422,19 @@ const std::vector ShaderInfo - ShaderInfo::uniformBlocks = { - UniformBlockInfo{"SymbolDrawableUBO", idSymbolDrawableUBO}, - UniformBlockInfo{"SymbolDynamicUBO", idSymbolDynamicUBO}, - UniformBlockInfo{"SymbolDrawablePaintUBO", idSymbolDrawablePaintUBO}, - UniformBlockInfo{"SymbolDrawableTilePropsUBO", idSymbolDrawableTilePropsUBO}, - UniformBlockInfo{"SymbolDrawableInterpolateUBO", idSymbolDrawableInterpolateUBO}, -}; const std::vector ShaderInfo::textures = { TextureInfo{"u_texture", idSymbolImageTexture}, }; // Symbol Text & Icon +const std::vector + ShaderInfo::uniformBlocks = { + UniformBlockInfo{"SymbolDynamicUBO", idSymbolDynamicUBO}, + UniformBlockInfo{"SymbolDrawableUBO", idSymbolDrawableUBO}, + UniformBlockInfo{"SymbolTilePropsUBO", idSymbolTilePropsUBO}, + UniformBlockInfo{"SymbolInterpolateUBO", idSymbolInterpolateUBO}, + UniformBlockInfo{"SymbolEvaluatedPropsUBO", idSymbolEvaluatedPropsUBO}, +}; const std::vector ShaderInfo::attributes = { AttributeInfo{"a_pos_offset", idSymbolPosOffsetVertexAttribute}, @@ -438,14 +447,6 @@ const std::vector ShaderInfo - ShaderInfo::uniformBlocks = { - UniformBlockInfo{"SymbolDrawableUBO", idSymbolDrawableUBO}, - UniformBlockInfo{"SymbolDynamicUBO", idSymbolDynamicUBO}, - UniformBlockInfo{"SymbolDrawablePaintUBO", idSymbolDrawablePaintUBO}, - UniformBlockInfo{"SymbolDrawableTilePropsUBO", idSymbolDrawableTilePropsUBO}, - UniformBlockInfo{"SymbolDrawableInterpolateUBO", idSymbolDrawableInterpolateUBO}, -}; const std::vector ShaderInfo::textures = { TextureInfo{"u_texture", idSymbolImageTexture}, TextureInfo{"u_texture_icon", idSymbolImageIconTexture}, diff --git a/src/mbgl/shaders/mtl/background.cpp b/src/mbgl/shaders/mtl/background.cpp index 3effa4091..406e2b2d0 100644 --- a/src/mbgl/shaders/mtl/background.cpp +++ b/src/mbgl/shaders/mtl/background.cpp @@ -4,12 +4,12 @@ namespace mbgl { namespace shaders { -const std::array ShaderSource::attributes = { - AttributeInfo{0, gfx::AttributeDataType::Float3, idBackgroundPosVertexAttribute}, -}; const std::array ShaderSource::uniforms = { - UniformBlockInfo{1, true, false, sizeof(BackgroundDrawableUBO), idBackgroundDrawableUBO}, - UniformBlockInfo{2, false, true, sizeof(BackgroundLayerUBO), idBackgroundLayerUBO}, + UniformBlockInfo{true, false, sizeof(BackgroundDrawableUBO), idBackgroundDrawableUBO}, + UniformBlockInfo{false, true, sizeof(BackgroundLayerUBO), idBackgroundLayerUBO}, +}; +const std::array ShaderSource::attributes = { + AttributeInfo{backgroundUBOCount + 0, gfx::AttributeDataType::Float3, idBackgroundPosVertexAttribute}, }; const std::array ShaderSource::textures = {}; diff --git a/src/mbgl/shaders/mtl/background_pattern.cpp b/src/mbgl/shaders/mtl/background_pattern.cpp index 6d2629ce1..d7b761430 100644 --- a/src/mbgl/shaders/mtl/background_pattern.cpp +++ b/src/mbgl/shaders/mtl/background_pattern.cpp @@ -4,14 +4,14 @@ namespace mbgl { namespace shaders { -const std::array - ShaderSource::attributes = { - AttributeInfo{0, gfx::AttributeDataType::Float3, idBackgroundPosVertexAttribute}, -}; const std::array ShaderSource::uniforms = { - UniformBlockInfo{1, true, false, sizeof(BackgroundDrawableUBO), idBackgroundDrawableUBO}, - UniformBlockInfo{2, true, true, sizeof(BackgroundPatternLayerUBO), idBackgroundLayerUBO}, + UniformBlockInfo{true, false, sizeof(BackgroundPatternDrawableUBO), idBackgroundDrawableUBO}, + UniformBlockInfo{true, true, sizeof(BackgroundPatternLayerUBO), idBackgroundLayerUBO}, +}; +const std::array + ShaderSource::attributes = { + AttributeInfo{backgroundUBOCount + 0, gfx::AttributeDataType::Float3, idBackgroundPosVertexAttribute}, }; const std::array ShaderSource::textures = { TextureInfo{0, idBackgroundImageTexture}}; diff --git a/src/mbgl/shaders/mtl/circle.cpp b/src/mbgl/shaders/mtl/circle.cpp index f993b9ade..4efc1329d 100644 --- a/src/mbgl/shaders/mtl/circle.cpp +++ b/src/mbgl/shaders/mtl/circle.cpp @@ -3,21 +3,21 @@ namespace mbgl { namespace shaders { -const std::array ShaderSource::attributes = { - AttributeInfo{0, gfx::AttributeDataType::Short2, idCirclePosVertexAttribute}, - AttributeInfo{1, gfx::AttributeDataType::Float4, idCircleColorVertexAttribute}, - AttributeInfo{2, gfx::AttributeDataType::Float2, idCircleRadiusVertexAttribute}, - AttributeInfo{3, gfx::AttributeDataType::Float2, idCircleBlurVertexAttribute}, - AttributeInfo{4, gfx::AttributeDataType::Float2, idCircleOpacityVertexAttribute}, - AttributeInfo{5, gfx::AttributeDataType::Float4, idCircleStrokeColorVertexAttribute}, - AttributeInfo{6, gfx::AttributeDataType::Float2, idCircleStrokeWidthVertexAttribute}, - AttributeInfo{7, gfx::AttributeDataType::Float2, idCircleStrokeOpacityVertexAttribute}, -}; const std::array ShaderSource::uniforms = { - UniformBlockInfo{8, true, false, sizeof(CircleDrawableUBO), idCircleDrawableUBO}, - UniformBlockInfo{9, true, true, sizeof(CirclePaintParamsUBO), idCirclePaintParamsUBO}, - UniformBlockInfo{10, true, true, sizeof(CircleEvaluatedPropsUBO), idCircleEvaluatedPropsUBO}, - UniformBlockInfo{11, true, false, sizeof(CircleInterpolateUBO), idCircleInterpolateUBO}, + UniformBlockInfo{true, false, sizeof(CircleDrawableUBO), idCircleDrawableUBO}, + UniformBlockInfo{true, true, sizeof(CirclePaintParamsUBO), idCirclePaintParamsUBO}, + UniformBlockInfo{true, true, sizeof(CircleEvaluatedPropsUBO), idCircleEvaluatedPropsUBO}, + UniformBlockInfo{true, false, sizeof(CircleInterpolateUBO), idCircleInterpolateUBO}, +}; +const std::array ShaderSource::attributes = { + AttributeInfo{circleUBOCount + 0, gfx::AttributeDataType::Short2, idCirclePosVertexAttribute}, + AttributeInfo{circleUBOCount + 1, gfx::AttributeDataType::Float4, idCircleColorVertexAttribute}, + AttributeInfo{circleUBOCount + 2, gfx::AttributeDataType::Float2, idCircleRadiusVertexAttribute}, + AttributeInfo{circleUBOCount + 3, gfx::AttributeDataType::Float2, idCircleBlurVertexAttribute}, + AttributeInfo{circleUBOCount + 4, gfx::AttributeDataType::Float2, idCircleOpacityVertexAttribute}, + AttributeInfo{circleUBOCount + 5, gfx::AttributeDataType::Float4, idCircleStrokeColorVertexAttribute}, + AttributeInfo{circleUBOCount + 6, gfx::AttributeDataType::Float2, idCircleStrokeWidthVertexAttribute}, + AttributeInfo{circleUBOCount + 7, gfx::AttributeDataType::Float2, idCircleStrokeOpacityVertexAttribute}, }; const std::array ShaderSource::textures = {}; diff --git a/src/mbgl/shaders/mtl/clipping_mask.cpp b/src/mbgl/shaders/mtl/clipping_mask.cpp index e3eacf868..5b97d69a9 100644 --- a/src/mbgl/shaders/mtl/clipping_mask.cpp +++ b/src/mbgl/shaders/mtl/clipping_mask.cpp @@ -5,11 +5,11 @@ namespace shaders { using ShaderType = ShaderSource; -const std::array ShaderType::attributes = { - AttributeInfo{0, gfx::AttributeDataType::Float3, idClippingMaskPosVertexAttribute}, -}; const std::array ShaderType::uniforms = { - UniformBlockInfo{1, true, false, sizeof(ClipUBO), idClippingMaskUBO}, + UniformBlockInfo{true, false, sizeof(ClipUBO), idClippingMaskUBO}, +}; +const std::array ShaderType::attributes = { + AttributeInfo{clippingMaskUBOCount + 0, gfx::AttributeDataType::Float3, idClippingMaskPosVertexAttribute}, }; const std::array ShaderType::textures = {}; diff --git a/src/mbgl/shaders/mtl/collision_box.cpp b/src/mbgl/shaders/mtl/collision_box.cpp index ac1eb8899..2523a47da 100644 --- a/src/mbgl/shaders/mtl/collision_box.cpp +++ b/src/mbgl/shaders/mtl/collision_box.cpp @@ -3,15 +3,15 @@ namespace mbgl { namespace shaders { -const std::array ShaderSource::attributes = { - AttributeInfo{0, gfx::AttributeDataType::Short2, idCollisionPosVertexAttribute}, - AttributeInfo{1, gfx::AttributeDataType::Short2, idCollisionAnchorPosVertexAttribute}, - AttributeInfo{2, gfx::AttributeDataType::Short2, idCollisionExtrudeVertexAttribute}, - AttributeInfo{3, gfx::AttributeDataType::UShort2, idCollisionPlacedVertexAttribute}, - AttributeInfo{4, gfx::AttributeDataType::Float2, idCollisionShiftVertexAttribute}, -}; const std::array ShaderSource::uniforms = { - UniformBlockInfo{5, true, true, sizeof(CollisionUBO), idCollisionUBO}, + UniformBlockInfo{true, true, sizeof(CollisionUBO), idCollisionUBO}, +}; +const std::array ShaderSource::attributes = { + AttributeInfo{collisionUBOCount + 0, gfx::AttributeDataType::Short2, idCollisionPosVertexAttribute}, + AttributeInfo{collisionUBOCount + 1, gfx::AttributeDataType::Short2, idCollisionAnchorPosVertexAttribute}, + AttributeInfo{collisionUBOCount + 2, gfx::AttributeDataType::Short2, idCollisionExtrudeVertexAttribute}, + AttributeInfo{collisionUBOCount + 3, gfx::AttributeDataType::UShort2, idCollisionPlacedVertexAttribute}, + AttributeInfo{collisionUBOCount + 4, gfx::AttributeDataType::Float2, idCollisionShiftVertexAttribute}, }; const std::array ShaderSource::textures = {}; diff --git a/src/mbgl/shaders/mtl/collision_circle.cpp b/src/mbgl/shaders/mtl/collision_circle.cpp index e62054bbf..6a56729e2 100644 --- a/src/mbgl/shaders/mtl/collision_circle.cpp +++ b/src/mbgl/shaders/mtl/collision_circle.cpp @@ -3,16 +3,16 @@ namespace mbgl { namespace shaders { -const std::array ShaderSource::attributes = - { - AttributeInfo{0, gfx::AttributeDataType::Short2, idCollisionPosVertexAttribute}, - AttributeInfo{1, gfx::AttributeDataType::Short2, idCollisionAnchorPosVertexAttribute}, - AttributeInfo{2, gfx::AttributeDataType::Short2, idCollisionExtrudeVertexAttribute}, - AttributeInfo{3, gfx::AttributeDataType::UShort2, idCollisionPlacedVertexAttribute}, -}; const std::array ShaderSource::uniforms = { - UniformBlockInfo{4, true, true, sizeof(CollisionUBO), idCollisionUBO}, + UniformBlockInfo{true, true, sizeof(CollisionUBO), idCollisionUBO}, +}; +const std::array ShaderSource::attributes = + { + AttributeInfo{collisionUBOCount + 0, gfx::AttributeDataType::Short2, idCollisionPosVertexAttribute}, + AttributeInfo{collisionUBOCount + 1, gfx::AttributeDataType::Short2, idCollisionAnchorPosVertexAttribute}, + AttributeInfo{collisionUBOCount + 2, gfx::AttributeDataType::Short2, idCollisionExtrudeVertexAttribute}, + AttributeInfo{collisionUBOCount + 3, gfx::AttributeDataType::UShort2, idCollisionPlacedVertexAttribute}, }; const std::array ShaderSource::textures = {}; diff --git a/src/mbgl/shaders/mtl/custom_symbol_icon.cpp b/src/mbgl/shaders/mtl/custom_symbol_icon.cpp index 145d2fc23..0b6713c7c 100644 --- a/src/mbgl/shaders/mtl/custom_symbol_icon.cpp +++ b/src/mbgl/shaders/mtl/custom_symbol_icon.cpp @@ -3,16 +3,16 @@ namespace mbgl { namespace shaders { +const std::array + ShaderSource::uniforms = { + UniformBlockInfo{true, false, sizeof(CustomSymbolIconDrawableUBO), idCustomSymbolDrawableUBO}, + UniformBlockInfo{true, false, sizeof(CustomSymbolIconParametersUBO), idCustomSymbolParametersUBO}, +}; const std::array ShaderSource::attributes = { // always attributes - AttributeInfo{0, gfx::AttributeDataType::Float2, idCustomSymbolPosVertexAttribute}, - AttributeInfo{1, gfx::AttributeDataType::Float2, idCustomSymbolTexVertexAttribute}, -}; -const std::array - ShaderSource::uniforms = { - UniformBlockInfo{2, true, false, sizeof(CustomSymbolIconDrawableUBO), idCustomSymbolDrawableUBO}, - UniformBlockInfo{3, true, false, sizeof(CustomSymbolIconParametersUBO), idCustomSymbolParametersUBO}, + AttributeInfo{customSymbolUBOCount + 0, gfx::AttributeDataType::Float2, idCustomSymbolPosVertexAttribute}, + AttributeInfo{customSymbolUBOCount + 1, gfx::AttributeDataType::Float2, idCustomSymbolTexVertexAttribute}, }; const std::array ShaderSource::textures = { TextureInfo{0, idCustomSymbolImageTexture}, diff --git a/src/mbgl/shaders/mtl/debug.cpp b/src/mbgl/shaders/mtl/debug.cpp index d2eac2a00..0103f2708 100644 --- a/src/mbgl/shaders/mtl/debug.cpp +++ b/src/mbgl/shaders/mtl/debug.cpp @@ -3,11 +3,11 @@ namespace mbgl { namespace shaders { -const std::array ShaderSource::attributes = { - AttributeInfo{0, gfx::AttributeDataType::Short2, idDebugPosVertexAttribute}, -}; const std::array ShaderSource::uniforms = { - UniformBlockInfo{1, true, true, sizeof(DebugUBO), idDebugUBO}, + UniformBlockInfo{true, true, sizeof(DebugUBO), idDebugUBO}, +}; +const std::array ShaderSource::attributes = { + AttributeInfo{debugUBOCount + 0, gfx::AttributeDataType::Short2, idDebugPosVertexAttribute}, }; const std::array ShaderSource::textures = { TextureInfo{0, idDebugOverlayTexture}, diff --git a/src/mbgl/shaders/mtl/fill.cpp b/src/mbgl/shaders/mtl/fill.cpp index 893fd4ca4..0a49d9c88 100644 --- a/src/mbgl/shaders/mtl/fill.cpp +++ b/src/mbgl/shaders/mtl/fill.cpp @@ -3,75 +3,74 @@ namespace mbgl { namespace shaders { -const std::array ShaderSource::attributes = { - AttributeInfo{0, gfx::AttributeDataType::Short2, idFillPosVertexAttribute}, - AttributeInfo{1, gfx::AttributeDataType::Float4, idFillColorVertexAttribute}, - AttributeInfo{2, gfx::AttributeDataType::Float2, idFillOpacityVertexAttribute}, -}; const std::array ShaderSource::uniforms = { - UniformBlockInfo{3, true, false, sizeof(FillDrawableUBO), idFillDrawableUBO}, - UniformBlockInfo{4, true, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, - UniformBlockInfo{5, true, false, sizeof(FillInterpolateUBO), idFillInterpolateUBO}, + UniformBlockInfo{true, false, sizeof(FillDrawableUBO), idFillDrawableUBO}, + UniformBlockInfo{true, false, sizeof(FillInterpolateUBO), idFillInterpolateUBO}, + UniformBlockInfo{true, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, +}; +const std::array ShaderSource::attributes = { + AttributeInfo{fillUBOCount + 0, gfx::AttributeDataType::Short2, idFillPosVertexAttribute}, + AttributeInfo{fillUBOCount + 1, gfx::AttributeDataType::Float4, idFillColorVertexAttribute}, + AttributeInfo{fillUBOCount + 2, gfx::AttributeDataType::Float2, idFillOpacityVertexAttribute}, }; const std::array ShaderSource::textures = {}; -const std::array ShaderSource::attributes = { - AttributeInfo{0, gfx::AttributeDataType::Short2, idFillPosVertexAttribute}, - AttributeInfo{1, gfx::AttributeDataType::Float4, idFillOutlineColorVertexAttribute}, - AttributeInfo{2, gfx::AttributeDataType::Float2, idFillOpacityVertexAttribute}, -}; const std::array ShaderSource::uniforms = { - UniformBlockInfo{3, true, false, sizeof(FillOutlineDrawableUBO), idFillOutlineDrawableUBO}, - UniformBlockInfo{4, true, true, sizeof(FillOutlineEvaluatedPropsUBO), idFillOutlineEvaluatedPropsUBO}, - UniformBlockInfo{5, true, false, sizeof(FillOutlineInterpolateUBO), idFillOutlineInterpolateUBO}, + UniformBlockInfo{true, false, sizeof(FillOutlineDrawableUBO), idFillDrawableUBO}, + UniformBlockInfo{true, false, sizeof(FillOutlineInterpolateUBO), idFillInterpolateUBO}, + UniformBlockInfo{true, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, +}; +const std::array ShaderSource::attributes = { + AttributeInfo{fillUBOCount + 0, gfx::AttributeDataType::Short2, idFillPosVertexAttribute}, + AttributeInfo{fillUBOCount + 1, gfx::AttributeDataType::Float4, idFillOutlineColorVertexAttribute}, + AttributeInfo{fillUBOCount + 2, gfx::AttributeDataType::Float2, idFillOpacityVertexAttribute}, }; const std::array ShaderSource::textures = {}; -const std::array ShaderSource::attributes = { - AttributeInfo{0, gfx::AttributeDataType::Short2, idFillPosVertexAttribute}, - AttributeInfo{1, gfx::AttributeDataType::UShort4, idFillPatternFromVertexAttribute}, - AttributeInfo{2, gfx::AttributeDataType::UShort4, idFillPatternToVertexAttribute}, - AttributeInfo{3, gfx::AttributeDataType::Float2, idFillOpacityVertexAttribute}, -}; const std::array ShaderSource::uniforms = { - UniformBlockInfo{4, true, true, sizeof(FillPatternDrawableUBO), idFillPatternDrawableUBO}, - UniformBlockInfo{5, true, true, sizeof(FillPatternTilePropsUBO), idFillPatternTilePropsUBO}, - UniformBlockInfo{6, true, true, sizeof(FillPatternEvaluatedPropsUBO), idFillPatternEvaluatedPropsUBO}, - UniformBlockInfo{7, true, false, sizeof(FillPatternInterpolateUBO), idFillPatternInterpolateUBO}, + UniformBlockInfo{true, true, sizeof(FillPatternDrawableUBO), idFillDrawableUBO}, + UniformBlockInfo{true, true, sizeof(FillPatternTilePropsUBO), idFillTilePropsUBO}, + UniformBlockInfo{true, false, sizeof(FillPatternInterpolateUBO), idFillInterpolateUBO}, + UniformBlockInfo{true, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, +}; +const std::array ShaderSource::attributes = { + AttributeInfo{fillUBOCount + 0, gfx::AttributeDataType::Short2, idFillPosVertexAttribute}, + AttributeInfo{fillUBOCount + 1, gfx::AttributeDataType::UShort4, idFillPatternFromVertexAttribute}, + AttributeInfo{fillUBOCount + 2, gfx::AttributeDataType::UShort4, idFillPatternToVertexAttribute}, + AttributeInfo{fillUBOCount + 3, gfx::AttributeDataType::Float2, idFillOpacityVertexAttribute}, }; const std::array ShaderSource::textures = { TextureInfo{0, idFillImageTexture}, }; +const std::array + ShaderSource::uniforms = { + UniformBlockInfo{true, true, sizeof(FillOutlinePatternDrawableUBO), idFillDrawableUBO}, + UniformBlockInfo{true, true, sizeof(FillOutlinePatternTilePropsUBO), idFillTilePropsUBO}, + UniformBlockInfo{true, false, sizeof(FillOutlinePatternInterpolateUBO), idFillInterpolateUBO}, + UniformBlockInfo{true, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, +}; const std::array ShaderSource::attributes = { - AttributeInfo{0, gfx::AttributeDataType::Short2, idFillPosVertexAttribute}, - AttributeInfo{1, gfx::AttributeDataType::UShort4, idFillPatternFromVertexAttribute}, - AttributeInfo{2, gfx::AttributeDataType::UShort4, idFillPatternToVertexAttribute}, - AttributeInfo{3, gfx::AttributeDataType::Float2, idFillOpacityVertexAttribute}, -}; -const std::array ShaderSource::uniforms = { - UniformBlockInfo{4, true, true, sizeof(FillOutlinePatternDrawableUBO), idFillOutlinePatternDrawableUBO}, - UniformBlockInfo{5, true, true, sizeof(FillOutlinePatternTilePropsUBO), idFillOutlinePatternTilePropsUBO}, - UniformBlockInfo{6, true, true, sizeof(FillOutlinePatternEvaluatedPropsUBO), idFillOutlinePatternEvaluatedPropsUBO}, - UniformBlockInfo{7, true, false, sizeof(FillOutlinePatternInterpolateUBO), idFillOutlinePatternInterpolateUBO}, + AttributeInfo{fillUBOCount + 0, gfx::AttributeDataType::Short2, idFillPosVertexAttribute}, + AttributeInfo{fillUBOCount + 1, gfx::AttributeDataType::UShort4, idFillPatternFromVertexAttribute}, + AttributeInfo{fillUBOCount + 2, gfx::AttributeDataType::UShort4, idFillPatternToVertexAttribute}, + AttributeInfo{fillUBOCount + 3, gfx::AttributeDataType::Float2, idFillOpacityVertexAttribute}, }; const std::array ShaderSource::textures = { TextureInfo{0, idFillImageTexture}, }; +const std::array + ShaderSource::uniforms = { + UniformBlockInfo{true, false, sizeof(FillOutlineTriangulatedDrawableUBO), idFillDrawableUBO}, + UniformBlockInfo{true, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, +}; const std::array ShaderSource::attributes = { - AttributeInfo{0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, - AttributeInfo{1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, -}; -const std::array ShaderSource::uniforms = { - UniformBlockInfo{2, true, true, sizeof(FillOutlineTriangulatedDrawableUBO), idFillOutlineTriangulatedDrawableUBO}, - UniformBlockInfo{ - 3, true, true, sizeof(FillOutlineTriangulatedPropertiesUBO), idFillOutlineTriangulatedPropertiesUBO}, + AttributeInfo{fillUBOCount + 0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, + AttributeInfo{fillUBOCount + 1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, }; const std::array ShaderSource::textures = {}; diff --git a/src/mbgl/shaders/mtl/fill_extrusion.cpp b/src/mbgl/shaders/mtl/fill_extrusion.cpp index e8223697a..67d46d449 100644 --- a/src/mbgl/shaders/mtl/fill_extrusion.cpp +++ b/src/mbgl/shaders/mtl/fill_extrusion.cpp @@ -3,18 +3,18 @@ namespace mbgl { namespace shaders { -const std::array ShaderSource::attributes = { - AttributeInfo{0, gfx::AttributeDataType::Short2, idFillExtrusionPosVertexAttribute}, - AttributeInfo{1, gfx::AttributeDataType::Short4, idFillExtrusionNormalEdVertexAttribute}, - AttributeInfo{2, gfx::AttributeDataType::Float4, idFillExtrusionColorVertexAttribute}, - AttributeInfo{3, gfx::AttributeDataType::Float, idFillExtrusionBaseVertexAttribute}, - AttributeInfo{4, gfx::AttributeDataType::Float, idFillExtrusionHeightVertexAttribute}, -}; const std::array ShaderSource::uniforms = { - UniformBlockInfo{5, true, false, sizeof(FillExtrusionDrawableUBO), idFillExtrusionDrawableUBO}, - UniformBlockInfo{6, true, false, sizeof(FillExtrusionDrawablePropsUBO), idFillExtrusionDrawablePropsUBO}, - UniformBlockInfo{7, true, false, sizeof(FillExtrusionInterpolateUBO), idFillExtrusionInterpolateUBO}, + UniformBlockInfo{true, false, sizeof(FillExtrusionDrawableUBO), idFillExtrusionDrawableUBO}, + UniformBlockInfo{true, false, sizeof(FillExtrusionPropsUBO), idFillExtrusionPropsUBO}, + UniformBlockInfo{true, false, sizeof(FillExtrusionInterpolateUBO), idFillExtrusionInterpolateUBO}, +}; +const std::array ShaderSource::attributes = { + AttributeInfo{fillExtrusionUBOCount + 0, gfx::AttributeDataType::Short2, idFillExtrusionPosVertexAttribute}, + AttributeInfo{fillExtrusionUBOCount + 1, gfx::AttributeDataType::Short4, idFillExtrusionNormalEdVertexAttribute}, + AttributeInfo{fillExtrusionUBOCount + 2, gfx::AttributeDataType::Float4, idFillExtrusionColorVertexAttribute}, + AttributeInfo{fillExtrusionUBOCount + 3, gfx::AttributeDataType::Float, idFillExtrusionBaseVertexAttribute}, + AttributeInfo{fillExtrusionUBOCount + 4, gfx::AttributeDataType::Float, idFillExtrusionHeightVertexAttribute}, }; const std::array ShaderSource::textures = {}; diff --git a/src/mbgl/shaders/mtl/fill_extrusion_pattern.cpp b/src/mbgl/shaders/mtl/fill_extrusion_pattern.cpp index 3df13f684..0a9d5cf57 100644 --- a/src/mbgl/shaders/mtl/fill_extrusion_pattern.cpp +++ b/src/mbgl/shaders/mtl/fill_extrusion_pattern.cpp @@ -4,21 +4,22 @@ namespace mbgl { namespace shaders { -const std::array - ShaderSource::attributes = { - AttributeInfo{0, gfx::AttributeDataType::Short2, idFillExtrusionPosVertexAttribute}, - AttributeInfo{1, gfx::AttributeDataType::Short4, idFillExtrusionNormalEdVertexAttribute}, - AttributeInfo{2, gfx::AttributeDataType::Float, idFillExtrusionBaseVertexAttribute}, - AttributeInfo{3, gfx::AttributeDataType::Float, idFillExtrusionHeightVertexAttribute}, - AttributeInfo{4, gfx::AttributeDataType::UShort4, idFillExtrusionPatternFromVertexAttribute}, - AttributeInfo{5, gfx::AttributeDataType::UShort4, idFillExtrusionPatternToVertexAttribute}, -}; const std::array ShaderSource::uniforms = { - UniformBlockInfo{6, true, true, sizeof(FillExtrusionDrawableUBO), idFillExtrusionDrawableUBO}, - UniformBlockInfo{7, true, true, sizeof(FillExtrusionDrawablePropsUBO), idFillExtrusionDrawablePropsUBO}, - UniformBlockInfo{8, true, true, sizeof(FillExtrusionDrawableTilePropsUBO), idFillExtrusionDrawableTilePropsUBO}, - UniformBlockInfo{9, true, false, sizeof(FillExtrusionInterpolateUBO), idFillExtrusionInterpolateUBO}, + UniformBlockInfo{true, true, sizeof(FillExtrusionDrawableUBO), idFillExtrusionDrawableUBO}, + UniformBlockInfo{true, true, sizeof(FillExtrusionPropsUBO), idFillExtrusionPropsUBO}, + UniformBlockInfo{true, true, sizeof(FillExtrusionTilePropsUBO), idFillExtrusionTilePropsUBO}, + UniformBlockInfo{true, false, sizeof(FillExtrusionInterpolateUBO), idFillExtrusionInterpolateUBO}, +}; +const std::array ShaderSource::attributes = { + AttributeInfo{fillExtrusionUBOCount + 0, gfx::AttributeDataType::Short2, idFillExtrusionPosVertexAttribute}, + AttributeInfo{fillExtrusionUBOCount + 1, gfx::AttributeDataType::Short4, idFillExtrusionNormalEdVertexAttribute}, + AttributeInfo{fillExtrusionUBOCount + 2, gfx::AttributeDataType::Float, idFillExtrusionBaseVertexAttribute}, + AttributeInfo{fillExtrusionUBOCount + 3, gfx::AttributeDataType::Float, idFillExtrusionHeightVertexAttribute}, + AttributeInfo{ + fillExtrusionUBOCount + 4, gfx::AttributeDataType::UShort4, idFillExtrusionPatternFromVertexAttribute}, + AttributeInfo{fillExtrusionUBOCount + 5, gfx::AttributeDataType::UShort4, idFillExtrusionPatternToVertexAttribute}, }; const std::array ShaderSource::textures = { diff --git a/src/mbgl/shaders/mtl/heatmap.cpp b/src/mbgl/shaders/mtl/heatmap.cpp index 0ac7738da..c3952a7f7 100644 --- a/src/mbgl/shaders/mtl/heatmap.cpp +++ b/src/mbgl/shaders/mtl/heatmap.cpp @@ -3,15 +3,15 @@ namespace mbgl { namespace shaders { -const std::array ShaderSource::attributes = { - AttributeInfo{0, gfx::AttributeDataType::Short2, idHeatmapPosVertexAttribute}, - AttributeInfo{1, gfx::AttributeDataType::Float2, idHeatmapWeightVertexAttribute}, - AttributeInfo{2, gfx::AttributeDataType::Float2, idHeatmapRadiusVertexAttribute}, -}; const std::array ShaderSource::uniforms = { - UniformBlockInfo{3, true, false, sizeof(HeatmapDrawableUBO), idHeatmapDrawableUBO}, - UniformBlockInfo{4, true, true, sizeof(HeatmapEvaluatedPropsUBO), idHeatmapEvaluatedPropsUBO}, - UniformBlockInfo{5, true, false, sizeof(HeatmapInterpolateUBO), idHeatmapInterpolateUBO}, + UniformBlockInfo{true, false, sizeof(HeatmapDrawableUBO), idHeatmapDrawableUBO}, + UniformBlockInfo{true, true, sizeof(HeatmapEvaluatedPropsUBO), idHeatmapEvaluatedPropsUBO}, + UniformBlockInfo{true, false, sizeof(HeatmapInterpolateUBO), idHeatmapInterpolateUBO}, +}; +const std::array ShaderSource::attributes = { + AttributeInfo{heatmapUBOCount + 0, gfx::AttributeDataType::Short2, idHeatmapPosVertexAttribute}, + AttributeInfo{heatmapUBOCount + 1, gfx::AttributeDataType::Float2, idHeatmapWeightVertexAttribute}, + AttributeInfo{heatmapUBOCount + 2, gfx::AttributeDataType::Float2, idHeatmapRadiusVertexAttribute}, }; const std::array ShaderSource::textures = {}; diff --git a/src/mbgl/shaders/mtl/heatmap_texture.cpp b/src/mbgl/shaders/mtl/heatmap_texture.cpp index 944205d5e..c7843a03a 100644 --- a/src/mbgl/shaders/mtl/heatmap_texture.cpp +++ b/src/mbgl/shaders/mtl/heatmap_texture.cpp @@ -3,13 +3,13 @@ namespace mbgl { namespace shaders { -const std::array ShaderSource::attributes = - { - AttributeInfo{0, gfx::AttributeDataType::Short2, idHeatmapPosVertexAttribute}, -}; const std::array ShaderSource::uniforms = { - UniformBlockInfo{1, true, true, sizeof(HeatmapTextureDrawableUBO), idHeatmapTextureDrawableUBO}, + UniformBlockInfo{true, true, sizeof(HeatmapTexturePropsUBO), idHeatmapTexturePropsUBO}, +}; +const std::array ShaderSource::attributes = + { + AttributeInfo{heatmapTextureUBOCount + 0, gfx::AttributeDataType::Short2, idHeatmapPosVertexAttribute}, }; const std::array ShaderSource::textures = { TextureInfo{0, idHeatmapImageTexture}, diff --git a/src/mbgl/shaders/mtl/hillshade.cpp b/src/mbgl/shaders/mtl/hillshade.cpp index 6353df65c..079c8b309 100644 --- a/src/mbgl/shaders/mtl/hillshade.cpp +++ b/src/mbgl/shaders/mtl/hillshade.cpp @@ -3,13 +3,13 @@ namespace mbgl { namespace shaders { -const std::array ShaderSource::attributes = { - AttributeInfo{0, gfx::AttributeDataType::Short2, idHillshadePosVertexAttribute}, - AttributeInfo{1, gfx::AttributeDataType::Short2, idHillshadeTexturePosVertexAttribute}, -}; const std::array ShaderSource::uniforms = { - UniformBlockInfo{2, true, true, sizeof(HillshadeDrawableUBO), idHillshadeDrawableUBO}, - UniformBlockInfo{3, false, true, sizeof(HillshadeEvaluatedPropsUBO), idHillshadeEvaluatedPropsUBO}, + UniformBlockInfo{true, true, sizeof(HillshadeDrawableUBO), idHillshadeDrawableUBO}, + UniformBlockInfo{false, true, sizeof(HillshadeEvaluatedPropsUBO), idHillshadeEvaluatedPropsUBO}, +}; +const std::array ShaderSource::attributes = { + AttributeInfo{hillshadeUBOCount + 0, gfx::AttributeDataType::Short2, idHillshadePosVertexAttribute}, + AttributeInfo{hillshadeUBOCount + 1, gfx::AttributeDataType::Short2, idHillshadeTexturePosVertexAttribute}, }; const std::array ShaderSource::textures = { TextureInfo{0, idHillshadeImageTexture}, diff --git a/src/mbgl/shaders/mtl/hillshade_prepare.cpp b/src/mbgl/shaders/mtl/hillshade_prepare.cpp index a4efc7701..7465e2bb0 100644 --- a/src/mbgl/shaders/mtl/hillshade_prepare.cpp +++ b/src/mbgl/shaders/mtl/hillshade_prepare.cpp @@ -3,14 +3,14 @@ namespace mbgl { namespace shaders { -const std::array - ShaderSource::attributes = { - AttributeInfo{0, gfx::AttributeDataType::Short2, idHillshadePosVertexAttribute}, - AttributeInfo{1, gfx::AttributeDataType::Short2, idHillshadeTexturePosVertexAttribute}, -}; const std::array ShaderSource::uniforms = { - UniformBlockInfo{2, true, true, sizeof(HillshadePrepareDrawableUBO), idHillshadePrepareDrawableUBO}, + UniformBlockInfo{true, true, sizeof(HillshadePrepareDrawableUBO), idHillshadePrepareDrawableUBO}, +}; +const std::array ShaderSource::attributes = { + AttributeInfo{hillshadePrepareUBOCount + 0, gfx::AttributeDataType::Short2, idHillshadePosVertexAttribute}, + AttributeInfo{hillshadePrepareUBOCount + 1, gfx::AttributeDataType::Short2, idHillshadeTexturePosVertexAttribute}, }; const std::array ShaderSource::textures = { TextureInfo{0, idHillshadeImageTexture}, diff --git a/src/mbgl/shaders/mtl/line.cpp b/src/mbgl/shaders/mtl/line.cpp index 8b4a2b3f4..0ce4a3dc3 100644 --- a/src/mbgl/shaders/mtl/line.cpp +++ b/src/mbgl/shaders/mtl/line.cpp @@ -3,62 +3,81 @@ namespace mbgl { namespace shaders { -const std::array ShaderSource::attributes = { - AttributeInfo{0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, - AttributeInfo{1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, - AttributeInfo{2, gfx::AttributeDataType::Float4, idLineColorVertexAttribute}, - AttributeInfo{3, gfx::AttributeDataType::Float2, idLineBlurVertexAttribute}, - AttributeInfo{4, gfx::AttributeDataType::Float2, idLineOpacityVertexAttribute}, - AttributeInfo{5, gfx::AttributeDataType::Float2, idLineGapWidthVertexAttribute}, - AttributeInfo{6, gfx::AttributeDataType::Float2, idLineOffsetVertexAttribute}, - AttributeInfo{7, gfx::AttributeDataType::Float2, idLineWidthVertexAttribute}, -}; const std::array ShaderSource::uniforms = { - UniformBlockInfo{8, true, false, sizeof(LineDynamicUBO), idLineDynamicUBO}, - UniformBlockInfo{9, true, true, sizeof(LineUBO), idLineUBO}, - UniformBlockInfo{10, true, true, sizeof(LinePropertiesUBO), idLinePropertiesUBO}, - UniformBlockInfo{11, true, false, sizeof(LineInterpolationUBO), idLineInterpolationUBO}, + UniformBlockInfo{true, false, sizeof(LineDynamicUBO), idLineDynamicUBO}, + UniformBlockInfo{true, false, sizeof(idLineDrawableUBO), idLineDrawableUBO}, + UniformBlockInfo{true, false, sizeof(LineInterpolationUBO), idLineInterpolationUBO}, + UniformBlockInfo{true, true, sizeof(LineEvaluatedPropsUBO), idLineEvaluatedPropsUBO}, +}; +const std::array ShaderSource::attributes = { + AttributeInfo{lineUBOCount + 0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, + AttributeInfo{lineUBOCount + 1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, + AttributeInfo{lineUBOCount + 2, gfx::AttributeDataType::Float4, idLineColorVertexAttribute}, + AttributeInfo{lineUBOCount + 3, gfx::AttributeDataType::Float2, idLineBlurVertexAttribute}, + AttributeInfo{lineUBOCount + 4, gfx::AttributeDataType::Float2, idLineOpacityVertexAttribute}, + AttributeInfo{lineUBOCount + 5, gfx::AttributeDataType::Float2, idLineGapWidthVertexAttribute}, + AttributeInfo{lineUBOCount + 6, gfx::AttributeDataType::Float2, idLineOffsetVertexAttribute}, + AttributeInfo{lineUBOCount + 7, gfx::AttributeDataType::Float2, idLineWidthVertexAttribute}, }; const std::array ShaderSource::textures = {}; -const std::array ShaderSource::attributes = { - AttributeInfo{0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, - AttributeInfo{1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, - AttributeInfo{2, gfx::AttributeDataType::Float2, idLineBlurVertexAttribute}, - AttributeInfo{3, gfx::AttributeDataType::Float2, idLineOpacityVertexAttribute}, - AttributeInfo{4, gfx::AttributeDataType::Float2, idLineGapWidthVertexAttribute}, - AttributeInfo{5, gfx::AttributeDataType::Float2, idLineOffsetVertexAttribute}, - AttributeInfo{6, gfx::AttributeDataType::Float2, idLineWidthVertexAttribute}, - AttributeInfo{7, gfx::AttributeDataType::UShort4, idLinePatternFromVertexAttribute}, - AttributeInfo{8, gfx::AttributeDataType::UShort4, idLinePatternToVertexAttribute}, +const std::array ShaderSource::uniforms = { + UniformBlockInfo{true, false, sizeof(LineDynamicUBO), idLineDynamicUBO}, + UniformBlockInfo{true, false, sizeof(LineGradientDrawableUBO), idLineDrawableUBO}, + UniformBlockInfo{true, false, sizeof(LineGradientInterpolationUBO), idLineInterpolationUBO}, + UniformBlockInfo{true, true, sizeof(LineEvaluatedPropsUBO), idLineEvaluatedPropsUBO}, }; +const std::array ShaderSource::attributes = { + AttributeInfo{lineUBOCount + 0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, + AttributeInfo{lineUBOCount + 1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, + AttributeInfo{lineUBOCount + 2, gfx::AttributeDataType::Float2, idLineBlurVertexAttribute}, + AttributeInfo{lineUBOCount + 3, gfx::AttributeDataType::Float2, idLineOpacityVertexAttribute}, + AttributeInfo{lineUBOCount + 4, gfx::AttributeDataType::Float2, idLineGapWidthVertexAttribute}, + AttributeInfo{lineUBOCount + 5, gfx::AttributeDataType::Float2, idLineOffsetVertexAttribute}, + AttributeInfo{lineUBOCount + 6, gfx::AttributeDataType::Float2, idLineWidthVertexAttribute}, +}; +const std::array ShaderSource::textures = { + TextureInfo{0, idLineImageTexture}, +}; + const std::array ShaderSource::uniforms = { - UniformBlockInfo{9, true, false, sizeof(LineDynamicUBO), idLinePatternDynamicUBO}, - UniformBlockInfo{10, true, true, sizeof(LinePatternUBO), idLinePatternUBO}, - UniformBlockInfo{11, true, true, sizeof(LinePatternPropertiesUBO), idLinePatternPropertiesUBO}, - UniformBlockInfo{12, true, false, sizeof(LinePatternInterpolationUBO), idLinePatternInterpolationUBO}, - UniformBlockInfo{13, true, true, sizeof(LinePatternTilePropertiesUBO), idLinePatternTilePropertiesUBO}, + UniformBlockInfo{true, false, sizeof(LineDynamicUBO), idLineDynamicUBO}, + UniformBlockInfo{true, true, sizeof(LinePatternDrawableUBO), idLineDrawableUBO}, + UniformBlockInfo{true, false, sizeof(LinePatternInterpolationUBO), idLineInterpolationUBO}, + UniformBlockInfo{true, true, sizeof(LinePatternTilePropertiesUBO), idLineTilePropertiesUBO}, + UniformBlockInfo{true, true, sizeof(LineEvaluatedPropsUBO), idLineEvaluatedPropsUBO}, +}; +const std::array ShaderSource::attributes = { + AttributeInfo{lineUBOCount + 0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, + AttributeInfo{lineUBOCount + 1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, + AttributeInfo{lineUBOCount + 2, gfx::AttributeDataType::Float2, idLineBlurVertexAttribute}, + AttributeInfo{lineUBOCount + 3, gfx::AttributeDataType::Float2, idLineOpacityVertexAttribute}, + AttributeInfo{lineUBOCount + 4, gfx::AttributeDataType::Float2, idLineGapWidthVertexAttribute}, + AttributeInfo{lineUBOCount + 5, gfx::AttributeDataType::Float2, idLineOffsetVertexAttribute}, + AttributeInfo{lineUBOCount + 6, gfx::AttributeDataType::Float2, idLineWidthVertexAttribute}, + AttributeInfo{lineUBOCount + 7, gfx::AttributeDataType::UShort4, idLinePatternFromVertexAttribute}, + AttributeInfo{lineUBOCount + 8, gfx::AttributeDataType::UShort4, idLinePatternToVertexAttribute}, }; const std::array ShaderSource::textures = { TextureInfo{0, idLineImageTexture}, }; -const std::array ShaderSource::attributes = { - AttributeInfo{0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, - AttributeInfo{1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, - AttributeInfo{2, gfx::AttributeDataType::Float4, idLineColorVertexAttribute}, - AttributeInfo{3, gfx::AttributeDataType::Float2, idLineBlurVertexAttribute}, - AttributeInfo{4, gfx::AttributeDataType::Float2, idLineOpacityVertexAttribute}, - AttributeInfo{5, gfx::AttributeDataType::Float2, idLineGapWidthVertexAttribute}, - AttributeInfo{6, gfx::AttributeDataType::Float2, idLineOffsetVertexAttribute}, - AttributeInfo{7, gfx::AttributeDataType::Float2, idLineWidthVertexAttribute}, - AttributeInfo{8, gfx::AttributeDataType::Float2, idLineFloorWidthVertexAttribute}, -}; const std::array ShaderSource::uniforms = { - UniformBlockInfo{9, true, false, sizeof(LineDynamicUBO), idLineSDFDynamicUBO}, - UniformBlockInfo{10, true, true, sizeof(LineSDFUBO), idLineSDFUBO}, - UniformBlockInfo{11, true, true, sizeof(LineSDFPropertiesUBO), idLineSDFPropertiesUBO}, - UniformBlockInfo{12, true, false, sizeof(LineSDFInterpolationUBO), idLineSDFInterpolationUBO}, + UniformBlockInfo{true, false, sizeof(LineDynamicUBO), idLineDynamicUBO}, + UniformBlockInfo{true, true, sizeof(LineSDFDrawableUBO), idLineDrawableUBO}, + UniformBlockInfo{true, false, sizeof(LineSDFInterpolationUBO), idLineInterpolationUBO}, + UniformBlockInfo{true, true, sizeof(LineEvaluatedPropsUBO), idLineEvaluatedPropsUBO}, +}; +const std::array ShaderSource::attributes = { + AttributeInfo{lineUBOCount + 0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, + AttributeInfo{lineUBOCount + 1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, + AttributeInfo{lineUBOCount + 2, gfx::AttributeDataType::Float4, idLineColorVertexAttribute}, + AttributeInfo{lineUBOCount + 3, gfx::AttributeDataType::Float2, idLineBlurVertexAttribute}, + AttributeInfo{lineUBOCount + 4, gfx::AttributeDataType::Float2, idLineOpacityVertexAttribute}, + AttributeInfo{lineUBOCount + 5, gfx::AttributeDataType::Float2, idLineGapWidthVertexAttribute}, + AttributeInfo{lineUBOCount + 6, gfx::AttributeDataType::Float2, idLineOffsetVertexAttribute}, + AttributeInfo{lineUBOCount + 7, gfx::AttributeDataType::Float2, idLineWidthVertexAttribute}, + AttributeInfo{lineUBOCount + 8, gfx::AttributeDataType::Float2, idLineFloorWidthVertexAttribute}, }; const std::array ShaderSource::textures = { TextureInfo{0, idLineImageTexture}, diff --git a/src/mbgl/shaders/mtl/line_gradient.cpp b/src/mbgl/shaders/mtl/line_gradient.cpp deleted file mode 100644 index c44177070..000000000 --- a/src/mbgl/shaders/mtl/line_gradient.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include - -namespace mbgl { -namespace shaders { - -const std::array ShaderSource::attributes = { - AttributeInfo{0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, - AttributeInfo{1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, - AttributeInfo{2, gfx::AttributeDataType::Float2, idLineBlurVertexAttribute}, - AttributeInfo{3, gfx::AttributeDataType::Float2, idLineOpacityVertexAttribute}, - AttributeInfo{4, gfx::AttributeDataType::Float2, idLineGapWidthVertexAttribute}, - AttributeInfo{5, gfx::AttributeDataType::Float2, idLineOffsetVertexAttribute}, - AttributeInfo{6, gfx::AttributeDataType::Float2, idLineWidthVertexAttribute}, -}; -const std::array ShaderSource::uniforms = { - UniformBlockInfo{7, true, false, sizeof(LineDynamicUBO), idLineGradientDynamicUBO}, - UniformBlockInfo{8, true, true, sizeof(LineGradientUBO), idLineGradientUBO}, - UniformBlockInfo{9, true, true, sizeof(LineGradientPropertiesUBO), idLineGradientPropertiesUBO}, - UniformBlockInfo{10, true, false, sizeof(LineGradientInterpolationUBO), idLineGradientInterpolationUBO}, -}; -const std::array ShaderSource::textures = { - TextureInfo{0, idLineImageTexture}, -}; - -} // namespace shaders -} // namespace mbgl diff --git a/src/mbgl/shaders/mtl/raster.cpp b/src/mbgl/shaders/mtl/raster.cpp index ccfd9b821..a7a28418c 100644 --- a/src/mbgl/shaders/mtl/raster.cpp +++ b/src/mbgl/shaders/mtl/raster.cpp @@ -3,12 +3,13 @@ namespace mbgl { namespace shaders { -const std::array ShaderSource::attributes = { - AttributeInfo{0, gfx::AttributeDataType::Short2, idRasterPosVertexAttribute}, - AttributeInfo{1, gfx::AttributeDataType::Short2, idRasterTexturePosVertexAttribute}, +const std::array ShaderSource::uniforms = { + UniformBlockInfo{true, false, sizeof(RasterDrawableUBO), idRasterDrawableUBO}, + UniformBlockInfo{true, true, sizeof(RasterEvaluatedPropsUBO), idRasterEvaluatedPropsUBO}, }; -const std::array ShaderSource::uniforms = { - UniformBlockInfo{2, true, true, sizeof(RasterDrawableUBO), idRasterDrawableUBO}, +const std::array ShaderSource::attributes = { + AttributeInfo{rasterUBOCount + 0, gfx::AttributeDataType::Short2, idRasterPosVertexAttribute}, + AttributeInfo{rasterUBOCount + 1, gfx::AttributeDataType::Short2, idRasterTexturePosVertexAttribute}, }; const std::array ShaderSource::textures = { TextureInfo{0, idRasterImage0Texture}, diff --git a/src/mbgl/shaders/mtl/symbol_icon.cpp b/src/mbgl/shaders/mtl/symbol_icon.cpp index 1681044bd..8150f3952 100644 --- a/src/mbgl/shaders/mtl/symbol_icon.cpp +++ b/src/mbgl/shaders/mtl/symbol_icon.cpp @@ -3,23 +3,23 @@ namespace mbgl { namespace shaders { +const std::array ShaderSource::uniforms = { + UniformBlockInfo{true, true, sizeof(SymbolDynamicUBO), idSymbolDynamicUBO}, + UniformBlockInfo{true, true, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, + UniformBlockInfo{true, true, sizeof(SymbolTilePropsUBO), idSymbolTilePropsUBO}, + UniformBlockInfo{true, false, sizeof(SymbolInterpolateUBO), idSymbolInterpolateUBO}, + UniformBlockInfo{true, true, sizeof(SymbolEvaluatedPropsUBO), idSymbolEvaluatedPropsUBO}, +}; const std::array ShaderSource::attributes = { // always attributes - AttributeInfo{0, gfx::AttributeDataType::Short4, idSymbolPosOffsetVertexAttribute}, - AttributeInfo{1, gfx::AttributeDataType::UShort4, idSymbolDataVertexAttribute}, - AttributeInfo{2, gfx::AttributeDataType::Short4, idSymbolPixelOffsetVertexAttribute}, - AttributeInfo{3, gfx::AttributeDataType::Float3, idSymbolProjectedPosVertexAttribute}, - AttributeInfo{4, gfx::AttributeDataType::Float, idSymbolFadeOpacityVertexAttribute}, + AttributeInfo{symbolUBOCount + 0, gfx::AttributeDataType::Short4, idSymbolPosOffsetVertexAttribute}, + AttributeInfo{symbolUBOCount + 1, gfx::AttributeDataType::UShort4, idSymbolDataVertexAttribute}, + AttributeInfo{symbolUBOCount + 2, gfx::AttributeDataType::Short4, idSymbolPixelOffsetVertexAttribute}, + AttributeInfo{symbolUBOCount + 3, gfx::AttributeDataType::Float3, idSymbolProjectedPosVertexAttribute}, + AttributeInfo{symbolUBOCount + 4, gfx::AttributeDataType::Float, idSymbolFadeOpacityVertexAttribute}, // sometimes uniforms - AttributeInfo{5, gfx::AttributeDataType::Float, idSymbolOpacityVertexAttribute}, -}; -const std::array ShaderSource::uniforms = { - UniformBlockInfo{6, true, true, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, - UniformBlockInfo{7, true, false, sizeof(SymbolDynamicUBO), idSymbolDynamicUBO}, - UniformBlockInfo{8, true, true, sizeof(SymbolDrawablePaintUBO), idSymbolDrawablePaintUBO}, - UniformBlockInfo{9, true, false, sizeof(SymbolDrawableTilePropsUBO), idSymbolDrawableTilePropsUBO}, - UniformBlockInfo{10, true, false, sizeof(SymbolDrawableInterpolateUBO), idSymbolDrawableInterpolateUBO}, + AttributeInfo{symbolUBOCount + 5, gfx::AttributeDataType::Float, idSymbolOpacityVertexAttribute}, }; const std::array ShaderSource::textures = { TextureInfo{0, idSymbolImageTexture}, diff --git a/src/mbgl/shaders/mtl/symbol_sdf.cpp b/src/mbgl/shaders/mtl/symbol_sdf.cpp index 48a9edb70..0d4c42926 100644 --- a/src/mbgl/shaders/mtl/symbol_sdf.cpp +++ b/src/mbgl/shaders/mtl/symbol_sdf.cpp @@ -3,29 +3,29 @@ namespace mbgl { namespace shaders { +const std::array ShaderSource::uniforms = + { + UniformBlockInfo{true, true, sizeof(SymbolDynamicUBO), idSymbolDynamicUBO}, + UniformBlockInfo{true, true, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, + UniformBlockInfo{true, true, sizeof(SymbolTilePropsUBO), idSymbolTilePropsUBO}, + UniformBlockInfo{true, false, sizeof(SymbolInterpolateUBO), idSymbolInterpolateUBO}, + UniformBlockInfo{true, true, sizeof(SymbolEvaluatedPropsUBO), idSymbolEvaluatedPropsUBO}, +}; const std::array ShaderSource::attributes = { // always attributes - AttributeInfo{0, gfx::AttributeDataType::Short4, idSymbolPosOffsetVertexAttribute}, - AttributeInfo{1, gfx::AttributeDataType::UShort4, idSymbolDataVertexAttribute}, - AttributeInfo{2, gfx::AttributeDataType::Short4, idSymbolPixelOffsetVertexAttribute}, - AttributeInfo{3, gfx::AttributeDataType::Float3, idSymbolProjectedPosVertexAttribute}, - AttributeInfo{4, gfx::AttributeDataType::Float, idSymbolFadeOpacityVertexAttribute}, + AttributeInfo{symbolUBOCount + 0, gfx::AttributeDataType::Short4, idSymbolPosOffsetVertexAttribute}, + AttributeInfo{symbolUBOCount + 1, gfx::AttributeDataType::UShort4, idSymbolDataVertexAttribute}, + AttributeInfo{symbolUBOCount + 2, gfx::AttributeDataType::Short4, idSymbolPixelOffsetVertexAttribute}, + AttributeInfo{symbolUBOCount + 3, gfx::AttributeDataType::Float3, idSymbolProjectedPosVertexAttribute}, + AttributeInfo{symbolUBOCount + 4, gfx::AttributeDataType::Float, idSymbolFadeOpacityVertexAttribute}, // sometimes uniforms - AttributeInfo{5, gfx::AttributeDataType::Float4, idSymbolColorVertexAttribute}, - AttributeInfo{6, gfx::AttributeDataType::Float4, idSymbolHaloColorVertexAttribute}, - AttributeInfo{7, gfx::AttributeDataType::Float, idSymbolOpacityVertexAttribute}, - AttributeInfo{8, gfx::AttributeDataType::Float, idSymbolHaloWidthVertexAttribute}, - AttributeInfo{9, gfx::AttributeDataType::Float, idSymbolHaloBlurVertexAttribute}, -}; -const std::array ShaderSource::uniforms = - { - UniformBlockInfo{10, true, true, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, - UniformBlockInfo{11, true, true, sizeof(SymbolDynamicUBO), idSymbolDynamicUBO}, - UniformBlockInfo{12, true, true, sizeof(SymbolDrawablePaintUBO), idSymbolDrawablePaintUBO}, - UniformBlockInfo{13, true, true, sizeof(SymbolDrawableTilePropsUBO), idSymbolDrawableTilePropsUBO}, - UniformBlockInfo{14, true, false, sizeof(SymbolDrawableInterpolateUBO), idSymbolDrawableInterpolateUBO}, + AttributeInfo{symbolUBOCount + 5, gfx::AttributeDataType::Float4, idSymbolColorVertexAttribute}, + AttributeInfo{symbolUBOCount + 6, gfx::AttributeDataType::Float4, idSymbolHaloColorVertexAttribute}, + AttributeInfo{symbolUBOCount + 7, gfx::AttributeDataType::Float, idSymbolOpacityVertexAttribute}, + AttributeInfo{symbolUBOCount + 8, gfx::AttributeDataType::Float, idSymbolHaloWidthVertexAttribute}, + AttributeInfo{symbolUBOCount + 9, gfx::AttributeDataType::Float, idSymbolHaloBlurVertexAttribute}, }; const std::array ShaderSource::textures = { TextureInfo{0, idSymbolImageTexture}, diff --git a/src/mbgl/shaders/mtl/symbol_text_and_icon.cpp b/src/mbgl/shaders/mtl/symbol_text_and_icon.cpp index 83b8d6459..b4f7d539c 100644 --- a/src/mbgl/shaders/mtl/symbol_text_and_icon.cpp +++ b/src/mbgl/shaders/mtl/symbol_text_and_icon.cpp @@ -3,28 +3,28 @@ namespace mbgl { namespace shaders { +const std::array + ShaderSource::uniforms = { + UniformBlockInfo{true, true, sizeof(SymbolDynamicUBO), idSymbolDynamicUBO}, + UniformBlockInfo{true, true, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, + UniformBlockInfo{true, true, sizeof(SymbolTilePropsUBO), idSymbolTilePropsUBO}, + UniformBlockInfo{true, false, sizeof(SymbolInterpolateUBO), idSymbolInterpolateUBO}, + UniformBlockInfo{true, true, sizeof(SymbolEvaluatedPropsUBO), idSymbolEvaluatedPropsUBO}, +}; const std::array ShaderSource::attributes = { // always attributes - AttributeInfo{0, gfx::AttributeDataType::Short4, idSymbolPosOffsetVertexAttribute}, - AttributeInfo{1, gfx::AttributeDataType::UShort4, idSymbolDataVertexAttribute}, - AttributeInfo{2, gfx::AttributeDataType::Float3, idSymbolProjectedPosVertexAttribute}, - AttributeInfo{3, gfx::AttributeDataType::Float, idSymbolFadeOpacityVertexAttribute}, + AttributeInfo{symbolUBOCount + 0, gfx::AttributeDataType::Short4, idSymbolPosOffsetVertexAttribute}, + AttributeInfo{symbolUBOCount + 1, gfx::AttributeDataType::UShort4, idSymbolDataVertexAttribute}, + AttributeInfo{symbolUBOCount + 2, gfx::AttributeDataType::Float3, idSymbolProjectedPosVertexAttribute}, + AttributeInfo{symbolUBOCount + 3, gfx::AttributeDataType::Float, idSymbolFadeOpacityVertexAttribute}, // sometimes uniforms - AttributeInfo{4, gfx::AttributeDataType::Float4, idSymbolColorVertexAttribute}, - AttributeInfo{5, gfx::AttributeDataType::Float4, idSymbolHaloColorVertexAttribute}, - AttributeInfo{6, gfx::AttributeDataType::Float, idSymbolOpacityVertexAttribute}, - AttributeInfo{7, gfx::AttributeDataType::Float, idSymbolHaloWidthVertexAttribute}, - AttributeInfo{8, gfx::AttributeDataType::Float, idSymbolHaloBlurVertexAttribute}, -}; -const std::array - ShaderSource::uniforms = { - UniformBlockInfo{9, true, true, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, - UniformBlockInfo{10, true, true, sizeof(SymbolDynamicUBO), idSymbolDynamicUBO}, - UniformBlockInfo{11, true, true, sizeof(SymbolDrawablePaintUBO), idSymbolDrawablePaintUBO}, - UniformBlockInfo{12, true, true, sizeof(SymbolDrawableTilePropsUBO), idSymbolDrawableTilePropsUBO}, - UniformBlockInfo{13, true, false, sizeof(SymbolDrawableInterpolateUBO), idSymbolDrawableInterpolateUBO}, + AttributeInfo{symbolUBOCount + 4, gfx::AttributeDataType::Float4, idSymbolColorVertexAttribute}, + AttributeInfo{symbolUBOCount + 5, gfx::AttributeDataType::Float4, idSymbolHaloColorVertexAttribute}, + AttributeInfo{symbolUBOCount + 6, gfx::AttributeDataType::Float, idSymbolOpacityVertexAttribute}, + AttributeInfo{symbolUBOCount + 7, gfx::AttributeDataType::Float, idSymbolHaloWidthVertexAttribute}, + AttributeInfo{symbolUBOCount + 8, gfx::AttributeDataType::Float, idSymbolHaloBlurVertexAttribute}, }; const std::array ShaderSource::textures = { TextureInfo{0, idSymbolImageTexture}, diff --git a/src/mbgl/style/layers/custom_drawable_layer.cpp b/src/mbgl/style/layers/custom_drawable_layer.cpp index 19a879ac1..5f3db032a 100644 --- a/src/mbgl/style/layers/custom_drawable_layer.cpp +++ b/src/mbgl/style/layers/custom_drawable_layer.cpp @@ -89,7 +89,7 @@ const LayerTypeInfo* CustomDrawableLayer::Impl::staticTypeInfo() noexcept { class LineDrawableTweaker : public gfx::DrawableTweaker { public: - LineDrawableTweaker(const shaders::LinePropertiesUBO& properties) + LineDrawableTweaker(const shaders::LineEvaluatedPropsUBO& properties) : linePropertiesUBO(properties) {} void init(gfx::Drawable&) override {}; @@ -110,12 +110,11 @@ public: const shaders::LineDynamicUBO dynamicUBO = { /*units_to_pixels = */ {1.0f / parameters.pixelsToGLUnits[0], 1.0f / parameters.pixelsToGLUnits[1]}, 0, 0}; - const shaders::LineUBO lineUBO{/*matrix = */ util::cast(matrix), - /*ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, zoom), - 0, - 0, - 0}; - + const shaders::LineDrawableUBO drawableUBO = {/*matrix = */ util::cast(matrix), + /*ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, zoom), + 0, + 0, + 0}; const shaders::LineInterpolationUBO lineInterpolationUBO{/*color_t =*/0.f, /*blur_t =*/0.f, /*opacity_t =*/0.f, @@ -124,15 +123,15 @@ public: /*width_t =*/0.f, 0, 0}; - auto& uniforms = drawable.mutableUniformBuffers(); - uniforms.createOrUpdate(idLineDynamicUBO, &dynamicUBO, parameters.context); - uniforms.createOrUpdate(idLineUBO, &lineUBO, parameters.context); - uniforms.createOrUpdate(idLinePropertiesUBO, &linePropertiesUBO, parameters.context); - uniforms.createOrUpdate(idLineInterpolationUBO, &lineInterpolationUBO, parameters.context); + auto& drawableUniforms = drawable.mutableUniformBuffers(); + drawableUniforms.createOrUpdate(idLineDynamicUBO, &dynamicUBO, parameters.context); + drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, parameters.context); + drawableUniforms.createOrUpdate(idLineInterpolationUBO, &lineInterpolationUBO, parameters.context); + drawableUniforms.createOrUpdate(idLineEvaluatedPropsUBO, &linePropertiesUBO, parameters.context); }; private: - shaders::LinePropertiesUBO linePropertiesUBO; + shaders::LineEvaluatedPropsUBO linePropertiesUBO; }; class WideVectorDrawableTweaker : public gfx::DrawableTweaker { @@ -189,9 +188,9 @@ public: /*interClipLimit*/ 0.0f // N/A }; - auto& uniforms = drawable.mutableUniformBuffers(); - uniforms.createOrUpdate(idWideVectorUniformsUBO, &uniform, parameters.context); - uniforms.createOrUpdate(idWideVectorUniformWideVecUBO, &wideVec, parameters.context); + auto& drawableUniforms = drawable.mutableUniformBuffers(); + drawableUniforms.createOrUpdate(idWideVectorUniformsUBO, &uniform, parameters.context); + drawableUniforms.createOrUpdate(idWideVectorUniformWideVecUBO, &wideVec, parameters.context); }; private: @@ -218,15 +217,7 @@ public: const auto matrix = LayerTweaker::getTileMatrix( tileID, parameters, {{0, 0}}, style::TranslateAnchorType::Viewport, false, false, drawable, false); - const shaders::FillDrawableUBO fillUBO{/*matrix = */ util::cast(matrix)}; - - const shaders::FillEvaluatedPropsUBO fillPropertiesUBO{ - /* .color = */ color, - /* .opacity = */ opacity, - 0, - 0, - 0, - }; + const shaders::FillDrawableUBO fillDrawableUBO{/*matrix = */ util::cast(matrix)}; const shaders::FillInterpolateUBO fillInterpolateUBO{ /* .color_t = */ 0.f, @@ -234,10 +225,18 @@ public: 0, 0, }; - auto& uniforms = drawable.mutableUniformBuffers(); - uniforms.createOrUpdate(idFillDrawableUBO, &fillUBO, parameters.context); - uniforms.createOrUpdate(idFillEvaluatedPropsUBO, &fillPropertiesUBO, parameters.context); - uniforms.createOrUpdate(idFillInterpolateUBO, &fillInterpolateUBO, parameters.context); + const shaders::FillEvaluatedPropsUBO fillPropertiesUBO{ + /* .color = */ color, + /* .outline_color = */ Color::white(), + /* .opacity = */ opacity, + /* .fade = */ 0.f, + /* .width = */ 0.f, + 0, + }; + auto& drawableUniforms = drawable.mutableUniformBuffers(); + drawableUniforms.createOrUpdate(idFillDrawableUBO, &fillDrawableUBO, parameters.context); + drawableUniforms.createOrUpdate(idFillInterpolateUBO, &fillInterpolateUBO, parameters.context); + drawableUniforms.createOrUpdate(idFillEvaluatedPropsUBO, &fillPropertiesUBO, parameters.context); }; private: @@ -288,9 +287,9 @@ public: 0}; // set UBOs - auto& uniforms = drawable.mutableUniformBuffers(); - uniforms.createOrUpdate(idCustomSymbolDrawableUBO, &drawableUBO, parameters.context); - uniforms.createOrUpdate(idCustomSymbolParametersUBO, ¶metersUBO, parameters.context); + auto& drawableUniforms = drawable.mutableUniformBuffers(); + drawableUniforms.createOrUpdate(idCustomSymbolDrawableUBO, &drawableUBO, parameters.context); + drawableUniforms.createOrUpdate(idCustomSymbolParametersUBO, ¶metersUBO, parameters.context); }; private: @@ -535,15 +534,15 @@ void CustomDrawableLayerHost::Interface::finish() { // finish building classic lines // create line tweaker - const shaders::LinePropertiesUBO linePropertiesUBO{lineOptions.color, - lineOptions.blur, - lineOptions.opacity, - lineOptions.gapWidth, - lineOptions.offset, - lineOptions.width, - 0, - 0, - 0}; + const shaders::LineEvaluatedPropsUBO linePropertiesUBO = {lineOptions.color, + lineOptions.blur, + lineOptions.opacity, + lineOptions.gapWidth, + lineOptions.offset, + lineOptions.width, + 0, + 0, + 0}; auto tweaker = std::make_shared(linePropertiesUBO); // finish drawables diff --git a/test/util/hash.test.cpp b/test/util/hash.test.cpp index 1cab6fbc5..ce5c314b3 100644 --- a/test/util/hash.test.cpp +++ b/test/util/hash.test.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include