Global UBO (#2292)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Alex Cristici
2024-04-24 17:14:18 +03:00
committed by GitHub
parent 54a07f4b9c
commit d22362ab22
115 changed files with 966 additions and 659 deletions

View File

@@ -155,6 +155,17 @@ public:
return emplaceOrUpdateUniformBuffer(ptr, data, sizeof(T), persistent);
}
/// Get the global uniform buffers
virtual const gfx::UniformBufferArray& getGlobalUniformBuffers() const = 0;
/// Get the mutable global uniform buffer array
virtual gfx::UniformBufferArray& mutableGlobalUniformBuffers() = 0;
/// Bind the global uniform buffers
virtual void bindGlobalUniformBuffers(gfx::RenderPass&) const noexcept = 0;
/// Unbind the global uniform buffers
virtual void unbindGlobalUniformBuffers(gfx::RenderPass&) const noexcept = 0;
#endif
protected:

View File

@@ -9,6 +9,7 @@
#include <mbgl/gfx/context.hpp>
#include <mbgl/mtl/buffer_resource.hpp>
#include <mbgl/mtl/mtl_fwd.hpp>
#include <mbgl/mtl/uniform_buffer.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/containers.hpp>
@@ -144,6 +145,18 @@ public:
RenderStaticData& staticData,
const std::vector<shaders::ClipUBO>& tileUBOs);
/// Get the global uniform buffers
const gfx::UniformBufferArray& getGlobalUniformBuffers() const override { return globalUniformBuffers; };
/// Get the mutable global uniform buffer array
gfx::UniformBufferArray& mutableGlobalUniformBuffers() override { return globalUniformBuffers; };
/// Bind the global uniform buffers
void bindGlobalUniformBuffers(gfx::RenderPass&) const noexcept override;
/// Unbind the global uniform buffers
void unbindGlobalUniformBuffers(gfx::RenderPass&) const noexcept override {}
private:
RendererBackend& backend;
bool cleanupOnDestruction = true;
@@ -160,6 +173,8 @@ private:
std::optional<BufferResource> clipMaskUniformsBuffer;
bool clipMaskUniformsBufferUsed = false;
const gfx::Renderable* stencilStateRenderable = nullptr;
UniformBufferArray globalUniformBuffers;
};
} // namespace mtl

View File

@@ -40,20 +40,18 @@ struct alignas(16) BackgroundPatternLayerUBO {
/* 8 */ std::array<float, 2> pattern_br_a;
/* 16 */ std::array<float, 2> pattern_tl_b;
/* 24 */ std::array<float, 2> pattern_br_b;
/* 32 */ std::array<float, 2> texsize;
/* 40 */ std::array<float, 2> pattern_size_a;
/* 48 */ std::array<float, 2> pattern_size_b;
/* 56 */ float scale_a;
/* 60 */ float scale_b;
/* 64 */ float mix;
/* 68 */ float opacity;
/* 72 */ float pad1, pad2;
/* 80 */
/* 32 */ std::array<float, 2> pattern_size_a;
/* 40 */ std::array<float, 2> pattern_size_b;
/* 48 */ float scale_a;
/* 52 */ float scale_b;
/* 56 */ float mix;
/* 60 */ float opacity;
/* 64 */
};
static_assert(sizeof(BackgroundPatternLayerUBO) == 80);
static_assert(sizeof(BackgroundPatternLayerUBO) == 64);
enum {
idBackgroundDrawableUBO,
idBackgroundDrawableUBO = globalUBOCount,
idBackgroundLayerUBO,
backgroundUBOCount
};

View File

@@ -47,8 +47,7 @@ struct alignas(16) CircleInterpolateUBO {
static_assert(sizeof(CircleInterpolateUBO) % 16 == 0);
enum {
idCircleDrawableUBO,
idCirclePaintParamsUBO,
idCircleDrawableUBO = globalUBOCount,
idCircleEvaluatedPropsUBO,
idCircleInterpolateUBO,
circleUBOCount

View File

@@ -8,14 +8,14 @@ namespace shaders {
struct alignas(16) CollisionUBO {
std::array<float, 4 * 4> matrix;
std::array<float, 2> extrude_scale;
float camera_to_center_distance;
float overscale_factor;
float pad;
};
static_assert(sizeof(CollisionUBO) % 16 == 0);
static_assert(sizeof(CollisionUBO) == 80);
enum {
idCollisionUBO,
idCollisionUBO = globalUBOCount,
collisionUBOCount
};

View File

@@ -27,7 +27,7 @@ struct alignas(16) CustomSymbolIconParametersUBO {
static_assert(sizeof(CustomSymbolIconParametersUBO) == 3 * 16);
enum {
idCustomSymbolDrawableUBO,
idCustomSymbolDrawableUBO = globalUBOCount,
idCustomSymbolParametersUBO,
customSymbolUBOCount
};

View File

@@ -14,7 +14,7 @@ struct alignas(16) DebugUBO {
static_assert(sizeof(DebugUBO) % 16 == 0);
enum {
idDebugUBO,
idDebugUBO = globalUBOCount,
debugUBOCount
};

View File

@@ -8,16 +8,15 @@ namespace mbgl {
namespace shaders {
struct alignas(16) FillExtrusionDrawableUBO {
/* 0 */ std::array<float, 4 * 4> matrix;
/* 64 */ std::array<float, 4> scale;
/* 80 */ std::array<float, 2> texsize;
/* 88 */ std::array<float, 2> pixel_coord_upper;
/* 96 */ std::array<float, 2> pixel_coord_lower;
/* 104 */ float height_factor;
/* 108 */ float pad;
/* 112 */
/* 0 */ std::array<float, 4 * 4> matrix;
/* 64 */ std::array<float, 2> texsize;
/* 72 */ std::array<float, 2> pixel_coord_upper;
/* 80 */ std::array<float, 2> pixel_coord_lower;
/* 88 */ float height_factor;
/* 92 */ float tile_ratio;
/* 96 */
};
static_assert(sizeof(FillExtrusionDrawableUBO) == 7 * 16);
static_assert(sizeof(FillExtrusionDrawableUBO) == 6 * 16);
/// Evaluated properties that do not depend on the tile
struct alignas(16) FillExtrusionPropsUBO {
@@ -31,7 +30,9 @@ struct alignas(16) FillExtrusionPropsUBO {
/* 56 */ float vertical_gradient;
/* 60 */ float opacity;
/* 64 */ float fade;
/* 68 */ float pad2, pad3, pad4;
/* 68 */ float from_scale;
/* 72 */ float to_scale;
/* 76 */ float pad2;
/* 80 */
};
static_assert(sizeof(FillExtrusionPropsUBO) == 5 * 16);
@@ -57,7 +58,7 @@ struct alignas(16) FillExtrusionInterpolateUBO {
static_assert(sizeof(FillExtrusionInterpolateUBO) == 2 * 16);
enum {
idFillExtrusionDrawableUBO,
idFillExtrusionDrawableUBO = globalUBOCount,
idFillExtrusionPropsUBO,
idFillExtrusionTilePropsUBO,
idFillExtrusionInterpolateUBO,

View File

@@ -10,6 +10,7 @@ namespace shaders {
struct alignas(16) FillDrawableUBO {
/* 0 */ std::array<float, 4 * 4> matrix; // composite model-view-projection matrix
/* 64 */
};
static_assert(sizeof(FillDrawableUBO) == 4 * 16);
@@ -25,11 +26,9 @@ static_assert(sizeof(FillInterpolateUBO) % 16 == 0);
struct alignas(16) FillOutlineDrawableUBO {
/* 0 */ std::array<float, 4 * 4> matrix; // composite model-view-projection matrix
/* 64 */ std::array<float, 2> world;
/* 72 */ float pad1, pad2;
/* 80 */
/* 64 */
};
static_assert(sizeof(FillOutlineDrawableUBO) == 5 * 16);
static_assert(sizeof(FillOutlineDrawableUBO) == 4 * 16);
struct alignas(16) FillOutlineInterpolateUBO {
float outline_color_t;
@@ -43,14 +42,14 @@ static_assert(sizeof(FillOutlineInterpolateUBO) == 1 * 16);
struct alignas(16) FillPatternDrawableUBO {
/* 0 */ std::array<float, 4 * 4> matrix; // composite model-view-projection matrix
/* 64 */ std::array<float, 4> scale;
/* 80 */ std::array<float, 2> pixel_coord_upper;
/* 88 */ std::array<float, 2> pixel_coord_lower;
/* 96 */ std::array<float, 2> texsize;
/* 104 */ float pad1, pad2;
/* 112 */
/* 64 */ std::array<float, 2> pixel_coord_upper;
/* 72 */ std::array<float, 2> pixel_coord_lower;
/* 80 */ std::array<float, 2> texsize;
/* 88 */ float tile_ratio;
/* 92 */ float pad;
/* 96 */
};
static_assert(sizeof(FillPatternDrawableUBO) == 7 * 16);
static_assert(sizeof(FillPatternDrawableUBO) == 6 * 16);
struct alignas(16) FillPatternTilePropsUBO {
std::array<float, 4> pattern_from;
@@ -71,13 +70,14 @@ static_assert(sizeof(FillPatternInterpolateUBO) == 1 * 16);
struct alignas(16) FillOutlinePatternDrawableUBO {
/* 0 */ std::array<float, 4 * 4> matrix; // composite model-view-projection matrix
/* 64 */ std::array<float, 4> scale;
/* 80 */ std::array<float, 2> world;
/* 88 */ std::array<float, 2> pixel_coord_upper;
/* 96 */ std::array<float, 2> pixel_coord_lower;
/* 104 */ std::array<float, 2> texsize;
/* 64 */ std::array<float, 2> pixel_coord_upper;
/* 72 */ std::array<float, 2> pixel_coord_lower;
/* 80 */ std::array<float, 2> texsize;
/* 88 */ float tile_ratio;
/* 92 */ float pad;
/* 96 */
};
static_assert(sizeof(FillOutlinePatternDrawableUBO) == 7 * 16);
static_assert(sizeof(FillOutlinePatternDrawableUBO) == 6 * 16);
struct alignas(16) FillOutlinePatternTilePropsUBO {
std::array<float, 4> pattern_from;
@@ -98,9 +98,8 @@ static_assert(sizeof(FillOutlinePatternInterpolateUBO) == 1 * 16);
struct alignas(16) FillOutlineTriangulatedDrawableUBO {
std::array<float, 4 * 4> matrix;
std::array<float, 2> units_to_pixels;
float ratio;
float pad;
float pad1, pad2, pad3;
};
static_assert(sizeof(FillOutlineTriangulatedDrawableUBO) % 16 == 0);
@@ -112,13 +111,13 @@ struct alignas(16) FillEvaluatedPropsUBO {
Color outline_color;
float opacity;
float fade;
float width;
float pad1;
float from_scale;
float to_scale;
};
static_assert(sizeof(FillEvaluatedPropsUBO) == 3 * 16);
enum {
idFillDrawableUBO,
idFillDrawableUBO = globalUBOCount,
idFillTilePropsUBO,
idFillInterpolateUBO,
idFillEvaluatedPropsUBO,

View File

@@ -20,14 +20,12 @@ layout (std140) uniform BackgroundPatternLayerUBO {
highp vec2 u_pattern_br_a;
highp vec2 u_pattern_tl_b;
highp vec2 u_pattern_br_b;
highp vec2 u_texsize;
highp vec2 u_pattern_size_a;
highp vec2 u_pattern_size_b;
highp float u_scale_a;
highp float u_scale_b;
highp float u_mix;
highp float u_opacity;
highp float layer_pad1, layer_pad2;
};
layout (location = 0) in vec2 a_pos;
@@ -41,19 +39,28 @@ 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 BackgroundPatternLayerUBO {
static constexpr const char* fragment = R"(layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform BackgroundPatternLayerUBO {
highp vec2 u_pattern_tl_a;
highp vec2 u_pattern_br_a;
highp vec2 u_pattern_tl_b;
highp vec2 u_pattern_br_b;
highp vec2 u_texsize;
highp vec2 u_pattern_size_a;
highp vec2 u_pattern_size_b;
highp float u_scale_a;
highp float u_scale_b;
highp float u_mix;
highp float u_opacity;
highp float layer_pad1, layer_pad2;
};
uniform sampler2D u_image;
@@ -63,11 +70,11 @@ in mediump vec2 v_pos_b;
void main() {
vec2 imagecoord = mod(v_pos_a, 1.0);
vec2 pos = mix(u_pattern_tl_a / u_texsize, u_pattern_br_a / u_texsize, imagecoord);
vec2 pos = mix(u_pattern_tl_a / u_pattern_atlas_texsize, u_pattern_br_a / u_pattern_atlas_texsize, imagecoord);
vec4 color1 = texture(u_image, pos);
vec2 imagecoord_b = mod(v_pos_b, 1.0);
vec2 pos2 = mix(u_pattern_tl_b / u_texsize, u_pattern_br_b / u_texsize, imagecoord_b);
vec2 pos2 = mix(u_pattern_tl_b / u_pattern_atlas_texsize, u_pattern_br_b / u_pattern_atlas_texsize, imagecoord_b);
vec4 color2 = texture(u_image, pos2);
fragColor = mix(color1, color2, u_mix) * u_opacity;

View File

@@ -11,18 +11,23 @@ struct ShaderSource<BuiltIn::CircleShader, gfx::Backend::Type::OpenGL> {
static constexpr const char* vertex = R"(layout (location = 0) in vec2 a_pos;
out vec3 v_data;
layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform CircleDrawableUBO {
highp mat4 u_matrix;
highp vec2 u_extrude_scale;
lowp vec2 drawable_pad1;
};
layout (std140) uniform CirclePaintParamsUBO {
highp float u_camera_to_center_distance;
lowp float params_pad1;
lowp vec2 params_pad2;
};
layout (std140) uniform CircleEvaluatedPropsUBO {
highp vec4 u_color;
highp vec4 u_stroke_color;

View File

@@ -14,10 +14,21 @@ layout (location = 2) in vec2 a_extrude;
layout (location = 3) in vec2 a_placed;
layout (location = 4) in vec2 a_shift;
layout (std140) uniform CollisionBoxUBO {
layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform CollisionUBO {
highp mat4 u_matrix;
highp vec2 u_extrude_scale;
highp float u_camera_to_center_distance;
highp float u_overscale_factor;
highp float pad1;
};
@@ -39,10 +50,10 @@ void main() {
v_notUsed = a_placed.y;
}
)";
static constexpr const char* fragment = R"(layout (std140) uniform CollisionBoxUBO {
static constexpr const char* fragment = R"(layout (std140) uniform CollisionUBO {
highp mat4 u_matrix;
highp vec2 u_extrude_scale;
highp float u_camera_to_center_distance;
highp float u_overscale_factor;
highp float pad1;
};

View File

@@ -13,11 +13,22 @@ layout (location = 1) in vec2 a_anchor_pos;
layout (location = 2) in vec2 a_extrude;
layout (location = 3) in vec2 a_placed;
layout (std140) uniform CollisionCircleUBO {
layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform CollisionUBO {
highp mat4 u_matrix;
highp vec2 u_extrude_scale;
highp float u_camera_to_center_distance;
highp float u_overscale_factor;
highp float pad1;
};
out float v_placed;
@@ -47,11 +58,22 @@ void main() {
v_extrude_scale = u_extrude_scale * u_camera_to_center_distance * collision_perspective_ratio;
}
)";
static constexpr const char* fragment = R"(layout (std140) uniform CollisionCircleUBO {
static constexpr const char* fragment = R"(layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform CollisionUBO {
highp mat4 u_matrix;
highp vec2 u_extrude_scale;
highp float u_camera_to_center_distance;
highp float u_overscale_factor;
highp float pad1;
};
in float v_placed;

View File

@@ -21,8 +21,8 @@ layout (std140) uniform FillEvaluatedPropsUBO {
highp vec4 u_outline_color;
highp float u_opacity;
highp float u_fade;
highp float u_width;
highp float props_pad1;
highp float u_from_scale;
highp float u_to_scale;
};
layout (location = 0) in vec2 a_pos;
@@ -61,8 +61,8 @@ layout (std140) uniform FillEvaluatedPropsUBO {
highp vec4 u_outline_color;
highp float u_opacity;
highp float u_fade;
highp float u_width;
highp float props_pad1;
highp float u_from_scale;
highp float u_to_scale;
};
#ifndef HAS_UNIFORM_u_color

View File

@@ -14,12 +14,11 @@ out vec4 v_color;
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;
highp float u_tile_ratio;
};
layout (std140) uniform FillExtrusionPropsUBO {
highp vec4 u_color;
@@ -32,7 +31,9 @@ layout (std140) uniform FillExtrusionPropsUBO {
highp float u_vertical_gradient;
highp float u_opacity;
highp float u_fade;
highp float props_pad2, props_pad3, props_pad4;
highp float u_from_scale;
highp float u_to_scale;
highp float props_pad2;
};
layout (std140) uniform FillExtrusionTilePropsUBO {
highp vec4 u_pattern_from;

View File

@@ -15,14 +15,24 @@ out vec2 v_pos_a;
out vec2 v_pos_b;
out vec4 v_lighting;
layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
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;
highp float u_tile_ratio;
};
layout (std140) uniform FillExtrusionPropsUBO {
highp vec4 u_color;
@@ -35,7 +45,9 @@ layout (std140) uniform FillExtrusionPropsUBO {
highp float u_vertical_gradient;
highp float u_opacity;
highp float u_fade;
highp float props_pad2, props_pad3, props_pad4;
highp float u_from_scale;
highp float u_to_scale;
highp float props_pad2;
};
layout (std140) uniform FillExtrusionTilePropsUBO {
highp vec4 u_pattern_from;
@@ -94,10 +106,10 @@ mediump vec4 pattern_to = u_pattern_to;
vec2 pattern_tl_b = pattern_to.xy;
vec2 pattern_br_b = pattern_to.zw;
float pixelRatio = u_scale.x;
float tileRatio = u_scale.y;
float fromScale = u_scale.z;
float toScale = u_scale.w;
float pixelRatio = u_pixel_ratio;
float tileRatio = u_tile_ratio;
float fromScale = u_from_scale;
float toScale = u_to_scale;
vec3 normal = a_normal_ed.xyz;
float edgedistance = a_normal_ed.w;
@@ -142,12 +154,11 @@ in vec4 v_lighting;
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;
highp float u_tile_ratio;
};
layout (std140) uniform FillExtrusionPropsUBO {
highp vec4 u_color;
@@ -160,7 +171,9 @@ layout (std140) uniform FillExtrusionPropsUBO {
highp float u_vertical_gradient;
highp float u_opacity;
highp float u_fade;
highp float props_pad2, props_pad3, props_pad4;
highp float u_from_scale;
highp float u_to_scale;
highp float props_pad2;
};
layout (std140) uniform FillExtrusionTilePropsUBO {
highp vec4 u_pattern_from;

View File

@@ -8,10 +8,18 @@ namespace shaders {
template <>
struct ShaderSource<BuiltIn::FillOutlineShader, gfx::Backend::Type::OpenGL> {
static constexpr const char* name = "FillOutlineShader";
static constexpr const char* vertex = R"(layout (std140) uniform FillOutlineDrawableUBO {
static constexpr const char* vertex = R"(layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform FillOutlineDrawableUBO {
highp mat4 u_matrix;
highp vec2 u_world;
highp vec2 drawable_pad1;
};
layout (std140) uniform FillOutlineInterpolateUBO {
highp float u_outline_color_t;
@@ -24,8 +32,8 @@ layout (std140) uniform FillEvaluatedPropsUBO {
highp vec4 u_outline_color;
highp float u_opacity;
highp float u_fade;
highp float u_width;
highp float props_pad1;
highp float u_from_scale;
highp float u_to_scale;
};
layout (location = 0) in vec2 a_pos;
@@ -54,7 +62,7 @@ lowp float opacity = u_opacity;
#endif
gl_Position = u_matrix * vec4(a_pos, 0, 1);
v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world;
v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world_size;
}
)";
static constexpr const char* fragment = R"(layout (std140) uniform FillOutlineInterpolateUBO {
@@ -68,8 +76,8 @@ layout (std140) uniform FillEvaluatedPropsUBO {
highp vec4 u_outline_color;
highp float u_opacity;
highp float u_fade;
highp float u_width;
highp float props_pad1;
highp float u_from_scale;
highp float u_to_scale;
};
in vec2 v_pos;

View File

@@ -8,13 +8,23 @@ namespace shaders {
template <>
struct ShaderSource<BuiltIn::FillOutlinePatternShader, gfx::Backend::Type::OpenGL> {
static constexpr const char* name = "FillOutlinePatternShader";
static constexpr const char* vertex = R"(layout (std140) uniform FillOutlinePatternDrawableUBO {
static constexpr const char* vertex = R"(layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform FillOutlinePatternDrawableUBO {
highp mat4 u_matrix;
highp vec4 u_scale;
highp vec2 u_world;
highp vec2 u_pixel_coord_upper;
highp vec2 u_pixel_coord_lower;
highp vec2 u_texsize;
highp float u_tile_ratio;
highp float drawable_pad1;
};
layout (std140) uniform FillOutlinePatternTilePropsUBO {
highp vec4 u_pattern_from;
@@ -31,8 +41,8 @@ layout (std140) uniform FillEvaluatedPropsUBO {
highp vec4 u_outline_color;
highp float u_opacity;
highp float u_fade;
highp float u_width;
highp float props_pad1;
highp float u_from_scale;
highp float u_to_scale;
};
layout (location = 0) in vec2 a_pos;
@@ -76,10 +86,10 @@ mediump vec4 pattern_to = u_pattern_to;
vec2 pattern_tl_b = pattern_to.xy;
vec2 pattern_br_b = pattern_to.zw;
float pixelRatio = u_scale.x;
float tileRatio = u_scale.y;
float fromScale = u_scale.z;
float toScale = u_scale.w;
float pixelRatio = u_pixel_ratio;
float tileRatio = u_tile_ratio;
float fromScale = u_from_scale;
float toScale = u_to_scale;
gl_Position = u_matrix * vec4(a_pos, 0, 1);
@@ -89,16 +99,16 @@ mediump vec4 pattern_to = u_pattern_to;
v_pos_a = get_pattern_pos(u_pixel_coord_upper, u_pixel_coord_lower, fromScale * display_size_a, tileRatio, a_pos);
v_pos_b = get_pattern_pos(u_pixel_coord_upper, u_pixel_coord_lower, toScale * display_size_b, tileRatio, a_pos);
v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world;
v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world_size;
}
)";
static constexpr const char* fragment = R"(layout (std140) uniform FillOutlinePatternDrawableUBO {
highp mat4 u_matrix;
highp vec4 u_scale;
highp vec2 u_world;
highp vec2 u_pixel_coord_upper;
highp vec2 u_pixel_coord_lower;
highp vec2 u_texsize;
highp float u_tile_ratio;
highp float drawable_pad1;
};
layout (std140) uniform FillOutlinePatternTilePropsUBO {
highp vec4 u_pattern_from;
@@ -115,8 +125,8 @@ layout (std140) uniform FillEvaluatedPropsUBO {
highp vec4 u_outline_color;
highp float u_opacity;
highp float u_fade;
highp float u_width;
highp float props_pad1;
highp float u_from_scale;
highp float u_to_scale;
};
uniform sampler2D u_image;

View File

@@ -19,19 +19,28 @@ struct ShaderSource<BuiltIn::FillOutlineTriangulatedShader, gfx::Backend::Type::
layout (location = 0) in vec2 a_pos_normal;
layout (location = 1) in vec4 a_data;
layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform FillOutlineTriangulatedDrawableUBO {
highp mat4 u_matrix;
highp vec2 u_units_to_pixels;
mediump float u_ratio;
lowp float drawable_pad1;
lowp float drawable_pad1, drawable_pad2, drawable_pad3;
};
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;
highp float u_from_scale;
highp float u_to_scale;
};
out vec2 v_normal;
@@ -82,8 +91,8 @@ void main() {
highp vec4 u_outline_color;
highp float u_opacity;
highp float u_fade;
highp float u_width;
highp float props_pad1;
highp float u_from_scale;
highp float u_to_scale;
};
in float v_width;

View File

@@ -8,14 +8,23 @@ namespace shaders {
template <>
struct ShaderSource<BuiltIn::FillPatternShader, gfx::Backend::Type::OpenGL> {
static constexpr const char* name = "FillPatternShader";
static constexpr const char* vertex = R"(layout (std140) uniform FillPatternDrawableUBO {
static constexpr const char* vertex = R"(layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform FillPatternDrawableUBO {
highp mat4 u_matrix;
highp vec4 u_scale;
highp vec2 u_pixel_coord_upper;
highp vec2 u_pixel_coord_lower;
highp vec2 u_texsize;
highp float u_tile_ratio;
highp float drawable_pad1;
highp float drawable_pad2;
};
layout (std140) uniform FillPatternTilePropsUBO {
highp vec4 u_pattern_from;
@@ -32,8 +41,8 @@ layout (std140) uniform FillEvaluatedPropsUBO {
highp vec4 u_outline_color;
highp float u_opacity;
highp float u_fade;
highp float u_width;
highp float props_pad1;
highp float u_from_scale;
highp float u_to_scale;
};
layout (location = 0) in vec2 a_pos;
@@ -76,10 +85,10 @@ mediump vec4 pattern_to = u_pattern_to;
vec2 pattern_tl_b = pattern_to.xy;
vec2 pattern_br_b = pattern_to.zw;
float pixelRatio = u_scale.x;
float tileZoomRatio = u_scale.y;
float fromScale = u_scale.z;
float toScale = u_scale.w;
float pixelRatio = u_pixel_ratio;
float tileZoomRatio = u_tile_ratio;
float fromScale = u_from_scale;
float toScale = u_to_scale;
vec2 display_size_a = vec2((pattern_br_a.x - pattern_tl_a.x) / pixelRatio, (pattern_br_a.y - pattern_tl_a.y) / pixelRatio);
vec2 display_size_b = vec2((pattern_br_b.x - pattern_tl_b.x) / pixelRatio, (pattern_br_b.y - pattern_tl_b.y) / pixelRatio);
@@ -91,12 +100,11 @@ mediump vec4 pattern_to = u_pattern_to;
)";
static constexpr const char* fragment = R"(layout (std140) uniform FillPatternDrawableUBO {
highp mat4 u_matrix;
highp vec4 u_scale;
highp vec2 u_pixel_coord_upper;
highp vec2 u_pixel_coord_lower;
highp vec2 u_texsize;
highp float u_tile_ratio;
highp float drawable_pad1;
highp float drawable_pad2;
};
layout (std140) uniform FillPatternTilePropsUBO {
highp vec4 u_pattern_from;
@@ -113,8 +121,8 @@ layout (std140) uniform FillEvaluatedPropsUBO {
highp vec4 u_outline_color;
highp float u_opacity;
highp float u_fade;
highp float u_width;
highp float props_pad1;
highp float u_from_scale;
highp float u_to_scale;
};
uniform sampler2D u_image;

View File

@@ -11,15 +11,24 @@ struct ShaderSource<BuiltIn::HeatmapTextureShader, gfx::Backend::Type::OpenGL> {
static constexpr const char* vertex = R"(layout (location = 0) in vec2 a_pos;
out vec2 v_pos;
layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform HeatmapTexturePropsUBO {
highp mat4 u_matrix;
highp vec2 u_world;
highp float u_opacity;
lowp float props_pad1;
lowp float props_pad1, props_pad2, props_pad3;
};
void main() {
gl_Position = u_matrix * vec4(a_pos * u_world, 0, 1);
gl_Position = u_matrix * vec4(a_pos * u_world_size, 0, 1);
v_pos.x = a_pos.x;
v_pos.y = 1.0 - a_pos.y;
@@ -31,9 +40,8 @@ uniform sampler2D u_color_ramp;
layout (std140) uniform HeatmapTexturePropsUBO {
highp mat4 u_matrix;
highp vec2 u_world;
highp float u_opacity;
lowp float props_pad1;
lowp float props_pad1, props_pad2, props_pad3;
};
void main() {

View File

@@ -19,9 +19,15 @@ struct ShaderSource<BuiltIn::LineShader, gfx::Backend::Type::OpenGL> {
layout (location = 0) in vec2 a_pos_normal;
layout (location = 1) in vec4 a_data;
layout (std140) uniform LineDynamicUBO {
layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
lowp float dynamic_pad1, dynamic_pad2;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform LineDrawableUBO {

View File

@@ -23,9 +23,15 @@ struct ShaderSource<BuiltIn::LineGradientShader, gfx::Backend::Type::OpenGL> {
layout (location = 0) in vec2 a_pos_normal;
layout (location = 1) in vec4 a_data;
layout (std140) uniform LineDynamicUBO {
layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
lowp float dynamic_pad1, dynamic_pad2;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform LineGradientDrawableUBO {

View File

@@ -23,9 +23,15 @@ struct ShaderSource<BuiltIn::LinePatternShader, gfx::Backend::Type::OpenGL> {
layout (location = 0) in vec2 a_pos_normal;
layout (location = 1) in vec4 a_data;
layout (std140) uniform LineDynamicUBO {
layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
lowp float dynamic_pad1, dynamic_pad2;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform LinePatternDrawableUBO {

View File

@@ -23,9 +23,15 @@ struct ShaderSource<BuiltIn::LineSDFShader, gfx::Backend::Type::OpenGL> {
layout (location = 0) in vec2 a_pos_normal;
layout (location = 1) in vec4 a_data;
layout (std140) uniform LineDynamicUBO {
layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
lowp float dynamic_pad1, dynamic_pad2;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform LineSDFDrawableUBO {

View File

@@ -14,11 +14,15 @@ 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;
layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float dynamic_pad1;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform SymbolDrawableUBO {
@@ -142,7 +146,7 @@ lowp float opacity = u_opacity;
v_tex = a_tex / u_texsize;
vec2 fade_opacity = unpack_opacity(a_fade_opacity);
float fade_change = fade_opacity[1] > 0.5 ? u_fade_change : -u_fade_change;
float fade_change = fade_opacity[1] > 0.5 ? u_symbol_fade_change : -u_symbol_fade_change;
v_fade_opacity = max(0.0, min(1.0, fade_opacity[0] + fade_change));
}
)";

View File

@@ -22,11 +22,15 @@ 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;
layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float dynamic_pad1;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform SymbolDrawableUBO {
@@ -196,7 +200,7 @@ lowp float halo_blur = u_halo_blur;
float gamma_scale = gl_Position.w;
vec2 fade_opacity = unpack_opacity(a_fade_opacity);
float fade_change = fade_opacity[1] > 0.5 ? u_fade_change : -u_fade_change;
float fade_change = fade_opacity[1] > 0.5 ? u_symbol_fade_change : -u_symbol_fade_change;
float interpolated_fade_opacity = max(0.0, min(1.0, fade_opacity[0] + fade_change));
v_data0 = a_tex / u_texsize;
@@ -205,13 +209,6 @@ 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;

View File

@@ -21,11 +21,15 @@ 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;
layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float dynamic_pad1;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform SymbolDrawableUBO {
@@ -195,7 +199,7 @@ lowp float halo_blur = u_halo_blur;
float gamma_scale = gl_Position.w;
vec2 fade_opacity = unpack_opacity(a_fade_opacity);
float fade_change = fade_opacity[1] > 0.5 ? u_fade_change : -u_fade_change;
float fade_change = fade_opacity[1] > 0.5 ? u_symbol_fade_change : -u_symbol_fade_change;
float interpolated_fade_opacity = max(0.0, min(1.0, fade_opacity[0] + fade_change));
v_data0.xy = a_tex / u_texsize;
@@ -208,13 +212,6 @@ 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;

View File

@@ -28,7 +28,7 @@ struct alignas(16) HeatmapInterpolateUBO {
static_assert(sizeof(HeatmapInterpolateUBO) % 16 == 0);
enum {
idHeatmapDrawableUBO,
idHeatmapDrawableUBO = globalUBOCount,
idHeatmapEvaluatedPropsUBO,
idHeatmapInterpolateUBO,
heatmapUBOCount

View File

@@ -7,14 +7,13 @@ namespace shaders {
struct alignas(16) HeatmapTexturePropsUBO {
std::array<float, 4 * 4> matrix;
std::array<float, 2> world;
float opacity;
float pad1;
float pad1, pad2, pad3;
};
static_assert(sizeof(HeatmapTexturePropsUBO) % 16 == 0);
enum {
idHeatmapTexturePropsUBO,
idHeatmapTexturePropsUBO = globalUBOCount,
heatmapTextureUBOCount
};

View File

@@ -20,7 +20,7 @@ struct alignas(16) HillshadeEvaluatedPropsUBO {
static_assert(sizeof(HillshadeEvaluatedPropsUBO) % 16 == 0);
enum {
idHillshadeDrawableUBO,
idHillshadeDrawableUBO = globalUBOCount,
idHillshadeEvaluatedPropsUBO,
hillshadeUBOCount
};

View File

@@ -15,7 +15,7 @@ struct alignas(16) HillshadePrepareDrawableUBO {
static_assert(sizeof(HillshadePrepareDrawableUBO) % 16 == 0);
enum {
idHillshadePrepareDrawableUBO,
idHillshadePrepareDrawableUBO = globalUBOCount,
hillshadePrepareUBOCount
};

View File

@@ -33,5 +33,25 @@ struct Attribute {
};
static_assert(sizeof(Attribute) == 8);
//
// Global UBOs
struct alignas(16) GlobalPaintParamsUBO {
std::array<float, 2> pattern_atlas_texsize;
std::array<float, 2> units_to_pixels;
std::array<float, 2> world_size;
float camera_to_center_distance;
float symbol_fade_change;
float aspect_ratio;
float pixel_ratio;
float pad1, pad2;
};
static_assert(sizeof(GlobalPaintParamsUBO) == 3 * 16);
enum {
idGlobalPaintParamsUBO,
globalUBOCount
};
} // namespace shaders
} // namespace mbgl

View File

@@ -8,13 +8,6 @@ namespace shaders {
//
// Line
struct alignas(16) LineDynamicUBO {
/* 0 */ std::array<float, 2> units_to_pixels;
/* 8 */ float pad1, pad2;
/* 16 */
};
static_assert(sizeof(LineDynamicUBO) == 16);
struct alignas(16) LineDrawableUBO {
std::array<float, 4 * 4> matrix;
float ratio;
@@ -122,8 +115,7 @@ struct alignas(16) LineEvaluatedPropsUBO {
static_assert(sizeof(LineEvaluatedPropsUBO) % 16 == 0);
enum {
idLineDynamicUBO,
idLineDrawableUBO,
idLineDrawableUBO = globalUBOCount,
idLineInterpolationUBO,
idLineTilePropertiesUBO,
idLineEvaluatedPropsUBO,

View File

@@ -24,7 +24,7 @@ struct ShaderSource<BuiltIn::BackgroundShader, gfx::Backend::Type::Metal> {
using namespace metal;
struct VertexStage {
short2 position [[attribute(2)]];
short2 position [[attribute(3)]];
};
struct FragmentStage {
@@ -41,14 +41,14 @@ struct alignas(16) BackgroundLayerUBO {
};
FragmentStage vertex vertexMain(VertexStage in [[stage_in]],
device const BackgroundDrawableUBO& drawableUBO [[buffer(0)]]) {
device const BackgroundDrawableUBO& drawableUBO [[buffer(1)]]) {
return {
.position = drawableUBO.matrix * float4(float2(in.position.xy), 0, 1)
};
}
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
device const BackgroundLayerUBO& layerUBO [[buffer(1)]]) {
device const BackgroundLayerUBO& layerUBO [[buffer(2)]]) {
#if defined(OVERDRAW_INSPECTOR)
return half4(1.0);
#endif

View File

@@ -11,7 +11,7 @@ struct ShaderSource<BuiltIn::BackgroundPatternShader, gfx::Backend::Type::Metal>
static constexpr auto vertexMainFunction = "vertexMain";
static constexpr auto fragmentMainFunction = "fragmentMain";
static const std::array<UniformBlockInfo, 2> uniforms;
static const std::array<UniformBlockInfo, 3> uniforms;
static const std::array<AttributeInfo, 1> attributes;
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 1> textures;
@@ -21,7 +21,7 @@ struct ShaderSource<BuiltIn::BackgroundPatternShader, gfx::Backend::Type::Metal>
using namespace metal;
struct VertexStage {
short2 position [[attribute(2)]];
short2 position [[attribute(3)]];
};
struct FragmentStage {
@@ -42,19 +42,17 @@ struct alignas(16) BackgroundPatternLayerUBO {
float2 pattern_br_a;
float2 pattern_tl_b;
float2 pattern_br_b;
float2 texsize;
float2 pattern_size_a;
float2 pattern_size_b;
float scale_a;
float scale_b;
float mix;
float opacity;
float pad1, pad2;
};
FragmentStage vertex vertexMain(VertexStage in [[stage_in]],
device const BackgroundPatternDrawableUBO& drawableUBO [[buffer(0)]],
device const BackgroundPatternLayerUBO& layerUBO [[buffer(1)]]) {
device const BackgroundPatternDrawableUBO& drawableUBO [[buffer(1)]],
device const BackgroundPatternLayerUBO& layerUBO [[buffer(2)]]) {
const float2 pos = float2(in.position);
const float2 pos_a = get_pattern_pos(drawableUBO.pixel_coord_upper,
drawableUBO.pixel_coord_lower,
@@ -74,18 +72,20 @@ FragmentStage vertex vertexMain(VertexStage in [[stage_in]],
}
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
device const BackgroundPatternLayerUBO& layerUBO [[buffer(1)]],
device const GlobalPaintParamsUBO& paintParamsUBO [[buffer(0)]],
device const BackgroundPatternLayerUBO& layerUBO [[buffer(2)]],
texture2d<float, access::sample> image [[texture(0)]],
sampler image_sampler [[sampler(0)]]) {
#if defined(OVERDRAW_INSPECTOR)
return half4(1.0);
#endif
const float2 texsize = paintParamsUBO.pattern_atlas_texsize;
const float2 imagecoord = glMod(float2(in.pos_a), 1.0);
const float2 pos = mix(layerUBO.pattern_tl_a / layerUBO.texsize, layerUBO.pattern_br_a / layerUBO.texsize, imagecoord);
const float2 pos = mix(layerUBO.pattern_tl_a / texsize, layerUBO.pattern_br_a / texsize, imagecoord);
const float4 color1 = image.sample(image_sampler, pos);
const float2 imagecoord_b = glMod(float2(in.pos_b), 1.0);
const float2 pos2 = mix(layerUBO.pattern_tl_b / layerUBO.texsize, layerUBO.pattern_br_b / layerUBO.texsize, imagecoord_b);
const float2 pos2 = mix(layerUBO.pattern_tl_b / texsize, layerUBO.pattern_br_b / texsize, imagecoord_b);
const float4 color2 = image.sample(image_sampler, pos2);
return half4(mix(color1, color2, layerUBO.mix) * layerUBO.opacity);

View File

@@ -108,8 +108,8 @@ struct alignas(16) CircleInterpolateUBO {
};
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
device const CircleDrawableUBO& drawable [[buffer(0)]],
device const CirclePaintParamsUBO& params [[buffer(1)]],
device const GlobalPaintParamsUBO& paintParams [[buffer(0)]],
device const CircleDrawableUBO& drawable [[buffer(1)]],
device const CircleEvaluatedPropsUBO& props [[buffer(2)]],
device const CircleInterpolateUBO& interp [[buffer(3)]]) {
@@ -143,14 +143,14 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
// whole circle based on the pitch scaling effect at its central point
const float4 projected_center = drawable.matrix * float4(circle_center, 0, 1);
corner_position += scaled_extrude * (radius + stroke_width) *
(projected_center.w / params.camera_to_center_distance);
(projected_center.w / paintParams.camera_to_center_distance);
}
position = drawable.matrix * float4(corner_position, 0, 1);
} else {
position = drawable.matrix * float4(circle_center, 0, 1);
const float factor = props.scale_with_map ? params.camera_to_center_distance : position.w;
const float factor = props.scale_with_map ? paintParams.camera_to_center_distance : position.w;
position.xy += scaled_extrude * (radius + stroke_width) * factor;
}
@@ -189,7 +189,6 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
}
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
device const CirclePaintParamsUBO& params [[buffer(1)]],
device const CircleEvaluatedPropsUBO& props [[buffer(2)]]) {
#if defined(OVERDRAW_INSPECTOR)
return half4(1.0);

View File

@@ -38,7 +38,7 @@ struct alignas(16) ClipUBO {
static_assert(sizeof(ClipUBO) == 5 * 16, "unexpected padding");
struct VertexStage {
short2 position [[attribute(1)]];
short2 position [[attribute(2)]];
};
struct FragmentStage {
@@ -51,7 +51,7 @@ struct FragmentResult {
};
FragmentStage vertex vertexMain(VertexStage in [[stage_in]],
device const ClipUBO& clipUBO [[buffer(0)]]) {
device const ClipUBO& clipUBO [[buffer(1)]]) {
return { clipUBO.matrix * float4(float2(in.position.xy), 0, 1) };
}

View File

@@ -22,11 +22,11 @@ struct ShaderSource<BuiltIn::CollisionBoxShader, gfx::Backend::Type::Metal> {
static constexpr auto source = R"(
struct VertexStage {
short2 pos [[attribute(1)]];
short2 anchor_pos [[attribute(2)]];
short2 extrude [[attribute(3)]];
ushort2 placed [[attribute(4)]];
float2 shift [[attribute(5)]];
short2 pos [[attribute(2)]];
short2 anchor_pos [[attribute(3)]];
short2 extrude [[attribute(4)]];
ushort2 placed [[attribute(5)]];
float2 shift [[attribute(6)]];
};
struct FragmentStage {
@@ -38,17 +38,18 @@ struct FragmentStage {
struct alignas(16) CollisionBoxUBO {
float4x4 matrix;
float2 extrude_scale;
float camera_to_center_distance;
float overscale_factor;
float pad1;
};
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
device const CollisionBoxUBO& drawable [[buffer(0)]]) {
device const GlobalPaintParamsUBO& paintParams [[buffer(0)]],
device const CollisionBoxUBO& drawable [[buffer(1)]]) {
float4 projectedPoint = drawable.matrix * float4(float2(vertx.anchor_pos), 0, 1);
float camera_to_anchor_distance = projectedPoint.w;
float collision_perspective_ratio = clamp(
0.5 + 0.5 * (drawable.camera_to_center_distance / camera_to_anchor_distance),
0.5 + 0.5 * (paintParams.camera_to_center_distance / camera_to_anchor_distance),
0.0, // Prevents oversized near-field boxes in pitched/overzoomed tiles
4.0);
@@ -66,7 +67,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
}
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
device const CollisionBoxUBO& drawable [[buffer(0)]]) {
device const CollisionBoxUBO& drawable [[buffer(1)]]) {
float alpha = 0.5;

View File

@@ -22,10 +22,10 @@ struct ShaderSource<BuiltIn::CollisionCircleShader, gfx::Backend::Type::Metal> {
static constexpr auto source = R"(
struct VertexStage {
short2 pos [[attribute(1)]];
short2 anchor_pos [[attribute(2)]];
short2 extrude [[attribute(3)]];
ushort2 placed [[attribute(4)]];
short2 pos [[attribute(2)]];
short2 anchor_pos [[attribute(3)]];
short2 extrude [[attribute(4)]];
ushort2 placed [[attribute(5)]];
};
struct FragmentStage {
@@ -40,17 +40,18 @@ struct FragmentStage {
struct alignas(16) CollisionCircleUBO {
float4x4 matrix;
float2 extrude_scale;
float camera_to_center_distance;
float overscale_factor;
float pad1;
};
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
device const CollisionCircleUBO& drawable [[buffer(0)]]) {
device const GlobalPaintParamsUBO& paintParams [[buffer(0)]],
device const CollisionCircleUBO& drawable [[buffer(1)]]) {
float4 projectedPoint = drawable.matrix * float4(float2(vertx.anchor_pos), 0, 1);
float camera_to_anchor_distance = projectedPoint.w;
float collision_perspective_ratio = clamp(
0.5 + 0.5 * (drawable.camera_to_center_distance / camera_to_anchor_distance),
0.5 + 0.5 * (paintParams.camera_to_center_distance / camera_to_anchor_distance),
0.0, // Prevents oversized near-field circles in pitched/overzoomed tiles
4.0);
@@ -64,7 +65,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
float radius = abs(float(vertx.extrude.y)); // We don't pitch the circles, so both units of the extrusion vector are equal in magnitude to the radius
float2 extrude = float2(vertx.extrude) * padding_factor;
float2 extrude_scale = drawable.extrude_scale * drawable.camera_to_center_distance * collision_perspective_ratio;
float2 extrude_scale = drawable.extrude_scale * paintParams.camera_to_center_distance * collision_perspective_ratio;
return {
.position = position,
@@ -77,7 +78,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
}
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
device const CollisionCircleUBO& drawable [[buffer(0)]]) {
device const CollisionCircleUBO& drawable [[buffer(1)]]) {
float alpha = 0.5;

View File

@@ -54,26 +54,38 @@ float4 unpack_mix_color(const float4 packedColors, const float t) {
decode_color(float2(packedColors[2], packedColors[3])), t);
}
struct alignas(16) GlobalPaintParamsUBO {
/* 0 */ float2 pattern_atlas_texsize;
/* 8 */ float2 units_to_pixels;
/* 16 */ float2 world_size;
/* 24 */ float camera_to_center_distance;
/* 28 */ float symbol_fade_change;
/* 32 */ float aspect_ratio;
/* 36 */ float pixel_ratio;
/* 40 */ float pad1, pad2;
/* 48 */
};
static_assert(sizeof(GlobalPaintParamsUBO) == 3 * 16, "unexpected padding");
struct alignas(16) FillEvaluatedPropsUBO {
float4 color;
float4 outline_color;
float opacity;
float fade;
float width;
float pad1;
float from_scale;
float to_scale;
};
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 */
/* 0 */ float4x4 matrix;
/* 64 */ float2 texsize;
/* 72 */ float2 pixel_coord_upper;
/* 80 */ float2 pixel_coord_lower;
/* 88 */ float height_factor;
/* 92 */ float tile_ratio;
/* 96 */
};
static_assert(sizeof(FillExtrusionDrawableUBO) == 7 * 16, "unexpected padding");
static_assert(sizeof(FillExtrusionDrawableUBO) == 6 * 16, "unexpected padding");
struct alignas(16) FillExtrusionPropsUBO {
/* 0 */ float4 color;
@@ -84,7 +96,9 @@ struct alignas(16) FillExtrusionPropsUBO {
/* 56 */ float vertical_gradient;
/* 60 */ float opacity;
/* 64 */ float fade;
/* 68 */ float pad2, pad3, pad4;
/* 68 */ float from_scale;
/* 72 */ float to_scale;
/* 76 */ float pad2;
/* 80 */
};
static_assert(sizeof(FillExtrusionPropsUBO) == 5 * 16, "unexpected padding");
@@ -107,11 +121,6 @@ struct alignas(16) FillExtrusionInterpolateUBO {
};
static_assert(sizeof(FillExtrusionInterpolateUBO) == 2 * 16, "unexpected padding");
struct alignas(16) LineDynamicUBO {
float2 units_to_pixels;
float pad1, pad2;
};
struct alignas(16) LineEvaluatedPropsUBO {
float4 color;
float blur;
@@ -123,14 +132,6 @@ struct alignas(16) LineEvaluatedPropsUBO {
float pad1, pad2;
};
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) SymbolDrawableUBO {
float4x4 matrix;
float4x4 label_plane_matrix;

View File

@@ -36,8 +36,8 @@ struct alignas(16) CustomSymbolIconParametersUBO {
};
struct VertexStage {
float2 a_pos [[attribute(2)]];
float2 a_tex [[attribute(3)]];
float2 a_pos [[attribute(3)]];
float2 a_tex [[attribute(4)]];
};
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(0)]],
device const CustomSymbolIconParametersUBO& parameters [[buffer(1)]]) {
device const CustomSymbolIconDrawableUBO& drawable [[buffer(1)]],
device const CustomSymbolIconParametersUBO& parameters [[buffer(2)]]) {
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;

View File

@@ -22,7 +22,7 @@ struct ShaderSource<BuiltIn::DebugShader, gfx::Backend::Type::Metal> {
static constexpr auto source = R"(
struct VertexStage {
short2 pos [[attribute(1)]];
short2 pos [[attribute(2)]];
};
struct FragmentStage {
@@ -38,9 +38,9 @@ struct alignas(16) DebugUBO {
};
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
device const DebugUBO& debugUBO [[buffer(0)]]) {
device const DebugUBO& debug [[buffer(1)]]) {
const float4 position = debugUBO.matrix * float4(float2(vertx.pos) * debugUBO.overlay_scale, 0, 1);
const float4 position = debug.matrix * float4(float2(vertx.pos) * debug.overlay_scale, 0, 1);
// This vertex shader expects a EXTENT x EXTENT quad,
// The UV co-ordinates for the overlay texture can be calculated using that knowledge
@@ -53,12 +53,12 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
}
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
device const DebugUBO& debugUBO [[buffer(0)]],
device const DebugUBO& debug [[buffer(1)]],
texture2d<float, access::sample> overlay [[texture(0)]],
sampler overlay_sampler [[sampler(0)]]) {
float4 overlay_color = overlay.sample(overlay_sampler, in.uv);
float4 color = mix(debugUBO.color, overlay_color, overlay_color.a);
float4 color = mix(debug.color, overlay_color, overlay_color.a);
return half4(color);
}
)";

View File

@@ -22,13 +22,13 @@ struct ShaderSource<BuiltIn::FillShader, gfx::Backend::Type::Metal> {
static constexpr auto source = R"(
struct VertexStage {
short2 position [[attribute(4)]];
short2 position [[attribute(5)]];
#if !defined(HAS_UNIFORM_u_color)
float4 color [[attribute(5)]];
float4 color [[attribute(6)]];
#endif
#if !defined(HAS_UNIFORM_u_opacity)
float2 opacity [[attribute(6)]];
float2 opacity [[attribute(7)]];
#endif
};
@@ -53,9 +53,9 @@ struct alignas(16) FillInterpolateUBO {
};
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
device const FillDrawableUBO& drawable [[buffer(0)]],
device const FillInterpolateUBO& interp [[buffer(2)]],
device const FillEvaluatedPropsUBO& props [[buffer(3)]]) {
device const FillDrawableUBO& drawable [[buffer(1)]],
device const FillInterpolateUBO& interp [[buffer(3)]],
device const FillEvaluatedPropsUBO& props [[buffer(4)]]) {
return {
.position = drawable.matrix * float4(float2(vertx.position), 0.0f, 1.0f),
#if !defined(HAS_UNIFORM_u_color)
@@ -68,7 +68,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
}
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
device const FillEvaluatedPropsUBO& props [[buffer(3)]]) {
device const FillEvaluatedPropsUBO& props [[buffer(4)]]) {
#if defined(OVERDRAW_INSPECTOR)
return half4(1.0);
#endif
@@ -96,16 +96,16 @@ struct ShaderSource<BuiltIn::FillOutlineShader, gfx::Backend::Type::Metal> {
static constexpr auto vertexMainFunction = "vertexMain";
static constexpr auto fragmentMainFunction = "fragmentMain";
static const std::array<UniformBlockInfo, 3> uniforms;
static const std::array<UniformBlockInfo, 4> uniforms;
static const std::array<AttributeInfo, 3> attributes;
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 0> textures;
static constexpr auto source = R"(
struct VertexStage {
short2 position [[attribute(4)]];
float4 outline_color [[attribute(5)]];
float2 opacity [[attribute(6)]];
short2 position [[attribute(5)]];
float4 outline_color [[attribute(6)]];
float2 opacity [[attribute(7)]];
};
struct FragmentStage {
@@ -121,8 +121,6 @@ struct FragmentStage {
struct alignas(16) FillOutlineDrawableUBO {
float4x4 matrix;
float2 world;
float2 pad1;
};
struct alignas(16) FillOutlineInterpolateUBO {
@@ -131,13 +129,14 @@ struct alignas(16) FillOutlineInterpolateUBO {
};
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
device const FillOutlineDrawableUBO& drawable [[buffer(0)]],
device const FillOutlineInterpolateUBO& interp [[buffer(2)]],
device const FillEvaluatedPropsUBO& props [[buffer(3)]]) {
device const GlobalPaintParamsUBO& paintParams [[buffer(0)]],
device const FillOutlineDrawableUBO& drawable [[buffer(1)]],
device const FillOutlineInterpolateUBO& interp [[buffer(3)]],
device const FillEvaluatedPropsUBO& props [[buffer(4)]]) {
const float4 position = drawable.matrix * float4(float2(vertx.position), 0.0f, 1.0f);
return {
.position = position,
.pos = (position.xy / position.w + 1.0) / 2.0 * drawable.world,
.pos = (position.xy / position.w + 1.0) / 2.0 * paintParams.world_size,
#if !defined(HAS_UNIFORM_u_outline_color)
.outline_color = half4(unpack_mix_color(vertx.outline_color, interp.outline_color_t)),
#endif
@@ -148,7 +147,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
}
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
device const FillEvaluatedPropsUBO& props [[buffer(3)]]) {
device const FillEvaluatedPropsUBO& props [[buffer(4)]]) {
#if defined(OVERDRAW_INSPECTOR)
return half4(1.0);
#endif
@@ -182,23 +181,23 @@ struct ShaderSource<BuiltIn::FillPatternShader, gfx::Backend::Type::Metal> {
static constexpr auto vertexMainFunction = "vertexMain";
static constexpr auto fragmentMainFunction = "fragmentMain";
static const std::array<UniformBlockInfo, 4> uniforms;
static const std::array<UniformBlockInfo, 5> uniforms;
static const std::array<AttributeInfo, 4> attributes;
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 1> textures;
static constexpr auto source = R"(
struct VertexStage {
short2 position [[attribute(4)]];
short2 position [[attribute(5)]];
#if !defined(HAS_UNIFORM_u_pattern_from)
ushort4 pattern_from [[attribute(5)]];
ushort4 pattern_from [[attribute(6)]];
#endif
#if !defined(HAS_UNIFORM_u_pattern_to)
ushort4 pattern_to [[attribute(6)]];
ushort4 pattern_to [[attribute(7)]];
#endif
#if !defined(HAS_UNIFORM_u_opacity)
float2 opacity [[attribute(7)]];
float2 opacity [[attribute(8)]];
#endif
};
@@ -220,10 +219,11 @@ struct FragmentStage {
struct alignas(16) FillPatternDrawableUBO {
float4x4 matrix;
float4 scale;
float2 pixel_coord_upper;
float2 pixel_coord_lower;
float2 texsize;
float tile_ratio;
float pad;
};
struct alignas(16) FillPatternTilePropsUBO {
@@ -238,10 +238,11 @@ struct alignas(16) FillPatternInterpolateUBO {
};
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
device const FillPatternDrawableUBO& drawable [[buffer(0)]],
device const FillPatternTilePropsUBO& tileProps [[buffer(1)]],
device const FillPatternInterpolateUBO& interp [[buffer(2)]],
device const FillEvaluatedPropsUBO& props [[buffer(3)]]) {
device const GlobalPaintParamsUBO& paintParams [[buffer(0)]],
device const FillPatternDrawableUBO& drawable [[buffer(1)]],
device const FillPatternTilePropsUBO& tileProps [[buffer(2)]],
device const FillPatternInterpolateUBO& interp [[buffer(3)]],
device const FillEvaluatedPropsUBO& props [[buffer(4)]]) {
#if defined(HAS_UNIFORM_u_pattern_from)
const auto pattern_from = float4(tileProps.pattern_from);
#else
@@ -259,10 +260,10 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
const float2 pattern_tl_b = pattern_to.xy;
const float2 pattern_br_b = pattern_to.zw;
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 float pixelRatio = paintParams.pixel_ratio;
const float tileZoomRatio = drawable.tile_ratio;
const float fromScale = props.from_scale;
const float toScale = props.to_scale;
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);
@@ -285,9 +286,9 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
}
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
device const FillPatternDrawableUBO& drawable [[buffer(0)]],
device const FillPatternTilePropsUBO& tileProps [[buffer(1)]],
device const FillEvaluatedPropsUBO& props [[buffer(3)]],
device const FillPatternDrawableUBO& drawable [[buffer(1)]],
device const FillPatternTilePropsUBO& tileProps [[buffer(2)]],
device const FillEvaluatedPropsUBO& props [[buffer(4)]],
texture2d<float, access::sample> image0 [[texture(0)]],
sampler image0_sampler [[sampler(0)]]) {
#if defined(OVERDRAW_INSPECTOR)
@@ -336,7 +337,7 @@ struct ShaderSource<BuiltIn::FillOutlinePatternShader, gfx::Backend::Type::Metal
static constexpr auto vertexMainFunction = "vertexMain";
static constexpr auto fragmentMainFunction = "fragmentMain";
static const std::array<UniformBlockInfo, 4> uniforms;
static const std::array<UniformBlockInfo, 5> uniforms;
static const std::array<AttributeInfo, 4> attributes;
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 1> textures;
@@ -344,16 +345,16 @@ struct ShaderSource<BuiltIn::FillOutlinePatternShader, gfx::Backend::Type::Metal
static constexpr auto source = R"(
struct VertexStage {
short2 position [[attribute(4)]];
short2 position [[attribute(5)]];
#if !defined(HAS_UNIFORM_u_pattern_from)
ushort4 pattern_from [[attribute(5)]];
ushort4 pattern_from [[attribute(6)]];
#endif
#if !defined(HAS_UNIFORM_u_pattern_to)
ushort4 pattern_to [[attribute(6)]];
ushort4 pattern_to [[attribute(7)]];
#endif
#if !defined(HAS_UNIFORM_u_opacity)
float2 opacity [[attribute(7)]];
float2 opacity [[attribute(8)]];
#endif
};
@@ -376,11 +377,11 @@ struct FragmentStage {
struct alignas(16) FillOutlinePatternDrawableUBO {
float4x4 matrix;
float4 scale;
float2 world;
float2 pixel_coord_upper;
float2 pixel_coord_lower;
float2 texsize;
float tile_ratio;
float pad;
};
struct alignas(16) FillOutlinePatternTilePropsUBO {
@@ -395,10 +396,11 @@ struct alignas(16) FillOutlinePatternInterpolateUBO {
};
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
device const FillOutlinePatternDrawableUBO& drawable [[buffer(0)]],
device const FillOutlinePatternTilePropsUBO& tileProps [[buffer(1)]],
device const FillOutlinePatternInterpolateUBO& interp [[buffer(2)]],
device const FillEvaluatedPropsUBO& props [[buffer(3)]]) {
device const GlobalPaintParamsUBO& paintParams [[buffer(0)]],
device const FillOutlinePatternDrawableUBO& drawable [[buffer(1)]],
device const FillOutlinePatternTilePropsUBO& tileProps [[buffer(2)]],
device const FillOutlinePatternInterpolateUBO& interp [[buffer(3)]],
device const FillEvaluatedPropsUBO& props [[buffer(4)]]) {
#if defined(HAS_UNIFORM_u_pattern_from)
const auto pattern_from = tileProps.pattern_from;
#else
@@ -420,10 +422,10 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
const float2 pattern_tl_b = pattern_to.xy;
const float2 pattern_br_b = pattern_to.zw;
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 float pixelRatio = paintParams.pixel_ratio;
const float tileZoomRatio = drawable.tile_ratio;
const float fromScale = props.from_scale;
const float toScale = props.to_scale;
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);
@@ -434,7 +436,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
.position = position,
.v_pos_a = get_pattern_pos(drawable.pixel_coord_upper, drawable.pixel_coord_lower, fromScale * display_size_a, tileZoomRatio, pos2),
.v_pos_b = get_pattern_pos(drawable.pixel_coord_upper, drawable.pixel_coord_lower, toScale * display_size_b, tileZoomRatio, pos2),
.v_pos = (position.xy / position.w + 1.0) / 2.0 * drawable.world,
.v_pos = (position.xy / position.w + 1.0) / 2.0 * paintParams.world_size,
#if !defined(HAS_UNIFORM_u_pattern_from)
.pattern_from = half4(pattern_from),
@@ -449,9 +451,9 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
}
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
device const FillOutlinePatternDrawableUBO& drawable [[buffer(0)]],
device const FillOutlinePatternTilePropsUBO& tileProps [[buffer(1)]],
device const FillEvaluatedPropsUBO& props [[buffer(3)]],
device const FillOutlinePatternDrawableUBO& drawable [[buffer(1)]],
device const FillOutlinePatternTilePropsUBO& tileProps [[buffer(2)]],
device const FillEvaluatedPropsUBO& props [[buffer(4)]],
texture2d<float, access::sample> image0 [[texture(0)]],
sampler image0_sampler [[sampler(0)]]) {
#if defined(OVERDRAW_INSPECTOR)
@@ -504,15 +506,15 @@ struct ShaderSource<BuiltIn::FillOutlineTriangulatedShader, gfx::Backend::Type::
static constexpr auto vertexMainFunction = "vertexMain";
static constexpr auto fragmentMainFunction = "fragmentMain";
static const std::array<UniformBlockInfo, 2> uniforms;
static const std::array<UniformBlockInfo, 3> uniforms;
static const std::array<AttributeInfo, 2> attributes;
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 0> textures;
static constexpr auto source = R"(
struct VertexStage {
short2 pos_normal [[attribute(4)]];
uchar4 data [[attribute(5)]];
short2 pos_normal [[attribute(5)]];
uchar4 data [[attribute(6)]];
};
struct FragmentStage {
@@ -524,14 +526,14 @@ struct FragmentStage {
struct alignas(16) FillOutlineTriangulatedDrawableUBO {
float4x4 matrix;
float2 units_to_pixels;
float ratio;
float pad;
float pad1, pad2, pad3;
};
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
device const FillOutlineTriangulatedDrawableUBO& drawable [[buffer(0)]],
device const FillEvaluatedPropsUBO& props [[buffer(3)]]) {
device const GlobalPaintParamsUBO& paintParams [[buffer(0)]],
device const FillOutlineTriangulatedDrawableUBO& drawable [[buffer(1)]],
device const FillEvaluatedPropsUBO& props [[buffer(4)]]) {
// the distance over which the line edge fades out.
// Retina devices need a smaller distance to avoid aliasing.
@@ -546,7 +548,8 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
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 = props.width / 2.0;
const float width = 1.0; //Should come from props ubo
const float halfwidth = width / 2.0;
const float outset = halfwidth + (halfwidth == 0.0 ? 0.0 : ANTIALIASING);
// Scale the extrusion vector down to a normal and then up by the line width of this vertex.
@@ -557,7 +560,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
// 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 * drawable.units_to_pixels);
const float extrude_length_with_perspective = length(projected_extrude.xy / position.w * paintParams.units_to_pixels);
return {
.position = position,
@@ -568,7 +571,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
}
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
device const FillEvaluatedPropsUBO& props [[buffer(3)]]) {
device const FillEvaluatedPropsUBO& props [[buffer(4)]]) {
// Calculate the distance of the pixel from the line in pixels.
const float dist = length(in.normal) * in.width2;

View File

@@ -21,17 +21,17 @@ struct ShaderSource<BuiltIn::FillExtrusionShader, gfx::Backend::Type::Metal> {
static constexpr auto source = R"(
struct VertexStage {
short2 pos [[attribute(4)]];
short4 normal_ed [[attribute(5)]];
short2 pos [[attribute(5)]];
short4 normal_ed [[attribute(6)]];
#if !defined(HAS_UNIFORM_u_color)
float4 color [[attribute(6)]];
float4 color [[attribute(7)]];
#endif
#if !defined(HAS_UNIFORM_u_base)
float base [[attribute(7)]];
float base [[attribute(8)]];
#endif
#if !defined(HAS_UNIFORM_u_height)
float height [[attribute(8)]];
float height [[attribute(9)]];
#endif
};
@@ -46,9 +46,9 @@ struct FragmentOutput {
};
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
device const FillExtrusionDrawableUBO& fill [[buffer(0)]],
device const FillExtrusionPropsUBO& props [[buffer(1)]],
device const FillExtrusionInterpolateUBO& interp [[buffer(3)]]) {
device const FillExtrusionDrawableUBO& drawable [[buffer(1)]],
device const FillExtrusionPropsUBO& props [[buffer(2)]],
device const FillExtrusionInterpolateUBO& interp [[buffer(4)]]) {
#if defined(HAS_UNIFORM_u_base)
const auto base = props.light_position_base.w;
@@ -64,7 +64,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
const float3 normal = float3(vertx.normal_ed.xyz);
const float t = glMod(normal.x, 2.0);
const float z = (t != 0.0) ? height : base; // TODO: This would come out wrong on GL for negative values, check it...
const float4 position = fill.matrix * float4(float2(vertx.pos), z, 1);
const float4 position = drawable.matrix * float4(float2(vertx.pos), z, 1);
#if defined(OVERDRAW_INSPECTOR)
return {

View File

@@ -14,27 +14,27 @@ struct ShaderSource<BuiltIn::FillExtrusionPatternShader, gfx::Backend::Type::Met
static constexpr auto vertexMainFunction = "vertexMain";
static constexpr auto fragmentMainFunction = "fragmentMain";
static const std::array<UniformBlockInfo, 4> uniforms;
static const std::array<UniformBlockInfo, 5> uniforms;
static const std::array<AttributeInfo, 6> attributes;
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 1> textures;
static constexpr auto source = R"(
struct VertexStage {
short2 pos [[attribute(4)]];
short4 normal_ed [[attribute(5)]];
short2 pos [[attribute(5)]];
short4 normal_ed [[attribute(6)]];
#if !defined(HAS_UNIFORM_u_base)
float base [[attribute(6)]];
float base [[attribute(7)]];
#endif
#if !defined(HAS_UNIFORM_u_height)
float height [[attribute(7)]];
float height [[attribute(8)]];
#endif
#if !defined(HAS_UNIFORM_u_pattern_from)
ushort4 pattern_from [[attribute(8)]];
ushort4 pattern_from [[attribute(9)]];
#endif
#if !defined(HAS_UNIFORM_u_pattern_to)
ushort4 pattern_to [[attribute(9)]];
ushort4 pattern_to [[attribute(10)]];
#endif
};
@@ -58,10 +58,11 @@ struct FragmentOutput {
};
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
device const FillExtrusionDrawableUBO& fill [[buffer(0)]],
device const FillExtrusionPropsUBO& props [[buffer(1)]],
device const FillExtrusionTilePropsUBO& tileProps [[buffer(2)]],
device const FillExtrusionInterpolateUBO& interp [[buffer(3)]]) {
device const GlobalPaintParamsUBO& paintParams [[buffer(0)]],
device const FillExtrusionDrawableUBO& drawable [[buffer(1)]],
device const FillExtrusionPropsUBO& props [[buffer(2)]],
device const FillExtrusionTilePropsUBO& tileProps [[buffer(3)]],
device const FillExtrusionInterpolateUBO& interp [[buffer(4)]]) {
#if defined(HAS_UNIFORM_u_base)
const auto base = props.light_position_base.w;
@@ -78,7 +79,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
const float edgedistance = vertx.normal_ed.w;
const float t = glMod(normal.x, 2.0);
const float z = (t != 0.0) ? height : base; // TODO: This would come out wrong on GL for negative values, check it...
const float4 position = fill.matrix * float4(float2(vertx.pos), z, 1);
const float4 position = drawable.matrix * float4(float2(vertx.pos), z, 1);
#if defined(OVERDRAW_INSPECTOR)
return {
@@ -107,17 +108,17 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
const float2 pattern_tl_b = pattern_to.xy;
const float2 pattern_br_b = pattern_to.zw;
const float pixelRatio = fill.scale.x;
const float tileZoomRatio = fill.scale.y;
const float fromScale = fill.scale.z;
const float toScale = fill.scale.w;
const float pixelRatio = paintParams.pixel_ratio;
const float tileZoomRatio = drawable.tile_ratio;
const float fromScale = props.from_scale;
const float toScale = props.to_scale;
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);
const float2 pos = normal.x == 1.0 && normal.y == 0.0 && normal.z == 16384.0
? float2(vertx.pos) // extrusion top
: float2(edgedistance, z * fill.height_factor); // extrusion side
: float2(edgedistance, z * drawable.height_factor); // extrusion side
float4 lighting = float4(0.0, 0.0, 0.0, 1.0);
float directional = clamp(dot(normal / 16383.0, props.light_position_base.xyz), 0.0, 1.0);
@@ -143,15 +144,15 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
#if !defined(HAS_UNIFORM_u_pattern_from)
.pattern_to = half4(pattern_to),
#endif
.pos_a = get_pattern_pos(fill.pixel_coord_upper, fill.pixel_coord_lower, fromScale * display_size_a, tileZoomRatio, pos),
.pos_b = get_pattern_pos(fill.pixel_coord_upper, fill.pixel_coord_lower, toScale * display_size_b, tileZoomRatio, pos),
.pos_a = get_pattern_pos(drawable.pixel_coord_upper, drawable.pixel_coord_lower, fromScale * display_size_a, tileZoomRatio, pos),
.pos_b = get_pattern_pos(drawable.pixel_coord_upper, drawable.pixel_coord_lower, toScale * display_size_b, tileZoomRatio, pos),
};
}
fragment FragmentOutput fragmentMain(FragmentStage in [[stage_in]],
device const FillExtrusionDrawableUBO& fill [[buffer(0)]],
device const FillExtrusionPropsUBO& props [[buffer(1)]],
device const FillExtrusionTilePropsUBO& tileProps [[buffer(2)]],
device const FillExtrusionDrawableUBO& drawable [[buffer(1)]],
device const FillExtrusionPropsUBO& props [[buffer(2)]],
device const FillExtrusionTilePropsUBO& tileProps [[buffer(3)]],
texture2d<float, access::sample> image0 [[texture(0)]],
sampler image0_sampler [[sampler(0)]]) {
#if defined(OVERDRAW_INSPECTOR)
@@ -175,11 +176,11 @@ fragment FragmentOutput fragmentMain(FragmentStage in [[stage_in]],
const float2 pattern_br_b = pattern_to.zw;
const float2 imagecoord = glMod(in.pos_a, 1.0);
const float2 pos = mix(pattern_tl_a / fill.texsize, pattern_br_a / fill.texsize, imagecoord);
const float2 pos = mix(pattern_tl_a / drawable.texsize, pattern_br_a / drawable.texsize, imagecoord);
const float4 color1 = image0.sample(image0_sampler, pos);
const float2 imagecoord_b = glMod(in.pos_b, 1.0);
const float2 pos2 = mix(pattern_tl_b / fill.texsize, pattern_br_b / fill.texsize, imagecoord_b);
const float2 pos2 = mix(pattern_tl_b / drawable.texsize, pattern_br_b / drawable.texsize, imagecoord_b);
const float4 color2 = image0.sample(image0_sampler, pos2);
return {half4(mix(color1, color2, props.fade) * in.lighting)/*, in.position.z*/};

View File

@@ -22,13 +22,13 @@ struct ShaderSource<BuiltIn::HeatmapShader, gfx::Backend::Type::Metal> {
static constexpr auto source = R"(
struct VertexStage {
short2 pos [[attribute(3)]];
short2 pos [[attribute(4)]];
#if !defined(HAS_UNIFORM_u_weight)
float2 weight [[attribute(4)]];
float2 weight [[attribute(5)]];
#endif
#if !defined(HAS_UNIFORM_u_radius)
float2 radius [[attribute(5)]];
float2 radius [[attribute(6)]];
#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(0)]],
device const HeatmapEvaluatedPropsUBO& props [[buffer(1)]],
device const HeatmapInterpolateUBO& interp [[buffer(2)]]) {
device const HeatmapDrawableUBO& drawable [[buffer(1)]],
device const HeatmapEvaluatedPropsUBO& props [[buffer(2)]],
device const HeatmapInterpolateUBO& interp [[buffer(3)]]) {
#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(1)]]) {
device const HeatmapEvaluatedPropsUBO& props [[buffer(2)]]) {
#if defined(OVERDRAW_INSPECTOR)
return half4(1.0);
#endif

View File

@@ -14,7 +14,7 @@ struct ShaderSource<BuiltIn::HeatmapTextureShader, gfx::Backend::Type::Metal> {
static constexpr auto vertexMainFunction = "vertexMain";
static constexpr auto fragmentMainFunction = "fragmentMain";
static const std::array<UniformBlockInfo, 1> uniforms;
static const std::array<UniformBlockInfo, 2> uniforms;
static const std::array<AttributeInfo, 1> attributes;
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 2> textures;
@@ -22,7 +22,7 @@ struct ShaderSource<BuiltIn::HeatmapTextureShader, gfx::Backend::Type::Metal> {
static constexpr auto source = R"(
struct VertexStage {
short2 pos [[attribute(1)]];
short2 pos [[attribute(2)]];
};
struct FragmentStage {
@@ -32,17 +32,16 @@ struct FragmentStage {
struct alignas(16) HeatmapTexturePropsUBO {
float4x4 matrix;
float2 world;
float opacity;
bool overdrawInspector;
uint8_t pad1, pad2, pad3;
float pad1, pad2, pad3;
};
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
device const HeatmapTexturePropsUBO& props [[buffer(0)]]) {
device const GlobalPaintParamsUBO& paintParams [[buffer(0)]],
device const HeatmapTexturePropsUBO& props [[buffer(1)]]) {
const float2 pos = float2(vertx.pos);
const float4 position = props.matrix * float4(pos * props.world, 0, 1);
const float4 position = props.matrix * float4(pos * paintParams.world_size, 0, 1);
return {
.position = position,
@@ -51,7 +50,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
}
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
device const HeatmapTexturePropsUBO& props [[buffer(0)]],
device const HeatmapTexturePropsUBO& props [[buffer(1)]],
texture2d<float, access::sample> image [[texture(0)]],
texture2d<float, access::sample> color_ramp [[texture(1)]],
sampler image_sampler [[sampler(0)]],

View File

@@ -22,8 +22,8 @@ struct ShaderSource<BuiltIn::HillshadeShader, gfx::Backend::Type::Metal> {
static constexpr auto source = R"(
struct VertexStage {
short2 pos [[attribute(2)]];
short2 texture_pos [[attribute(3)]];
short2 pos [[attribute(3)]];
short2 texture_pos [[attribute(4)]];
};
struct FragmentStage {
@@ -44,7 +44,7 @@ struct alignas(16) HillshadeEvaluatedPropsUBO {
};
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
device const HillshadeDrawableUBO& drawable [[buffer(0)]]) {
device const HillshadeDrawableUBO& drawable [[buffer(1)]]) {
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(0)]],
device const HillshadeEvaluatedPropsUBO& props [[buffer(1)]],
device const HillshadeDrawableUBO& drawable [[buffer(1)]],
device const HillshadeEvaluatedPropsUBO& props [[buffer(2)]],
texture2d<float, access::sample> image [[texture(0)]],
sampler image_sampler [[sampler(0)]]) {
#if defined(OVERDRAW_INSPECTOR)

View File

@@ -21,8 +21,8 @@ struct ShaderSource<BuiltIn::HillshadePrepareShader, gfx::Backend::Type::Metal>
static constexpr auto source = R"(
struct VertexStage {
short2 pos [[attribute(1)]];
short2 texture_pos [[attribute(2)]];
short2 pos [[attribute(2)]];
short2 texture_pos [[attribute(3)]];
};
struct FragmentStage {
@@ -39,7 +39,7 @@ struct alignas(16) HillshadePrepareDrawableUBO {
};
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
device const HillshadePrepareDrawableUBO& drawable [[buffer(0)]]) {
device const HillshadePrepareDrawableUBO& drawable [[buffer(1)]]) {
const float4 position = drawable.matrix * float4(float2(vertx.pos), 0, 1);
@@ -61,7 +61,7 @@ float getElevation(float2 coord, float bias, texture2d<float, access::sample> im
}
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
device const HillshadePrepareDrawableUBO& drawable [[buffer(0)]],
device const HillshadePrepareDrawableUBO& drawable [[buffer(1)]],
texture2d<float, access::sample> image [[texture(0)]],
sampler image_sampler [[sampler(0)]]) {
#if defined(OVERDRAW_INSPECTOR)

View File

@@ -78,7 +78,7 @@ struct alignas(16) LineInterpolationUBO {
};
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
device const LineDynamicUBO& dynamic [[buffer(0)]],
device const GlobalPaintParamsUBO& paintParams [[buffer(0)]],
device const LineDrawableUBO& drawable [[buffer(1)]],
device const LineInterpolationUBO& interp [[buffer(2)]],
device const LineEvaluatedPropsUBO& props [[buffer(4)]]) {
@@ -133,7 +133,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
// 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);
const float extrude_length_with_perspective = length(projected_extrude.xy / position.w * paintParams.units_to_pixels);
return {
.position = position,
@@ -241,7 +241,7 @@ struct alignas(16) LineGradientInterpolationUBO {
};
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
device const LineDynamicUBO& dynamic [[buffer(0)]],
device const GlobalPaintParamsUBO& paintParams [[buffer(0)]],
device const LineGradientDrawableUBO& drawable [[buffer(1)]],
device const LineGradientInterpolationUBO& interp [[buffer(2)]],
device const LineEvaluatedPropsUBO& props [[buffer(4)]]) {
@@ -303,7 +303,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
// 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);
const float extrude_length_with_perspective = length(projected_extrude.xy / position.w * paintParams.units_to_pixels);
return {
.position = position,
@@ -442,7 +442,7 @@ struct alignas(16) LinePatternTilePropertiesUBO {
};
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
device const LineDynamicUBO& dynamic [[buffer(0)]],
device const GlobalPaintParamsUBO& paintParams [[buffer(0)]],
device const LinePatternDrawableUBO& drawable [[buffer(1)]],
device const LinePatternInterpolationUBO& interp [[buffer(2)]],
device const LinePatternTilePropertiesUBO& tileProps [[buffer(3)]],
@@ -500,7 +500,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
// 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);
const float extrude_length_with_perspective = length(projected_extrude.xy / position.w * paintParams.units_to_pixels);
return {
.position = position,
@@ -685,7 +685,7 @@ struct alignas(16) LineSDFInterpolationUBO {
};
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
device const LineDynamicUBO& dynamic [[buffer(0)]],
device const GlobalPaintParamsUBO& paintParams [[buffer(0)]],
device const LineSDFDrawableUBO& drawable [[buffer(1)]],
device const LineSDFInterpolationUBO& interp [[buffer(2)]],
device const LineEvaluatedPropsUBO& props [[buffer(4)]]) {
@@ -747,7 +747,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
// 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);
const float extrude_length_with_perspective = length(projected_extrude.xy / position.w * paintParams.units_to_pixels);
return {
.position = position,

View File

@@ -22,8 +22,8 @@ struct ShaderSource<BuiltIn::RasterShader, gfx::Backend::Type::Metal> {
static constexpr auto source = R"(
struct VertexStage {
short2 pos [[attribute(2)]];
short2 texture_pos [[attribute(3)]];
short2 pos [[attribute(3)]];
short2 texture_pos [[attribute(4)]];
};
struct FragmentStage {
@@ -37,7 +37,7 @@ struct alignas(16) RasterDrawableUBO {
};
struct alignas(16) RasterEvaluatedPropsUBO {
float3 spin_weights;
float4 spin_weights;
float2 tl_parent;
float scale_parent;
float buffer_scale;
@@ -47,14 +47,12 @@ struct alignas(16) RasterEvaluatedPropsUBO {
float brightness_high;
float saturation_factor;
float contrast_factor;
bool overdrawInspector;
uint8_t pad1, pad2, pad3;
float pad4;
float pad1, pad2;
};
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
device const RasterDrawableUBO& drawable [[buffer(0)]],
device const RasterEvaluatedPropsUBO& props [[buffer(1)]]) {
device const RasterDrawableUBO& drawable [[buffer(1)]],
device const RasterEvaluatedPropsUBO& props [[buffer(2)]]) {
const float4 position = drawable.matrix * float4(float2(vertx.pos), 0, 1);
@@ -74,7 +72,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
}
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
device const RasterEvaluatedPropsUBO& props [[buffer(1)]],
device const RasterEvaluatedPropsUBO& props [[buffer(2)]],
texture2d<float, access::sample> image0 [[texture(0)]],
texture2d<float, access::sample> image1 [[texture(1)]],
sampler image0_sampler [[sampler(0)]],

View File

@@ -46,7 +46,7 @@ struct FragmentStage {
};
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
device const SymbolDynamicUBO& dynamic [[buffer(0)]],
device const GlobalPaintParamsUBO& paintParams [[buffer(0)]],
device const SymbolDrawableUBO& drawable [[buffer(1)]],
device const SymbolTilePropsUBO& tileprops [[buffer(2)]],
device const SymbolInterpolateUBO& interp [[buffer(3)]],
@@ -77,8 +77,8 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
const float camera_to_anchor_distance = projectedPoint.w;
// See comments in symbol_sdf.vertex
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;
camera_to_anchor_distance / paintParams.camera_to_center_distance :
paintParams.camera_to_center_distance / camera_to_anchor_distance;
const float perspective_ratio = clamp(
0.5 + 0.5 * distance_ratio,
0.0, // Prevents oversized near-field symbols in pitched/overzoomed tiles
@@ -95,7 +95,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
const float2 a = projectedPoint.xy / projectedPoint.w;
const float2 b = offsetProjectedPoint.xy / offsetProjectedPoint.w;
symbol_rotation = atan2((b.y - a.y) / dynamic.aspect_ratio, b.x - a.x);
symbol_rotation = atan2((b.y - a.y) / paintParams.aspect_ratio, b.x - a.x);
}
const float angle_sin = sin(segment_angle + symbol_rotation);
@@ -108,7 +108,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
const float4 position = drawable.coord_matrix * float4(pos0 + rotation_matrix * posOffset, 0.0, 1.0);
const float2 raw_fade_opacity = unpack_opacity(vertx.fade_opacity);
const float fade_change = raw_fade_opacity[1] > 0.5 ? dynamic.fade_change : -dynamic.fade_change;
const float fade_change = raw_fade_opacity[1] > 0.5 ? paintParams.symbol_fade_change : -paintParams.symbol_fade_change;
const float fade_opacity = max(0.0, min(1.0, raw_fade_opacity[0] + fade_change));
return {
@@ -123,7 +123,6 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
}
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
device const SymbolDynamicUBO& dynamic [[buffer(0)]],
device const SymbolDrawableUBO& drawable [[buffer(1)]],
device const SymbolTilePropsUBO& tileprops [[buffer(2)]],
device const SymbolEvaluatedPropsUBO& props [[buffer(4)]],

View File

@@ -71,7 +71,7 @@ struct FragmentStage {
};
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
device const SymbolDynamicUBO& dynamic [[buffer(0)]],
device const GlobalPaintParamsUBO& paintParams [[buffer(0)]],
device const SymbolDrawableUBO& drawable [[buffer(1)]],
device const SymbolTilePropsUBO& tileprops [[buffer(2)]],
device const SymbolInterpolateUBO& interp [[buffer(3)]],
@@ -106,8 +106,8 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
// 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 = tileprops.pitch_with_map ?
camera_to_anchor_distance / dynamic.camera_to_center_distance :
dynamic.camera_to_center_distance / camera_to_anchor_distance;
camera_to_anchor_distance / paintParams.camera_to_center_distance :
paintParams.camera_to_center_distance / camera_to_anchor_distance;
const float perspective_ratio = clamp(
0.5 + 0.5 * distance_ratio,
0.0, // Prevents oversized near-field symbols in pitched/overzoomed tiles
@@ -127,7 +127,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
const float2 a = projectedPoint.xy / projectedPoint.w;
const float2 b = offsetProjectedPoint.xy / offsetProjectedPoint.w;
symbol_rotation = atan2((b.y - a.y) / dynamic.aspect_ratio, b.x - a.x);
symbol_rotation = atan2((b.y - a.y) / paintParams.aspect_ratio, b.x - a.x);
}
const float angle_sin = sin(segment_angle + symbol_rotation);
@@ -138,7 +138,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
const float2 pos0 = projected_pos.xy / projected_pos.w + rotation_matrix * pos_rot;
const float4 position = drawable.coord_matrix * float4(pos0, 0.0, 1.0);
const float2 fade_opacity = unpack_opacity(vertx.fade_opacity);
const float fade_change = (fade_opacity[1] > 0.5) ? dynamic.fade_change : -dynamic.fade_change;
const float fade_change = (fade_opacity[1] > 0.5) ? paintParams.symbol_fade_change : -paintParams.symbol_fade_change;
return {
.position = position,
@@ -165,7 +165,6 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
}
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
device const SymbolDynamicUBO& dynamic [[buffer(0)]],
device const SymbolDrawableUBO& drawable [[buffer(1)]],
device const SymbolTilePropsUBO& tileprops [[buffer(2)]],
device const SymbolEvaluatedPropsUBO& props [[buffer(4)]],

View File

@@ -75,7 +75,7 @@ struct FragmentStage {
};
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
device const SymbolDynamicUBO& dynamic [[buffer(0)]],
device const GlobalPaintParamsUBO& paintParams [[buffer(0)]],
device const SymbolDrawableUBO& drawable [[buffer(1)]],
device const SymbolTilePropsUBO& tileprops [[buffer(2)]],
device const SymbolInterpolateUBO& interp [[buffer(3)]],
@@ -110,8 +110,8 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
// 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 = tileprops.pitch_with_map ?
camera_to_anchor_distance / dynamic.camera_to_center_distance :
dynamic.camera_to_center_distance / camera_to_anchor_distance;
camera_to_anchor_distance / paintParams.camera_to_center_distance :
paintParams.camera_to_center_distance / camera_to_anchor_distance;
const float perspective_ratio = clamp(
0.5 + 0.5 * distance_ratio,
0.0, // Prevents oversized near-field symbols in pitched/overzoomed tiles
@@ -131,7 +131,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
const float2 a = projectedPoint.xy / projectedPoint.w;
const float2 b = offsetProjectedPoint.xy / offsetProjectedPoint.w;
symbol_rotation = atan2((b.y - a.y) / dynamic.aspect_ratio, b.x - a.x);
symbol_rotation = atan2((b.y - a.y) / paintParams.aspect_ratio, b.x - a.x);
}
const float angle_sin = sin(segment_angle + symbol_rotation);
@@ -145,7 +145,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
const float gamma_scale = position.w;
const float2 fade_opacity = unpack_opacity(vertx.fade_opacity);
const float fade_change = (fade_opacity[1] > 0.5) ? dynamic.fade_change : -dynamic.fade_change;
const float fade_change = (fade_opacity[1] > 0.5) ? paintParams.symbol_fade_change : -paintParams.symbol_fade_change;
const bool is_icon = (is_sdf == ICON);
return {
@@ -175,7 +175,6 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
}
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
device const SymbolDynamicUBO& dynamic [[buffer(0)]],
device const SymbolDrawableUBO& drawable [[buffer(1)]],
device const SymbolTilePropsUBO& tileprops [[buffer(2)]],
device const SymbolEvaluatedPropsUBO& props [[buffer(4)]],

View File

@@ -23,10 +23,10 @@ struct ShaderSource<BuiltIn::WideVectorShader, gfx::Backend::Type::Metal> {
AttributeInfo{wideVectorUBOCount + 1, gfx::AttributeDataType::Float4, idWideVectorColor},
AttributeInfo{wideVectorUBOCount + 2, gfx::AttributeDataType::Int, idWideVectorIndex}};
static constexpr std::array<AttributeInfo, 4> instanceAttributes{
AttributeInfo{5, gfx::AttributeDataType::Float3, idWideVectorInstanceCenter},
AttributeInfo{5, gfx::AttributeDataType::Float4, idWideVectorInstanceColor},
AttributeInfo{5, gfx::AttributeDataType::Int, idWideVectorInstancePrevious},
AttributeInfo{5, gfx::AttributeDataType::Int, idWideVectorInstanceNext}};
AttributeInfo{wideVectorUBOCount + 3, gfx::AttributeDataType::Float3, idWideVectorInstanceCenter},
AttributeInfo{wideVectorUBOCount + 3, gfx::AttributeDataType::Float4, idWideVectorInstanceColor},
AttributeInfo{wideVectorUBOCount + 3, gfx::AttributeDataType::Int, idWideVectorInstancePrevious},
AttributeInfo{wideVectorUBOCount + 3, gfx::AttributeDataType::Int, idWideVectorInstanceNext}};
static constexpr std::array<TextureInfo, 0> textures{};
static constexpr auto source = R"(
@@ -112,9 +112,9 @@ typedef struct
struct VertexTriWideVecB
{
// x, y offset around the center
float3 screenPos [[attribute(2)]];
float4 color [[attribute(3)]];
int index [[attribute(4)]];
float3 screenPos [[attribute(3)]];
float4 color [[attribute(4)]];
int index [[attribute(5)]];
};
// Wide vector vertex passed to fragment shader (new version)
@@ -221,10 +221,10 @@ 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(0) ]],
constant UniformWideVec &wideVec [[ buffer(1) ]],
constant Uniforms &uniforms [[ buffer(1) ]],
constant UniformWideVec &wideVec [[ buffer(2) ]],
uint instanceID [[ instance_id ]],
constant VertexTriWideVecInstance *wideVecInsts [[ buffer(5) ]])
constant VertexTriWideVecInstance *wideVecInsts [[ buffer(6) ]])
{
ProjVertexTriWideVecPerf outVert = {
.position = discardPt,
@@ -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(0) ]])
constant Uniforms &uniforms [[ buffer(1) ]])
{
float patternAlpha = 1.0;

View File

@@ -26,7 +26,7 @@ struct alignas(16) RasterEvaluatedPropsUBO {
static_assert(sizeof(RasterEvaluatedPropsUBO) == 64);
enum {
idRasterDrawableUBO,
idRasterDrawableUBO = globalUBOCount,
idRasterEvaluatedPropsUBO,
rasterUBOCount
};

View File

@@ -23,7 +23,7 @@ namespace shaders {
// UBO defines
enum {
idClippingMaskUBO,
idClippingMaskUBO = globalUBOCount,
clippingMaskUBOCount
};

View File

@@ -5,16 +5,6 @@
namespace mbgl {
namespace shaders {
/// 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(SymbolDynamicUBO) == 16);
struct alignas(16) SymbolDrawableUBO {
/* 0 */ std::array<float, 4 * 4> matrix;
/* 64 */ std::array<float, 4 * 4> label_plane_matrix;
@@ -76,8 +66,7 @@ struct alignas(16) SymbolEvaluatedPropsUBO {
static_assert(sizeof(SymbolEvaluatedPropsUBO) == 6 * 16);
enum {
idSymbolDynamicUBO,
idSymbolDrawableUBO,
idSymbolDrawableUBO = globalUBOCount,
idSymbolTilePropsUBO,
idSymbolInterpolateUBO,
idSymbolEvaluatedPropsUBO,

View File

@@ -32,7 +32,7 @@ struct alignas(16) WideVectorUniformWideVecUBO {
static_assert(sizeof(WideVectorUniformWideVecUBO) % 16 == 0);
enum {
idWideVectorUniformsUBO,
idWideVectorUniformsUBO = globalUBOCount,
idWideVectorUniformWideVecUBO,
wideVectorUBOCount
};

View File

@@ -1,16 +1,25 @@
layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform BackgroundPatternLayerUBO {
highp vec2 u_pattern_tl_a;
highp vec2 u_pattern_br_a;
highp vec2 u_pattern_tl_b;
highp vec2 u_pattern_br_b;
highp vec2 u_texsize;
highp vec2 u_pattern_size_a;
highp vec2 u_pattern_size_b;
highp float u_scale_a;
highp float u_scale_b;
highp float u_mix;
highp float u_opacity;
highp float layer_pad1, layer_pad2;
};
uniform sampler2D u_image;
@@ -20,11 +29,11 @@ in mediump vec2 v_pos_b;
void main() {
vec2 imagecoord = mod(v_pos_a, 1.0);
vec2 pos = mix(u_pattern_tl_a / u_texsize, u_pattern_br_a / u_texsize, imagecoord);
vec2 pos = mix(u_pattern_tl_a / u_pattern_atlas_texsize, u_pattern_br_a / u_pattern_atlas_texsize, imagecoord);
vec4 color1 = texture(u_image, pos);
vec2 imagecoord_b = mod(v_pos_b, 1.0);
vec2 pos2 = mix(u_pattern_tl_b / u_texsize, u_pattern_br_b / u_texsize, imagecoord_b);
vec2 pos2 = mix(u_pattern_tl_b / u_pattern_atlas_texsize, u_pattern_br_b / u_pattern_atlas_texsize, imagecoord_b);
vec4 color2 = texture(u_image, pos2);
fragColor = mix(color1, color2, u_mix) * u_opacity;

View File

@@ -10,14 +10,12 @@ layout (std140) uniform BackgroundPatternLayerUBO {
highp vec2 u_pattern_br_a;
highp vec2 u_pattern_tl_b;
highp vec2 u_pattern_br_b;
highp vec2 u_texsize;
highp vec2 u_pattern_size_a;
highp vec2 u_pattern_size_b;
highp float u_scale_a;
highp float u_scale_b;
highp float u_mix;
highp float u_opacity;
highp float layer_pad1, layer_pad2;
};
layout (location = 0) in vec2 a_pos;

View File

@@ -1,18 +1,23 @@
layout (location = 0) in vec2 a_pos;
out vec3 v_data;
layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform CircleDrawableUBO {
highp mat4 u_matrix;
highp vec2 u_extrude_scale;
lowp vec2 drawable_pad1;
};
layout (std140) uniform CirclePaintParamsUBO {
highp float u_camera_to_center_distance;
lowp float params_pad1;
lowp vec2 params_pad2;
};
layout (std140) uniform CircleEvaluatedPropsUBO {
highp vec4 u_color;
highp vec4 u_stroke_color;

View File

@@ -1,7 +1,7 @@
layout (std140) uniform CollisionBoxUBO {
layout (std140) uniform CollisionUBO {
highp mat4 u_matrix;
highp vec2 u_extrude_scale;
highp float u_camera_to_center_distance;
highp float u_overscale_factor;
highp float pad1;
};

View File

@@ -4,10 +4,21 @@ layout (location = 2) in vec2 a_extrude;
layout (location = 3) in vec2 a_placed;
layout (location = 4) in vec2 a_shift;
layout (std140) uniform CollisionBoxUBO {
layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform CollisionUBO {
highp mat4 u_matrix;
highp vec2 u_extrude_scale;
highp float u_camera_to_center_distance;
highp float u_overscale_factor;
highp float pad1;
};

View File

@@ -1,8 +1,19 @@
layout (std140) uniform CollisionCircleUBO {
layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform CollisionUBO {
highp mat4 u_matrix;
highp vec2 u_extrude_scale;
highp float u_camera_to_center_distance;
highp float u_overscale_factor;
highp float pad1;
};
in float v_placed;

View File

@@ -3,11 +3,22 @@ layout (location = 1) in vec2 a_anchor_pos;
layout (location = 2) in vec2 a_extrude;
layout (location = 3) in vec2 a_placed;
layout (std140) uniform CollisionCircleUBO {
layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform CollisionUBO {
highp mat4 u_matrix;
highp vec2 u_extrude_scale;
highp float u_camera_to_center_distance;
highp float u_overscale_factor;
highp float pad1;
};
out float v_placed;

View File

@@ -8,8 +8,8 @@ layout (std140) uniform FillEvaluatedPropsUBO {
highp vec4 u_outline_color;
highp float u_opacity;
highp float u_fade;
highp float u_width;
highp float props_pad1;
highp float u_from_scale;
highp float u_to_scale;
};
#pragma mapbox: define highp vec4 color

View File

@@ -11,8 +11,8 @@ layout (std140) uniform FillEvaluatedPropsUBO {
highp vec4 u_outline_color;
highp float u_opacity;
highp float u_fade;
highp float u_width;
highp float props_pad1;
highp float u_from_scale;
highp float u_to_scale;
};
layout (location = 0) in vec2 a_pos;

View File

@@ -4,12 +4,11 @@ out vec4 v_color;
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;
highp float u_tile_ratio;
};
layout (std140) uniform FillExtrusionPropsUBO {
highp vec4 u_color;
@@ -22,7 +21,9 @@ layout (std140) uniform FillExtrusionPropsUBO {
highp float u_vertical_gradient;
highp float u_opacity;
highp float u_fade;
highp float props_pad2, props_pad3, props_pad4;
highp float u_from_scale;
highp float u_to_scale;
highp float props_pad2;
};
layout (std140) uniform FillExtrusionTilePropsUBO {
highp vec4 u_pattern_from;

View File

@@ -4,12 +4,11 @@ in vec4 v_lighting;
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;
highp float u_tile_ratio;
};
layout (std140) uniform FillExtrusionPropsUBO {
highp vec4 u_color;
@@ -22,7 +21,9 @@ layout (std140) uniform FillExtrusionPropsUBO {
highp float u_vertical_gradient;
highp float u_opacity;
highp float u_fade;
highp float props_pad2, props_pad3, props_pad4;
highp float u_from_scale;
highp float u_to_scale;
highp float props_pad2;
};
layout (std140) uniform FillExtrusionTilePropsUBO {
highp vec4 u_pattern_from;

View File

@@ -5,14 +5,24 @@ out vec2 v_pos_a;
out vec2 v_pos_b;
out vec4 v_lighting;
layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
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;
highp float u_tile_ratio;
};
layout (std140) uniform FillExtrusionPropsUBO {
highp vec4 u_color;
@@ -25,7 +35,9 @@ layout (std140) uniform FillExtrusionPropsUBO {
highp float u_vertical_gradient;
highp float u_opacity;
highp float u_fade;
highp float props_pad2, props_pad3, props_pad4;
highp float u_from_scale;
highp float u_to_scale;
highp float props_pad2;
};
layout (std140) uniform FillExtrusionTilePropsUBO {
highp vec4 u_pattern_from;
@@ -56,10 +68,10 @@ void main() {
vec2 pattern_tl_b = pattern_to.xy;
vec2 pattern_br_b = pattern_to.zw;
float pixelRatio = u_scale.x;
float tileRatio = u_scale.y;
float fromScale = u_scale.z;
float toScale = u_scale.w;
float pixelRatio = u_pixel_ratio;
float tileRatio = u_tile_ratio;
float fromScale = u_from_scale;
float toScale = u_to_scale;
vec3 normal = a_normal_ed.xyz;
float edgedistance = a_normal_ed.w;

View File

@@ -9,8 +9,8 @@ layout (std140) uniform FillEvaluatedPropsUBO {
highp vec4 u_outline_color;
highp float u_opacity;
highp float u_fade;
highp float u_width;
highp float props_pad1;
highp float u_from_scale;
highp float u_to_scale;
};
in vec2 v_pos;

View File

@@ -1,7 +1,15 @@
layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform FillOutlineDrawableUBO {
highp mat4 u_matrix;
highp vec2 u_world;
highp vec2 drawable_pad1;
};
layout (std140) uniform FillOutlineInterpolateUBO {
highp float u_outline_color_t;
@@ -14,8 +22,8 @@ layout (std140) uniform FillEvaluatedPropsUBO {
highp vec4 u_outline_color;
highp float u_opacity;
highp float u_fade;
highp float u_width;
highp float props_pad1;
highp float u_from_scale;
highp float u_to_scale;
};
layout (location = 0) in vec2 a_pos;
@@ -30,5 +38,5 @@ void main() {
#pragma mapbox: initialize lowp float opacity
gl_Position = u_matrix * vec4(a_pos, 0, 1);
v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world;
v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world_size;
}

View File

@@ -1,10 +1,10 @@
layout (std140) uniform FillOutlinePatternDrawableUBO {
highp mat4 u_matrix;
highp vec4 u_scale;
highp vec2 u_world;
highp vec2 u_pixel_coord_upper;
highp vec2 u_pixel_coord_lower;
highp vec2 u_texsize;
highp float u_tile_ratio;
highp float drawable_pad1;
};
layout (std140) uniform FillOutlinePatternTilePropsUBO {
highp vec4 u_pattern_from;
@@ -21,8 +21,8 @@ layout (std140) uniform FillEvaluatedPropsUBO {
highp vec4 u_outline_color;
highp float u_opacity;
highp float u_fade;
highp float u_width;
highp float props_pad1;
highp float u_from_scale;
highp float u_to_scale;
};
uniform sampler2D u_image;

View File

@@ -1,10 +1,20 @@
layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform FillOutlinePatternDrawableUBO {
highp mat4 u_matrix;
highp vec4 u_scale;
highp vec2 u_world;
highp vec2 u_pixel_coord_upper;
highp vec2 u_pixel_coord_lower;
highp vec2 u_texsize;
highp float u_tile_ratio;
highp float drawable_pad1;
};
layout (std140) uniform FillOutlinePatternTilePropsUBO {
highp vec4 u_pattern_from;
@@ -21,8 +31,8 @@ layout (std140) uniform FillEvaluatedPropsUBO {
highp vec4 u_outline_color;
highp float u_opacity;
highp float u_fade;
highp float u_width;
highp float props_pad1;
highp float u_from_scale;
highp float u_to_scale;
};
layout (location = 0) in vec2 a_pos;
@@ -45,10 +55,10 @@ void main() {
vec2 pattern_tl_b = pattern_to.xy;
vec2 pattern_br_b = pattern_to.zw;
float pixelRatio = u_scale.x;
float tileRatio = u_scale.y;
float fromScale = u_scale.z;
float toScale = u_scale.w;
float pixelRatio = u_pixel_ratio;
float tileRatio = u_tile_ratio;
float fromScale = u_from_scale;
float toScale = u_to_scale;
gl_Position = u_matrix * vec4(a_pos, 0, 1);
@@ -58,5 +68,5 @@ void main() {
v_pos_a = get_pattern_pos(u_pixel_coord_upper, u_pixel_coord_lower, fromScale * display_size_a, tileRatio, a_pos);
v_pos_b = get_pattern_pos(u_pixel_coord_upper, u_pixel_coord_lower, toScale * display_size_b, tileRatio, a_pos);
v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world;
v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world_size;
}

View File

@@ -3,8 +3,8 @@ layout (std140) uniform FillEvaluatedPropsUBO {
highp vec4 u_outline_color;
highp float u_opacity;
highp float u_fade;
highp float u_width;
highp float props_pad1;
highp float u_from_scale;
highp float u_to_scale;
};
in float v_width;

View File

@@ -9,19 +9,28 @@
layout (location = 0) in vec2 a_pos_normal;
layout (location = 1) in vec4 a_data;
layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform FillOutlineTriangulatedDrawableUBO {
highp mat4 u_matrix;
highp vec2 u_units_to_pixels;
mediump float u_ratio;
lowp float drawable_pad1;
lowp float drawable_pad1, drawable_pad2, drawable_pad3;
};
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;
highp float u_from_scale;
highp float u_to_scale;
};
out vec2 v_normal;

View File

@@ -1,11 +1,10 @@
layout (std140) uniform FillPatternDrawableUBO {
highp mat4 u_matrix;
highp vec4 u_scale;
highp vec2 u_pixel_coord_upper;
highp vec2 u_pixel_coord_lower;
highp vec2 u_texsize;
highp float u_tile_ratio;
highp float drawable_pad1;
highp float drawable_pad2;
};
layout (std140) uniform FillPatternTilePropsUBO {
highp vec4 u_pattern_from;
@@ -22,8 +21,8 @@ layout (std140) uniform FillEvaluatedPropsUBO {
highp vec4 u_outline_color;
highp float u_opacity;
highp float u_fade;
highp float u_width;
highp float props_pad1;
highp float u_from_scale;
highp float u_to_scale;
};
uniform sampler2D u_image;

View File

@@ -1,11 +1,20 @@
layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform FillPatternDrawableUBO {
highp mat4 u_matrix;
highp vec4 u_scale;
highp vec2 u_pixel_coord_upper;
highp vec2 u_pixel_coord_lower;
highp vec2 u_texsize;
highp float u_tile_ratio;
highp float drawable_pad1;
highp float drawable_pad2;
};
layout (std140) uniform FillPatternTilePropsUBO {
highp vec4 u_pattern_from;
@@ -22,8 +31,8 @@ layout (std140) uniform FillEvaluatedPropsUBO {
highp vec4 u_outline_color;
highp float u_opacity;
highp float u_fade;
highp float u_width;
highp float props_pad1;
highp float u_from_scale;
highp float u_to_scale;
};
layout (location = 0) in vec2 a_pos;
@@ -45,10 +54,10 @@ void main() {
vec2 pattern_tl_b = pattern_to.xy;
vec2 pattern_br_b = pattern_to.zw;
float pixelRatio = u_scale.x;
float tileZoomRatio = u_scale.y;
float fromScale = u_scale.z;
float toScale = u_scale.w;
float pixelRatio = u_pixel_ratio;
float tileZoomRatio = u_tile_ratio;
float fromScale = u_from_scale;
float toScale = u_to_scale;
vec2 display_size_a = vec2((pattern_br_a.x - pattern_tl_a.x) / pixelRatio, (pattern_br_a.y - pattern_tl_a.y) / pixelRatio);
vec2 display_size_b = vec2((pattern_br_b.x - pattern_tl_b.x) / pixelRatio, (pattern_br_b.y - pattern_tl_b.y) / pixelRatio);

View File

@@ -4,9 +4,8 @@ uniform sampler2D u_color_ramp;
layout (std140) uniform HeatmapTexturePropsUBO {
highp mat4 u_matrix;
highp vec2 u_world;
highp float u_opacity;
lowp float props_pad1;
lowp float props_pad1, props_pad2, props_pad3;
};
void main() {

View File

@@ -1,15 +1,24 @@
layout (location = 0) in vec2 a_pos;
out vec2 v_pos;
layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform HeatmapTexturePropsUBO {
highp mat4 u_matrix;
highp vec2 u_world;
highp float u_opacity;
lowp float props_pad1;
lowp float props_pad1, props_pad2, props_pad3;
};
void main() {
gl_Position = u_matrix * vec4(a_pos * u_world, 0, 1);
gl_Position = u_matrix * vec4(a_pos * u_world_size, 0, 1);
v_pos.x = a_pos.x;
v_pos.y = 1.0 - a_pos.y;

View File

@@ -9,9 +9,15 @@
layout (location = 0) in vec2 a_pos_normal;
layout (location = 1) in vec4 a_data;
layout (std140) uniform LineDynamicUBO {
layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
lowp float dynamic_pad1, dynamic_pad2;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform LineDrawableUBO {

View File

@@ -13,9 +13,15 @@
layout (location = 0) in vec2 a_pos_normal;
layout (location = 1) in vec4 a_data;
layout (std140) uniform LineDynamicUBO {
layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
lowp float dynamic_pad1, dynamic_pad2;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform LineGradientDrawableUBO {

View File

@@ -13,9 +13,15 @@
layout (location = 0) in vec2 a_pos_normal;
layout (location = 1) in vec4 a_data;
layout (std140) uniform LineDynamicUBO {
layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
lowp float dynamic_pad1, dynamic_pad2;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform LinePatternDrawableUBO {

View File

@@ -13,9 +13,15 @@
layout (location = 0) in vec2 a_pos_normal;
layout (location = 1) in vec4 a_data;
layout (std140) uniform LineDynamicUBO {
layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
lowp float dynamic_pad1, dynamic_pad2;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform LineSDFDrawableUBO {

View File

@@ -4,11 +4,15 @@ 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;
layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float dynamic_pad1;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform SymbolDrawableUBO {
@@ -125,6 +129,6 @@ void main() {
v_tex = a_tex / u_texsize;
vec2 fade_opacity = unpack_opacity(a_fade_opacity);
float fade_change = fade_opacity[1] > 0.5 ? u_fade_change : -u_fade_change;
float fade_change = fade_opacity[1] > 0.5 ? u_symbol_fade_change : -u_symbol_fade_change;
v_fade_opacity = max(0.0, min(1.0, fade_opacity[0] + fade_change));
}

View File

@@ -1,12 +1,5 @@
#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;

View File

@@ -12,11 +12,15 @@ 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;
layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float dynamic_pad1;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform SymbolDrawableUBO {
@@ -151,7 +155,7 @@ void main() {
float gamma_scale = gl_Position.w;
vec2 fade_opacity = unpack_opacity(a_fade_opacity);
float fade_change = fade_opacity[1] > 0.5 ? u_fade_change : -u_fade_change;
float fade_change = fade_opacity[1] > 0.5 ? u_symbol_fade_change : -u_symbol_fade_change;
float interpolated_fade_opacity = max(0.0, min(1.0, fade_opacity[0] + fade_change));
v_data0 = a_tex / u_texsize;

View File

@@ -3,13 +3,6 @@
#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;

View File

@@ -11,11 +11,15 @@ 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;
layout (std140) uniform GlobalPaintParamsUBO {
highp vec2 u_pattern_atlas_texsize;
highp vec2 u_units_to_pixels;
highp vec2 u_world_size;
highp float u_camera_to_center_distance;
highp float u_symbol_fade_change;
highp float u_aspect_ratio;
highp float dynamic_pad1;
highp float u_pixel_ratio;
highp float global_pad1, global_pad2;
};
layout (std140) uniform SymbolDrawableUBO {
@@ -150,7 +154,7 @@ void main() {
float gamma_scale = gl_Position.w;
vec2 fade_opacity = unpack_opacity(a_fade_opacity);
float fade_change = fade_opacity[1] > 0.5 ? u_fade_change : -u_fade_change;
float fade_change = fade_opacity[1] > 0.5 ? u_symbol_fade_change : -u_symbol_fade_change;
float interpolated_fade_opacity = max(0.0, min(1.0, fade_opacity[0] + fade_change));
v_data0.xy = a_tex / u_texsize;

View File

@@ -486,6 +486,29 @@ bool Context::emplaceOrUpdateUniformBuffer(gfx::UniformBufferPtr& buffer,
return true;
}
}
void Context::bindGlobalUniformBuffers(gfx::RenderPass&) const noexcept {
for (size_t id = 0; id < globalUniformBuffers.allocatedSize(); id++) {
const auto& globalUniformBuffer = globalUniformBuffers.get(id);
if (!globalUniformBuffer) continue;
GLint binding = static_cast<GLint>(id);
const auto& uniformBufferGL = static_cast<const UniformBufferGL&>(*globalUniformBuffer);
MBGL_CHECK_ERROR(glBindBufferRange(GL_UNIFORM_BUFFER,
binding,
uniformBufferGL.getID(),
uniformBufferGL.getManagedBuffer().getBindingOffset(),
uniformBufferGL.getSize()));
}
}
void Context::unbindGlobalUniformBuffers(gfx::RenderPass&) const noexcept {
for (size_t id = 0; id < globalUniformBuffers.allocatedSize(); id++) {
const auto& globalUniformBuffer = globalUniformBuffers.get(id);
if (!globalUniformBuffer) continue;
GLint binding = static_cast<GLint>(id);
MBGL_CHECK_ERROR(glBindBufferBase(GL_UNIFORM_BUFFER, binding, 0));
}
}
#endif
void Context::setDirtyState() {

View File

@@ -19,6 +19,7 @@
#include <mbgl/gl/fence.hpp>
#include <mbgl/gl/buffer_allocator.hpp>
#include <mbgl/gfx/texture2d.hpp>
#include <mbgl/gl/uniform_buffer_gl.hpp>
#endif
#include <array>
@@ -134,6 +135,18 @@ public:
const void* data,
std::size_t size,
bool persistent) override;
/// Get the global uniform buffers
const gfx::UniformBufferArray& getGlobalUniformBuffers() const override { return globalUniformBuffers; };
/// Get the mutable global uniform buffer array
gfx::UniformBufferArray& mutableGlobalUniformBuffers() override { return globalUniformBuffers; };
/// Bind the global uniform buffers
void bindGlobalUniformBuffers(gfx::RenderPass&) const noexcept override;
/// Unbind the global uniform buffers
void unbindGlobalUniformBuffers(gfx::RenderPass&) const noexcept override;
#endif
void setDirtyState() override;
@@ -147,6 +160,7 @@ private:
std::shared_ptr<gl::Fence> frameInFlightFence;
std::unique_ptr<gl::UniformBufferAllocator> uboAllocator;
size_t frameNum = 0;
UniformBufferArrayGL globalUniformBuffers;
#endif
public:

View File

@@ -55,6 +55,10 @@ Context::~Context() noexcept {
clipMaskUniformsBuffer.reset();
stencilStateRenderable = nullptr;
for (size_t i = 0; i < globalUniformBuffers.allocatedSize(); i++) {
globalUniformBuffers.set(i, nullptr);
}
#if !defined(NDEBUG)
Log::Debug(Event::General, "Rendering Stats:\n" + stats.toString("\n"));
#endif
@@ -607,5 +611,17 @@ MTLDepthStencilStatePtr Context::makeDepthStencilState(const gfx::DepthMode& dep
return NS::TransferPtr(device->newDepthStencilState(depthStencilDescriptor.get()));
}
void Context::bindGlobalUniformBuffers(gfx::RenderPass& renderPass) const noexcept {
for (size_t id = 0; id < globalUniformBuffers.allocatedSize(); id++) {
const auto& globalUniformBuffer = globalUniformBuffers.get(id);
if (!globalUniformBuffer) continue;
const auto& buffer = static_cast<UniformBuffer&>(*globalUniformBuffer.get());
const auto& resource = buffer.getBufferResource();
auto& mtlRenderPass = static_cast<RenderPass&>(renderPass);
mtlRenderPass.bindVertex(resource, 0, id);
mtlRenderPass.bindFragment(resource, 0, id);
}
}
} // namespace mtl
} // namespace mbgl

View File

@@ -53,22 +53,16 @@ void BackgroundLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintPara
auto& layerUniforms = layerGroup.mutableUniformBuffers();
if (hasPattern) {
const Size atlasSize = parameters.patternAtlas.getPixelSize();
const BackgroundPatternLayerUBO layerUBO = {
/* .pattern_tl_a = */ util::cast<float>(imagePosA->tl()),
/* .pattern_br_a = */ util::cast<float>(imagePosA->br()),
/* .pattern_tl_b = */ util::cast<float>(imagePosB->tl()),
/* .pattern_br_b = */ util::cast<float>(imagePosB->br()),
/* .texsize = */ {static_cast<float>(atlasSize.width), static_cast<float>(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<BackgroundOpacity>(),
/* .pad1/2 = */ 0,
0};
const BackgroundPatternLayerUBO layerUBO = {/* .pattern_tl_a = */ util::cast<float>(imagePosA->tl()),
/* .pattern_br_a = */ util::cast<float>(imagePosA->br()),
/* .pattern_tl_b = */ util::cast<float>(imagePosB->tl()),
/* .pattern_br_b = */ util::cast<float>(imagePosB->br()),
/* .pattern_size_a = */ imagePosA->displaySize(),
/* .pattern_size_b = */ imagePosB->displaySize(),
/* .scale_a = */ crossfade.fromScale,
/* .scale_b = */ crossfade.toScale,
/* .mix = */ crossfade.t,
/* .opacity = */ evaluated.get<BackgroundOpacity>()};
layerUniforms.createOrUpdate(idBackgroundLayerUBO, &layerUBO, context);
} else {
const BackgroundLayerUBO layerUBO = {/* .color = */ evaluated.get<BackgroundColor>(),

View File

@@ -34,16 +34,6 @@ void CircleLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete
const auto debugGroup = parameters.encoder->createDebugGroup(label.c_str());
#endif
// Updated every frame, but shared across drawables
const CirclePaintParamsUBO paintParamsUBO = {
/* .camera_to_center_distance = */ parameters.state.getCameraToCenterDistance(),
/* .padding = */ 0,
0,
0};
auto& layerUniforms = layerGroup.mutableUniformBuffers();
layerUniforms.createOrUpdate(idCirclePaintParamsUBO, &paintParamsUBO, context);
const auto zoom = parameters.state.getZoom();
const bool pitchWithMap = evaluated.get<CirclePitchAlignment>() == AlignmentType::Map;
const bool scaleWithMap = evaluated.get<CirclePitchScale>() == CirclePitchScaleType::Map;
@@ -64,6 +54,7 @@ void CircleLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete
context.emplaceOrUpdateUniformBuffer(evaluatedPropsUniformBuffer, &evaluatedPropsUBO);
propertiesUpdated = false;
}
auto& layerUniforms = layerGroup.mutableUniformBuffers();
layerUniforms.set(idCircleEvaluatedPropsUBO, evaluatedPropsUniformBuffer);
visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) {

View File

@@ -61,8 +61,8 @@ void CollisionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParam
const CollisionUBO drawableUBO = {
/*.matrix=*/util::cast<float>(matrix),
/*.extrude_scale*/ extrudeScale,
/*.camera_to_center_distance*/ parameters.state.getCameraToCenterDistance(),
/*.overscale_factor*/ static_cast<float>(drawable.getTileID()->overscaleFactor())};
/*.overscale_factor*/ static_cast<float>(drawable.getTileID()->overscaleFactor()),
/*.pad*/ 0};
auto& drawableUniforms = drawable.mutableUniformBuffers();
drawableUniforms.createOrUpdate(idCollisionUBO, &drawableUBO, context);

View File

@@ -54,9 +54,9 @@ void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintP
/* .vertical_gradient = */ evaluated.get<FillExtrusionVerticalGradient>() ? 1.0f : 0.0f,
/* .opacity = */ evaluated.get<FillExtrusionOpacity>(),
/* .fade = */ crossfade.t,
/* .pad = */ 0,
0,
0};
/* .from_scale = */ crossfade.fromScale,
/* .to_scale = */ crossfade.toScale,
/* .pad = */ 0};
auto& layerUniforms = layerGroup.mutableUniformBuffers();
layerUniforms.createOrUpdate(idFillExtrusionPropsUBO, &propsUBO, context);
@@ -82,7 +82,6 @@ void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintP
const auto pixelX = static_cast<int32_t>(tileSizeAtNearestZoom *
(tileID.canonical.x + tileID.wrap * zoomScale));
const auto pixelY = static_cast<int32_t>(tileSizeAtNearestZoom * tileID.canonical.y);
const auto pixelRatio = parameters.pixelRatio;
const auto numTiles = std::pow(2, tileID.canonical.z);
const auto heightFactor = static_cast<float>(-numTiles / util::tileSize_D / 8.0);
@@ -93,12 +92,11 @@ void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintP
const FillExtrusionDrawableUBO drawableUBO = {
/* .matrix = */ util::cast<float>(matrix),
/* .scale = */ {pixelRatio, tileRatio, crossfade.fromScale, crossfade.toScale},
/* .texsize = */ {static_cast<float>(textureSize.width), static_cast<float>(textureSize.height)},
/* .pixel_coord_upper = */ {static_cast<float>(pixelX >> 16), static_cast<float>(pixelY >> 16)},
/* .pixel_coord_lower = */ {static_cast<float>(pixelX & 0xFFFF), static_cast<float>(pixelY & 0xFFFF)},
/* .height_factor = */ heightFactor,
/* .pad = */ 0};
/* .tile_ratio = */ tileRatio};
auto& drawableUniforms = drawable.mutableUniformBuffers();
drawableUniforms.createOrUpdate(idFillExtrusionDrawableUBO, &drawableUBO, context);

View File

@@ -46,8 +46,8 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters
/* .outline_color = */ evaluated.get<FillOutlineColor>().constantOr(FillOutlineColor::defaultValue()),
/* .opacity = */ evaluated.get<FillOpacity>().constantOr(FillOpacity::defaultValue()),
/* .fade = */ crossfade.t,
/* .width = */ 1.f,
0,
/* .from_scale = */ crossfade.fromScale,
/* .to_scale = */ crossfade.toScale,
};
context.emplaceOrUpdateUniformBuffer(evaluatedPropsUniformBuffer, &propsUBO);
propertiesUpdated = false;
@@ -57,10 +57,7 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters
const auto& translation = evaluated.get<FillTranslate>();
const auto anchor = evaluated.get<FillTranslateAnchor>();
const auto renderableSize = parameters.backend.getDefaultRenderable().getSize();
const auto intZoom = parameters.state.getIntegerZoom();
const auto pixelRatio = parameters.pixelRatio;
visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) {
if (!drawable.getTileID() || !checkTweakDrawable(drawable)) {
@@ -97,22 +94,17 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters
break;
}
case RenderFillLayer::FillVariant::FillOutline: {
const FillOutlineDrawableUBO drawableUBO = {
/*.matrix=*/util::cast<float>(matrix),
/*.world=*/{(float)renderableSize.width, (float)renderableSize.height},
/* pad1 */ 0,
/* pad2 */ 0};
const FillOutlineDrawableUBO drawableUBO = {/*.matrix=*/util::cast<float>(matrix)};
drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context);
break;
}
case RenderFillLayer::FillVariant::FillPattern: {
const FillPatternDrawableUBO drawableUBO = {
/*.matrix=*/util::cast<float>(matrix),
/*.scale=*/{pixelRatio, tileRatio, crossfade.fromScale, crossfade.toScale},
/*.pixel_coord_upper=*/{static_cast<float>(pixelX >> 16), static_cast<float>(pixelY >> 16)},
/*.pixel_coord_lower=*/{static_cast<float>(pixelX & 0xFFFF), static_cast<float>(pixelY & 0xFFFF)},
/*.texsize=*/{static_cast<float>(textureSize.width), static_cast<float>(textureSize.height)},
0,
/*.tile_ratio = */ tileRatio,
0,
};
drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context);
@@ -121,20 +113,20 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters
case RenderFillLayer::FillVariant::FillOutlinePattern: {
const FillOutlinePatternDrawableUBO drawableUBO = {
/*.matrix=*/util::cast<float>(matrix),
/*.scale=*/{pixelRatio, tileRatio, crossfade.fromScale, crossfade.toScale},
/*.world=*/{(float)renderableSize.width, (float)renderableSize.height},
/*.pixel_coord_upper=*/{static_cast<float>(pixelX >> 16), static_cast<float>(pixelY >> 16)},
/*.pixel_coord_lower=*/{static_cast<float>(pixelX & 0xFFFF), static_cast<float>(pixelY & 0xFFFF)},
/*.texsize=*/{static_cast<float>(textureSize.width), static_cast<float>(textureSize.height)},
};
/*.tile_ratio = */ tileRatio,
0};
drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context);
break;
}
case RenderFillLayer::FillVariant::FillOutlineTriangulated: {
const FillOutlineTriangulatedDrawableUBO drawableUBO = {
/*.matrix=*/util::cast<float>(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,
0,
0};
drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context);
break;

View File

@@ -29,15 +29,15 @@ void HeatmapTextureLayerTweaker::execute(LayerGroupBase& layerGroup, const Paint
propertiesUpdated = false;
mat4 matrix;
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<float>(viewportMat),
/* .world = */ {static_cast<float>(size.width), static_cast<float>(size.height)},
/* .opacity = */ evaluated.get<HeatmapOpacity>(),
/* .pad1 = */ 0,
};
matrix::ortho(matrix, 0, size.width, size.height, 0, -1, 1);
const HeatmapTexturePropsUBO propsUBO = {/* .matrix = */ util::cast<float>(matrix),
/* .opacity = */ evaluated.get<HeatmapOpacity>(),
/* .pad1,2,3 = */ 0,
0,
0};
auto& layerUniforms = layerGroup.mutableUniformBuffers();
layerUniforms.createOrUpdate(idHeatmapTexturePropsUBO, &propsUBO, parameters.context);
}

Some files were not shown because too many files have changed in this diff Show More