Custom drawable layer v3 (#3210)

This commit is contained in:
Adrian Cojocaru
2025-02-28 23:49:20 +02:00
committed by GitHub
parent b09235b41e
commit 7339fb91fd
90 changed files with 3930 additions and 462 deletions

View File

@@ -1035,6 +1035,7 @@ if(MLN_WITH_OPENGL)
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_circle.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_collision_box.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_collision_circle.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_custom_geometry.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_custom_symbol_icon.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_debug.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_fill.hpp
@@ -1217,6 +1218,7 @@ if(MLN_WITH_METAL)
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/clipping_mask.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/common.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/collision.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/custom_geometry.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/custom_symbol_icon.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/debug.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/fill.hpp
@@ -1226,6 +1228,7 @@ if(MLN_WITH_METAL)
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/hillshade.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/hillshade_prepare.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/line.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/location_indicator.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/raster.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/shader_group.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/shader_program.hpp
@@ -1256,6 +1259,7 @@ if(MLN_WITH_METAL)
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/circle.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/collision.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/clipping_mask.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/custom_geometry.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/custom_symbol_icon.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/debug.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/fill.cpp
@@ -1265,6 +1269,7 @@ if(MLN_WITH_METAL)
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/hillshade.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/hillshade_prepare.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/line.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/location_indicator.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/raster.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/symbol.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/widevector.cpp
@@ -1314,6 +1319,7 @@ if(MLN_WITH_VULKAN)
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/clipping_mask.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/collision.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/common.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/custom_geometry.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/custom_symbol_icon.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/fill.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/fill_extrusion.hpp
@@ -1354,6 +1360,7 @@ if(MLN_WITH_VULKAN)
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/circle.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/clipping_mask.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/collision.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/custom_geometry.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/custom_symbol_icon.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/debug.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/fill.cpp

View File

@@ -54,6 +54,14 @@ http_archive(
urls = ["https://github.com/glfw/glfw/releases/download/3.4/glfw-3.4.zip"],
)
new_git_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository")
new_git_repository(
name = "tinyobjloader",
remote = "https://github.com/tinyobjloader/tinyobjloader.git",
branch = "release",
)
darwin_config = use_repo_rule("//platform/darwin:bazel/darwin_config_repository_rule.bzl", "darwin_config")
darwin_config(

View File

@@ -67,6 +67,7 @@ MLN_GENERATED_OPENGL_SHADER_HEADERS = [
"include/mbgl/shaders/gl/drawable_circle.hpp",
"include/mbgl/shaders/gl/drawable_collision_box.hpp",
"include/mbgl/shaders/gl/drawable_collision_circle.hpp",
"include/mbgl/shaders/gl/drawable_custom_geometry.hpp",
"include/mbgl/shaders/gl/drawable_custom_symbol_icon.hpp",
"include/mbgl/shaders/gl/drawable_debug.hpp",
"include/mbgl/shaders/gl/drawable_fill.hpp",
@@ -1010,6 +1011,7 @@ MLN_DRAWABLES_HEADERS = [
"include/mbgl/shaders/background_layer_ubo.hpp",
"include/mbgl/shaders/circle_layer_ubo.hpp",
"include/mbgl/shaders/collision_layer_ubo.hpp",
"include/mbgl/shaders/custom_geometry_ubo.hpp",
"include/mbgl/shaders/custom_drawable_layer_ubo.hpp",
"include/mbgl/shaders/debug_layer_ubo.hpp",
"include/mbgl/shaders/fill_layer_ubo.hpp",
@@ -1081,6 +1083,7 @@ MLN_DRAWABLES_MTL_SOURCE = [
"src/mbgl/shaders/mtl/circle.cpp",
"src/mbgl/shaders/mtl/collision.cpp",
"src/mbgl/shaders/mtl/clipping_mask.cpp",
"src/mbgl/shaders/mtl/custom_geometry.cpp",
"src/mbgl/shaders/mtl/custom_symbol_icon.cpp",
"src/mbgl/shaders/mtl/debug.cpp",
"src/mbgl/shaders/mtl/fill.cpp",
@@ -1090,6 +1093,7 @@ MLN_DRAWABLES_MTL_SOURCE = [
"src/mbgl/shaders/mtl/hillshade.cpp",
"src/mbgl/shaders/mtl/hillshade_prepare.cpp",
"src/mbgl/shaders/mtl/line.cpp",
"src/mbgl/shaders/mtl/location_indicator.cpp",
"src/mbgl/shaders/mtl/raster.cpp",
"src/mbgl/shaders/mtl/symbol.cpp",
"src/mbgl/shaders/mtl/widevector.cpp",
@@ -1120,6 +1124,7 @@ MLN_DRAWABLES_MTL_HEADERS = [
"include/mbgl/shaders/mtl/clipping_mask.hpp",
"include/mbgl/shaders/mtl/collision.hpp",
"include/mbgl/shaders/mtl/common.hpp",
"include/mbgl/shaders/mtl/custom_geometry.hpp",
"include/mbgl/shaders/mtl/custom_symbol_icon.hpp",
"include/mbgl/shaders/mtl/debug.hpp",
"include/mbgl/shaders/mtl/fill.hpp",
@@ -1129,6 +1134,7 @@ MLN_DRAWABLES_MTL_HEADERS = [
"include/mbgl/shaders/mtl/hillshade.hpp",
"include/mbgl/shaders/mtl/hillshade_prepare.hpp",
"include/mbgl/shaders/mtl/line.hpp",
"include/mbgl/shaders/mtl/location_indicator.hpp",
"include/mbgl/shaders/mtl/raster.hpp",
"include/mbgl/shaders/mtl/shader_group.hpp",
"include/mbgl/shaders/mtl/shader_program.hpp",

View File

@@ -130,6 +130,8 @@ public:
bool persistent = false,
bool ssbo = false) = 0;
virtual UniqueUniformBufferArray createLayerUniformBufferArray() = 0;
/// Get the generic shader with the specified name
virtual gfx::ShaderProgramBasePtr getGenericShader(gfx::ShaderRegistry&, const std::string& name) = 0;

View File

@@ -12,6 +12,7 @@ namespace gfx {
class Context;
class UniformBuffer;
class UniformBufferArray;
class RenderPass;
using UniformBufferPtr = std::shared_ptr<UniformBuffer>;
using UniqueUniformBuffer = std::unique_ptr<UniformBuffer>;
@@ -75,6 +76,8 @@ public:
createOrUpdate(id, data, sizeof(T), context, persistent);
}
virtual void bind(gfx::RenderPass& renderPass) = 0;
UniformBufferArray& operator=(UniformBufferArray&&);
UniformBufferArray& operator=(const UniformBufferArray&);

View File

@@ -62,6 +62,8 @@ public:
void bind() const;
void unbind() const;
void bind(gfx::RenderPass&) override { bind(); }
private:
std::unique_ptr<gfx::UniformBuffer> copy(const gfx::UniformBuffer& uniformBuffers) override {
return std::make_unique<UniformBufferGL>(static_cast<const UniformBufferGL&>(uniformBuffers).clone());

View File

@@ -41,6 +41,7 @@ class VertexBufferResource;
using UniqueShaderProgram = std::unique_ptr<ShaderProgram>;
using UniqueVertexBufferResource = std::unique_ptr<VertexBufferResource>;
using UniqueUniformBufferArray = std::unique_ptr<gfx::UniformBufferArray>;
class Context final : public gfx::Context {
public:
@@ -88,6 +89,8 @@ public:
bool persistent = false,
bool ssbo = false) override;
UniqueUniformBufferArray createLayerUniformBufferArray() override;
gfx::ShaderProgramBasePtr getGenericShader(gfx::ShaderRegistry&, const std::string& name) override;
TileLayerGroupPtr createTileLayerGroup(int32_t layerIndex, std::size_t initialCapacity, std::string name) override;

View File

@@ -8,7 +8,6 @@ namespace mtl {
class IndexBufferResource : public gfx::IndexBufferResource {
public:
IndexBufferResource() noexcept = delete;
IndexBufferResource(BufferResource&&) noexcept;
IndexBufferResource(IndexBufferResource&& other) noexcept
: buffer(std::move(other.buffer)) {}

View File

@@ -42,8 +42,8 @@ public:
return *this;
}
void bind(RenderPass& renderPass) const noexcept;
void unbind(RenderPass&) const noexcept {}
void bindMtl(RenderPass&) const noexcept;
void bind(gfx::RenderPass& renderPass) override;
private:
gfx::UniqueUniformBuffer copy(const gfx::UniformBuffer& buffer) override {

View File

@@ -10,7 +10,6 @@ namespace mtl {
class VertexBufferResource : public gfx::VertexBufferResource {
public:
VertexBufferResource() noexcept = delete;
VertexBufferResource(BufferResource&&) noexcept;
VertexBufferResource(VertexBufferResource&& other) noexcept
: buffer(std::move(other.buffer)) {}

View File

@@ -0,0 +1,16 @@
#pragma once
#include <mbgl/shaders/layer_ubo.hpp>
namespace mbgl {
namespace shaders {
struct alignas(16) CustomGeometryDrawableUBO {
/* 0 */ std::array<float, 4 * 4> matrix;
/* 64 */ Color color;
/* 80 */
};
static_assert(sizeof(CustomGeometryDrawableUBO) == 5 * 16);
} // namespace shaders
} // namespace mbgl

View File

@@ -0,0 +1,39 @@
// Generated code, do not modify this file!
#pragma once
#include <mbgl/shaders/shader_source.hpp>
namespace mbgl {
namespace shaders {
template <>
struct ShaderSource<BuiltIn::CustomGeometryShader, gfx::Backend::Type::OpenGL> {
static constexpr const char* name = "CustomGeometryShader";
static constexpr const char* vertex = R"(layout (std140) uniform CustomGeometryDrawableUBO {
mat4 u_matrix;
vec4 u_color;
};
layout(location = 0) in vec3 a_pos;
layout(location = 1) in vec2 a_uv;
out vec2 frag_uv;
void main() {
frag_uv = a_uv;
gl_Position = u_matrix * vec4(a_pos, 1.0);
})";
static constexpr const char* fragment = R"(layout (std140) uniform CustomGeometryDrawableUBO {
mat4 u_matrix;
vec4 u_color;
};
in vec2 frag_uv;
uniform sampler2D u_image;
void main() {
fragColor = texture(u_image, frag_uv) * u_color;
})";
};
} // namespace shaders
} // namespace mbgl

View File

@@ -8,8 +8,24 @@ namespace shaders {
template <>
struct ShaderSource<BuiltIn::LocationIndicatorShader, gfx::Backend::Type::OpenGL> {
static constexpr const char* name = "LocationIndicatorShader";
static constexpr const char* vertex = R"()";
static constexpr const char* fragment = R"()";
static constexpr const char* vertex = R"(layout (std140) uniform LocationIndicatorDrawableUBO {
mat4 u_matrix;
vec4 u_color;
};
layout(location = 0) in vec2 a_pos;
void main() {
gl_Position = u_matrix * vec4(a_pos, 0.0, 1.0);
})";
static constexpr const char* fragment = R"(layout (std140) uniform LocationIndicatorDrawableUBO {
mat4 u_matrix;
vec4 u_color;
};
void main() {
fragColor = u_color;
})";
};
} // namespace shaders

View File

@@ -8,8 +8,31 @@ namespace shaders {
template <>
struct ShaderSource<BuiltIn::LocationIndicatorTexturedShader, gfx::Backend::Type::OpenGL> {
static constexpr const char* name = "LocationIndicatorTexturedShader";
static constexpr const char* vertex = R"()";
static constexpr const char* fragment = R"()";
static constexpr const char* vertex = R"(layout (std140) uniform LocationIndicatorDrawableUBO {
mat4 u_matrix;
vec4 u_color;
};
layout(location = 0) in vec2 a_pos;
layout(location = 1) in vec2 a_uv;
out vec2 frag_uv;
void main() {
frag_uv = a_uv;
gl_Position = u_matrix * vec4(a_pos, 0.0, 1.0);
})";
static constexpr const char* fragment = R"(layout (std140) uniform LocationIndicatorDrawableUBO {
mat4 u_matrix;
vec4 u_color;
};
in vec2 frag_uv;
uniform sampler2D u_image;
void main() {
fragColor = texture(u_image, frag_uv);
})";
};
} // namespace shaders

View File

@@ -65,6 +65,13 @@ struct ShaderInfo<BuiltIn::CollisionCircleShader, gfx::Backend::Type::OpenGL> {
static const std::vector<TextureInfo> textures;
};
template <>
struct ShaderInfo<BuiltIn::CustomGeometryShader, gfx::Backend::Type::OpenGL> {
static const std::vector<AttributeInfo> attributes;
static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
};
template <>
struct ShaderInfo<BuiltIn::CustomSymbolIconShader, gfx::Backend::Type::OpenGL> {
static const std::vector<AttributeInfo> attributes;
@@ -184,6 +191,20 @@ struct ShaderInfo<BuiltIn::LineShader, gfx::Backend::Type::OpenGL> {
static const std::vector<TextureInfo> textures;
};
template <>
struct ShaderInfo<BuiltIn::LocationIndicatorShader, gfx::Backend::Type::OpenGL> {
static const std::vector<AttributeInfo> attributes;
static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
};
template <>
struct ShaderInfo<BuiltIn::LocationIndicatorTexturedShader, gfx::Backend::Type::OpenGL> {
static const std::vector<AttributeInfo> attributes;
static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
};
template <>
struct ShaderInfo<BuiltIn::RasterShader, gfx::Backend::Type::OpenGL> {
static const std::vector<AttributeInfo> attributes;

View File

@@ -0,0 +1,70 @@
#pragma once
#include <mbgl/shaders/custom_geometry_ubo.hpp>
#include <mbgl/shaders/shader_source.hpp>
#include <mbgl/shaders/mtl/shader_program.hpp>
namespace mbgl {
namespace shaders {
constexpr auto customGeometryShaderPrelude = R"(
enum {
idCustomGeometryDrawableUBO = drawableReservedUBOCount,
customGeometryUBOCount
};
struct alignas(16) CustomGeometryDrawableUBO {
/* 0 */ float4x4 matrix;
/* 64 */ float4 color;
/* 80 */
};
static_assert(sizeof(CustomGeometryDrawableUBO) == 5 * 16, "wrong size");
)";
template <>
struct ShaderSource<BuiltIn::CustomGeometryShader, gfx::Backend::Type::Metal> {
static constexpr auto name = "CustomGeometryShader";
static constexpr auto vertexMainFunction = "vertexMain";
static constexpr auto fragmentMainFunction = "fragmentMain";
static const std::array<AttributeInfo, 2> attributes;
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 1> textures;
static constexpr auto prelude = customGeometryShaderPrelude;
static constexpr auto source = R"(
struct VertexStage {
float3 position [[attribute(customGeometryUBOCount + 0)]];
float2 uv [[attribute(customGeometryUBOCount + 1)]];
};
struct FragmentStage {
float4 position [[position, invariant]];
float2 uv;
};
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
device const CustomGeometryDrawableUBO& drawable [[buffer(idCustomGeometryDrawableUBO)]]) {
return {
.position = drawable.matrix * float4(vertx.position, 1.0),
.uv = vertx.uv
};
}
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
device const CustomGeometryDrawableUBO& drawable [[buffer(idCustomGeometryDrawableUBO)]],
texture2d<float, access::sample> colorTexture [[texture(0)]]) {
constexpr sampler sampler2d(coord::normalized, filter::linear);
const float4 color = colorTexture.sample(sampler2d, in.uv) * drawable.color;
return half4(color);
}
)";
};
} // namespace shaders
} // namespace mbgl

View File

@@ -0,0 +1,107 @@
#pragma once
#include <mbgl/shaders/location_indicator_ubo.hpp>
#include <mbgl/shaders/shader_source.hpp>
#include <mbgl/shaders/mtl/shader_program.hpp>
namespace mbgl {
namespace shaders {
constexpr auto locationIndicatorShaderPrelude = R"(
enum {
idLocationIndicatorUBO = drawableReservedUBOCount,
locationIndicatorUBOCount
};
struct alignas(16) LocationIndicatorDrawableUBO {
/* 0 */ float4x4 matrix;
/* 64 */ float4 color;
/* 80 */
};
static_assert(sizeof(LocationIndicatorDrawableUBO) == 5 * 16, "wrong size");
)";
template <>
struct ShaderSource<BuiltIn::LocationIndicatorShader, gfx::Backend::Type::Metal> {
static constexpr auto name = "LocationIndicatorShader";
static constexpr auto vertexMainFunction = "vertexMain";
static constexpr auto fragmentMainFunction = "fragmentMain";
static const std::array<AttributeInfo, 1> attributes;
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static constexpr std::array<TextureInfo, 0> textures{};
static constexpr auto prelude = locationIndicatorShaderPrelude;
static constexpr auto source = R"(
struct VertexStage {
float2 position [[attribute(locationIndicatorUBOCount + 0)]];
};
struct FragmentStage {
float4 position [[position, invariant]];
};
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
device const LocationIndicatorDrawableUBO& drawable [[buffer(idLocationIndicatorUBO)]]) {
return {
.position = drawable.matrix * float4(vertx.position, 1.0)
};
}
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
device const LocationIndicatorDrawableUBO& drawable [[buffer(idLocationIndicatorUBO)]]) {
return half4(drawable.color);
}
)";
};
template <>
struct ShaderSource<BuiltIn::LocationIndicatorTexturedShader, gfx::Backend::Type::Metal> {
static constexpr auto name = "LocationIndicatorTexturedShader";
static constexpr auto vertexMainFunction = "vertexMain";
static constexpr auto fragmentMainFunction = "fragmentMain";
static const std::array<AttributeInfo, 2> attributes;
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 1> textures;
static constexpr auto prelude = locationIndicatorShaderPrelude;
static constexpr auto source = R"(
struct VertexStage {
float2 position [[attribute(locationIndicatorUBOCount + 0)]];
float2 uv [[attribute(locationIndicatorUBOCount + 1)]];
};
struct FragmentStage {
float4 position [[position, invariant]];
float2 uv;
};
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
device const LocationIndicatorDrawableUBO& drawable [[buffer(idLocationIndicatorUBO)]]) {
return {
.position = drawable.matrix * float4(vertx.position, 1.0),
.uv = vertx.uv
};
}
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
device const LocationIndicatorDrawableUBO& drawable [[buffer(idLocationIndicatorUBO)]],
texture2d<float, access::sample> colorTexture [[texture(0)]]) {
constexpr sampler sampler2d(coord::normalized, filter::linear);
const float4 color = colorTexture.sample(sampler2d, in.uv);
return half4(color);
}
)";
};
} // namespace shaders
} // namespace mbgl

View File

@@ -30,6 +30,11 @@ enum {
collisionDrawableUBOCount
};
enum {
idCustomGeometryDrawableUBO = drawableReservedUBOCount,
customGeometryDrawableUBOCount
};
enum {
idCustomSymbolDrawableUBO = idDrawableReservedVertexOnlyUBO,
customSymbolDrawableUBOCount = drawableReservedUBOCount
@@ -101,26 +106,27 @@ enum {
wideVectorDrawableUBOCount
};
static constexpr auto layerSSBOStartId = globalUBOCount;
static constexpr auto layerUBOStartId = std::max({static_cast<size_t>(backgroundDrawableUBOCount),
static_cast<size_t>(circleDrawableUBOCount),
static_cast<size_t>(clippingMaskDrawableUBOCount),
static_cast<size_t>(collisionDrawableUBOCount),
static_cast<size_t>(customSymbolDrawableUBOCount),
static_cast<size_t>(debugDrawableUBOCount),
static_cast<size_t>(fillDrawableUBOCount),
static_cast<size_t>(fillExtrusionDrawableUBOCount),
static_cast<size_t>(heatmapDrawableUBOCount),
static_cast<size_t>(heatmapTextureDrawableUBOCount),
static_cast<size_t>(hillshadeDrawableUBOCount),
static_cast<size_t>(hillshadePrepareDrawableUBOCount),
static_cast<size_t>(lineDrawableUBOCount),
static_cast<size_t>(locationIndicatorDrawableUBOCount),
static_cast<size_t>(rasterDrawableUBOCount),
static_cast<size_t>(symbolDrawableUBOCount),
static_cast<size_t>(wideVectorDrawableUBOCount)});
static constexpr uint32_t layerSSBOStartId = globalUBOCount;
static constexpr uint32_t layerUBOStartId = std::max({static_cast<uint32_t>(backgroundDrawableUBOCount),
static_cast<uint32_t>(circleDrawableUBOCount),
static_cast<uint32_t>(clippingMaskDrawableUBOCount),
static_cast<uint32_t>(collisionDrawableUBOCount),
static_cast<uint32_t>(customGeometryDrawableUBOCount),
static_cast<uint32_t>(customSymbolDrawableUBOCount),
static_cast<uint32_t>(debugDrawableUBOCount),
static_cast<uint32_t>(fillDrawableUBOCount),
static_cast<uint32_t>(fillExtrusionDrawableUBOCount),
static_cast<uint32_t>(heatmapDrawableUBOCount),
static_cast<uint32_t>(heatmapTextureDrawableUBOCount),
static_cast<uint32_t>(hillshadeDrawableUBOCount),
static_cast<uint32_t>(hillshadePrepareDrawableUBOCount),
static_cast<uint32_t>(lineDrawableUBOCount),
static_cast<uint32_t>(locationIndicatorDrawableUBOCount),
static_cast<uint32_t>(rasterDrawableUBOCount),
static_cast<uint32_t>(symbolDrawableUBOCount),
static_cast<uint32_t>(wideVectorDrawableUBOCount)});
static constexpr auto maxUBOCountPerDrawable = layerUBOStartId - globalUBOCount;
static constexpr uint32_t maxUBOCountPerDrawable = layerUBOStartId - globalUBOCount;
// layer UBOs
@@ -148,6 +154,10 @@ enum {
collisionUBOCount = getLayerStartValue(collisionDrawableUBOCount)
};
enum {
customGeometryUBOCount = getLayerStartValue(customGeometryDrawableUBOCount)
};
enum {
customSymbolUBOCount = getLayerStartValue(customSymbolDrawableUBOCount)
};
@@ -211,26 +221,26 @@ enum {
#undef getLayerStartValue
static constexpr auto maxUBOCountPerShader = std::max({static_cast<size_t>(backgroundUBOCount),
static_cast<size_t>(circleUBOCount),
static_cast<size_t>(clippingMaskUBOCount),
static_cast<size_t>(collisionUBOCount),
static_cast<size_t>(customSymbolUBOCount),
static_cast<size_t>(debugUBOCount),
static_cast<size_t>(fillUBOCount),
static_cast<size_t>(fillExtrusionUBOCount),
static_cast<size_t>(heatmapUBOCount),
static_cast<size_t>(heatmapTextureUBOCount),
static_cast<size_t>(hillshadeUBOCount),
static_cast<size_t>(hillshadePrepareUBOCount),
static_cast<size_t>(lineUBOCount),
static_cast<size_t>(locationIndicatorUBOCount),
static_cast<size_t>(rasterUBOCount),
static_cast<size_t>(symbolUBOCount),
static_cast<size_t>(wideVectorUBOCount)});
static constexpr uint32_t maxUBOCountPerShader = std::max({static_cast<uint32_t>(backgroundUBOCount),
static_cast<uint32_t>(circleUBOCount),
static_cast<uint32_t>(clippingMaskUBOCount),
static_cast<uint32_t>(collisionUBOCount),
static_cast<uint32_t>(customSymbolUBOCount),
static_cast<uint32_t>(debugUBOCount),
static_cast<uint32_t>(fillUBOCount),
static_cast<uint32_t>(fillExtrusionUBOCount),
static_cast<uint32_t>(heatmapUBOCount),
static_cast<uint32_t>(heatmapTextureUBOCount),
static_cast<uint32_t>(hillshadeUBOCount),
static_cast<uint32_t>(hillshadePrepareUBOCount),
static_cast<uint32_t>(lineUBOCount),
static_cast<uint32_t>(locationIndicatorUBOCount),
static_cast<uint32_t>(rasterUBOCount),
static_cast<uint32_t>(symbolUBOCount),
static_cast<uint32_t>(wideVectorUBOCount)});
static constexpr auto maxSSBOCountPerLayer = maxUBOCountPerDrawable;
static constexpr auto maxUBOCountPerLayer = maxUBOCountPerShader - layerUBOStartId;
static constexpr uint32_t maxSSBOCountPerLayer = maxUBOCountPerDrawable;
static constexpr uint32_t maxUBOCountPerLayer = maxUBOCountPerShader - layerUBOStartId;
// Texture defines
enum {
@@ -251,8 +261,8 @@ enum {
};
enum {
idCommonTexture,
commonTextureCount
idCustomGeometryTexture,
customGeometryTextureCount
};
enum {
@@ -286,6 +296,11 @@ enum {
hillshadeTextureCount
};
enum {
idLocationIndicatorTexture,
locationIndicatorTextureCount
};
enum {
idLineImageTexture,
lineTextureCount
@@ -303,20 +318,21 @@ enum {
symbolTextureCount
};
static constexpr auto maxTextureCountPerShader = std::max({static_cast<size_t>(backgroundTextureCount),
static_cast<size_t>(circleTextureCount),
static_cast<size_t>(clippingMaskTextureCount),
static_cast<size_t>(collisionTextureCount),
static_cast<size_t>(commonTextureCount),
static_cast<size_t>(customSymbolTextureCount),
static_cast<size_t>(debugTextureCount),
static_cast<size_t>(fillTextureCount),
static_cast<size_t>(fillExtrusionTextureCount),
static_cast<size_t>(heatmapTextureCount),
static_cast<size_t>(hillshadeTextureCount),
static_cast<size_t>(lineTextureCount),
static_cast<size_t>(rasterTextureCount),
static_cast<size_t>(symbolTextureCount)});
static constexpr uint32_t maxTextureCountPerShader = std::max({static_cast<uint32_t>(backgroundTextureCount),
static_cast<uint32_t>(circleTextureCount),
static_cast<uint32_t>(clippingMaskTextureCount),
static_cast<uint32_t>(collisionTextureCount),
static_cast<uint32_t>(customGeometryTextureCount),
static_cast<uint32_t>(customSymbolTextureCount),
static_cast<uint32_t>(debugTextureCount),
static_cast<uint32_t>(fillTextureCount),
static_cast<uint32_t>(fillExtrusionTextureCount),
static_cast<uint32_t>(heatmapTextureCount),
static_cast<uint32_t>(hillshadeTextureCount),
static_cast<uint32_t>(lineTextureCount),
static_cast<uint32_t>(locationIndicatorTextureCount),
static_cast<uint32_t>(rasterTextureCount),
static_cast<uint32_t>(symbolTextureCount)});
// Vertex attribute defines
enum {
@@ -354,9 +370,9 @@ enum {
};
enum {
idCommonPosVertexAttribute,
idCommonTexVertexAttribute,
commonVertexAttributeCount
idCustomGeometryPosVertexAttribute,
idCustomGeometryTexVertexAttribute,
customGeometryVertexAttributeCount
};
enum {
@@ -431,6 +447,12 @@ enum {
lineVertexAttributeCount
};
enum {
idLocationIndicatorPosVertexAttribute,
idLocationIndicatorTexVertexAttribute,
locationIndicatorVertexAttributeCount
};
enum {
idRasterPosVertexAttribute,
idRasterTexturePosVertexAttribute,
@@ -471,23 +493,24 @@ enum {
wideVectorInstanceAttributeCount
};
static constexpr auto maxVertexAttributeCountPerShader = std::max({
static_cast<size_t>(backgroundVertexAttributeCount),
static_cast<size_t>(circleVertexAttributeCount),
static_cast<size_t>(clippingMaskVertexAttributeCount),
static_cast<size_t>(collisionVertexAttributeCount),
static_cast<size_t>(commonVertexAttributeCount),
static_cast<size_t>(customSymbolVertexAttributeCount),
static_cast<size_t>(debugVertexAttributeCount),
static_cast<size_t>(fillVertexAttributeCount),
static_cast<size_t>(fillExtrusionVertexAttributeCount),
static_cast<size_t>(heatmapVertexAttributeCount),
static_cast<size_t>(hillshadeVertexAttributeCount),
static_cast<size_t>(lineVertexAttributeCount),
static_cast<size_t>(rasterVertexAttributeCount),
static_cast<size_t>(symbolVertexAttributeCount),
static_cast<size_t>(wideVectorAttributeCount),
static_cast<size_t>(wideVectorInstanceAttributeCount),
static constexpr uint32_t maxVertexAttributeCountPerShader = std::max({
static_cast<uint32_t>(backgroundVertexAttributeCount),
static_cast<uint32_t>(circleVertexAttributeCount),
static_cast<uint32_t>(clippingMaskVertexAttributeCount),
static_cast<uint32_t>(collisionVertexAttributeCount),
static_cast<uint32_t>(customGeometryVertexAttributeCount),
static_cast<uint32_t>(customSymbolVertexAttributeCount),
static_cast<uint32_t>(debugVertexAttributeCount),
static_cast<uint32_t>(fillVertexAttributeCount),
static_cast<uint32_t>(fillExtrusionVertexAttributeCount),
static_cast<uint32_t>(heatmapVertexAttributeCount),
static_cast<uint32_t>(hillshadeVertexAttributeCount),
static_cast<uint32_t>(lineVertexAttributeCount),
static_cast<uint32_t>(locationIndicatorVertexAttributeCount),
static_cast<uint32_t>(rasterVertexAttributeCount),
static_cast<uint32_t>(symbolVertexAttributeCount),
static_cast<uint32_t>(wideVectorAttributeCount),
static_cast<uint32_t>(wideVectorInstanceAttributeCount),
});
} // namespace shaders

View File

@@ -8,6 +8,7 @@
#include <mbgl/shaders/gl/drawable_circle.hpp>
#include <mbgl/shaders/gl/drawable_collision_box.hpp>
#include <mbgl/shaders/gl/drawable_collision_circle.hpp>
#include <mbgl/shaders/gl/drawable_custom_geometry.hpp>
#include <mbgl/shaders/gl/drawable_custom_symbol_icon.hpp>
#include <mbgl/shaders/gl/drawable_debug.hpp>
#include <mbgl/shaders/gl/drawable_fill.hpp>

View File

@@ -14,6 +14,7 @@ enum class BuiltIn {
CircleShader,
CollisionBoxShader,
CollisionCircleShader,
CustomGeometryShader,
CustomSymbolIconShader,
DebugShader,
FillShader,

View File

@@ -6,13 +6,12 @@
namespace mbgl {
namespace shaders {
#define BACKGROUND_SHADER_COMMON \
R"(
constexpr auto backgroundShaderPrelude = R"(
#define idBackgroundDrawableUBO idDrawableReservedVertexOnlyUBO
#define idBackgroundPropsUBO layerUBOStartId
)"
)";
template <>
struct ShaderSource<BuiltIn::BackgroundShader, gfx::Backend::Type::Vulkan> {
@@ -22,7 +21,8 @@ struct ShaderSource<BuiltIn::BackgroundShader, gfx::Backend::Type::Vulkan> {
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 0> textures;
static constexpr auto vertex = BACKGROUND_SHADER_COMMON R"(
static constexpr auto prelude = backgroundShaderPrelude;
static constexpr auto vertex = R"(
layout(location = 0) in ivec2 in_position;
@@ -48,7 +48,7 @@ void main() {
}
)";
static constexpr auto fragment = BACKGROUND_SHADER_COMMON R"(
static constexpr auto fragment = R"(
layout(location = 0) out vec4 out_color;
layout(set = LAYER_SET_INDEX, binding = idBackgroundPropsUBO) uniform BackgroundPropsUBO {
@@ -79,7 +79,8 @@ struct ShaderSource<BuiltIn::BackgroundPatternShader, gfx::Backend::Type::Vulkan
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 1> textures;
static constexpr auto vertex = BACKGROUND_SHADER_COMMON R"(
static constexpr auto prelude = backgroundShaderPrelude;
static constexpr auto vertex = R"(
layout(location = 0) in ivec2 in_position;
layout(push_constant) uniform Constants {
@@ -135,7 +136,7 @@ void main() {
}
)";
static constexpr auto fragment = BACKGROUND_SHADER_COMMON R"(
static constexpr auto fragment = R"(
layout(location = 0) in vec2 frag_pos_a;
layout(location = 1) in vec2 frag_pos_b;

View File

@@ -6,13 +6,12 @@
namespace mbgl {
namespace shaders {
#define CIRCLE_SHADER_PRELUDE \
R"(
constexpr auto circleShaderPrelude = R"(
#define idCircleDrawableUBO idDrawableReservedVertexOnlyUBO
#define idCircleEvaluatedPropsUBO layerUBOStartId
)"
)";
template <>
struct ShaderSource<BuiltIn::CircleShader, gfx::Backend::Type::Vulkan> {
@@ -22,7 +21,8 @@ struct ShaderSource<BuiltIn::CircleShader, gfx::Backend::Type::Vulkan> {
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 0> textures;
static constexpr auto vertex = CIRCLE_SHADER_PRELUDE R"(
static constexpr auto prelude = circleShaderPrelude;
static constexpr auto vertex = R"(
layout(location = 0) in ivec2 in_position;
@@ -204,7 +204,7 @@ void main() {
}
)";
static constexpr auto fragment = CIRCLE_SHADER_PRELUDE R"(
static constexpr auto fragment = R"(
layout(location = 0) in vec2 frag_extrude;
layout(location = 1) in float frag_antialiasblur;

View File

@@ -20,6 +20,7 @@ struct ShaderSource<BuiltIn::ClippingMaskProgram, gfx::Backend::Type::Vulkan> {
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 0> textures;
static constexpr auto prelude = "";
static constexpr auto vertex = R"(
layout(location = 0) in ivec2 position;

View File

@@ -6,13 +6,12 @@
namespace mbgl {
namespace shaders {
#define COLLISION_SHADER_COMMON \
R"(
constexpr auto collisionShaderPrelude = R"(
#define idCollisionDrawableUBO idDrawableReservedVertexOnlyUBO
#define idCollisionTilePropsUBO drawableReservedUBOCount
)"
)";
template <>
struct ShaderSource<BuiltIn::CollisionBoxShader, gfx::Backend::Type::Vulkan> {
@@ -22,7 +21,8 @@ struct ShaderSource<BuiltIn::CollisionBoxShader, gfx::Backend::Type::Vulkan> {
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 0> textures;
static constexpr auto vertex = COLLISION_SHADER_COMMON R"(
static constexpr auto prelude = collisionShaderPrelude;
static constexpr auto vertex = R"(
layout(location = 0) in ivec2 in_position;
layout(location = 1) in ivec2 in_anchor_position;
@@ -61,7 +61,7 @@ void main() {
}
)";
static constexpr auto fragment = COLLISION_SHADER_COMMON R"(
static constexpr auto fragment = R"(
layout(location = 0) in float frag_placed;
layout(location = 1) in float frag_notUsed;
@@ -98,7 +98,8 @@ struct ShaderSource<BuiltIn::CollisionCircleShader, gfx::Backend::Type::Vulkan>
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 0> textures;
static constexpr auto vertex = COLLISION_SHADER_COMMON R"(
static constexpr auto prelude = collisionShaderPrelude;
static constexpr auto vertex = R"(
layout(location = 0) in ivec2 in_position;
layout(location = 1) in ivec2 in_anchor_position;
@@ -143,7 +144,7 @@ void main() {
}
)";
static constexpr auto fragment = COLLISION_SHADER_COMMON R"(
static constexpr auto fragment = R"(
layout(location = 0) in float frag_placed;
layout(location = 1) in float frag_notUsed;

View File

@@ -0,0 +1,57 @@
#pragma once
#include <mbgl/shaders/shader_source.hpp>
#include <mbgl/shaders/vulkan/shader_program.hpp>
namespace mbgl {
namespace shaders {
constexpr auto customGeometryShaderPrelude = R"(#define idCustomGeometryDrawableUBO drawableReservedUBOCount)";
template <>
struct ShaderSource<BuiltIn::CustomGeometryShader, gfx::Backend::Type::Vulkan> {
static constexpr const char* name = "CustomGeometryShader";
static const std::array<AttributeInfo, 2> attributes;
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 1> textures;
static constexpr auto prelude = customGeometryShaderPrelude;
static constexpr auto vertex = R"(
layout(location = 0) in vec3 in_position;
layout(location = 1) in vec2 in_texcoord;
layout(set = DRAWABLE_UBO_SET_INDEX, binding = idCustomGeometryDrawableUBO) uniform CustomDrawableDrawableUBO {
mat4 matrix;
vec4 color;
} drawable;
layout(location = 0) out vec2 frag_uv;
void main() {
frag_uv = in_texcoord;
gl_Position = drawable.matrix * vec4(in_position, 1.0);
applySurfaceTransform();
}
)";
static constexpr auto fragment = R"(
layout(location = 0) in vec2 frag_uv;
layout(location = 0) out vec4 out_color;
layout(set = DRAWABLE_UBO_SET_INDEX, binding = idCustomGeometryDrawableUBO) uniform CustomDrawableDrawableUBO {
mat4 matrix;
vec4 color;
} drawable;
layout(set = DRAWABLE_IMAGE_SET_INDEX, binding = 0) uniform sampler2D image_sampler;
void main() {
out_color = texture(image_sampler, frag_uv) * drawable.color;
}
)";
};
} // namespace shaders
} // namespace mbgl

View File

@@ -6,12 +6,7 @@
namespace mbgl {
namespace shaders {
#define CUSTOM_SYMBOL_ICON_SHADER_PRELUDE \
R"(
#define idCustomSymbolDrawableUBO idDrawableReservedVertexOnlyUBO
)"
constexpr auto customSymbolIconShaderPrelude = R"(#define idCustomSymbolDrawableUBO idDrawableReservedVertexOnlyUBO)";
template <>
struct ShaderSource<BuiltIn::CustomSymbolIconShader, gfx::Backend::Type::Vulkan> {
@@ -21,7 +16,8 @@ struct ShaderSource<BuiltIn::CustomSymbolIconShader, gfx::Backend::Type::Vulkan>
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 1> textures;
static constexpr auto vertex = CUSTOM_SYMBOL_ICON_SHADER_PRELUDE R"(
static constexpr auto prelude = customSymbolIconShaderPrelude;
static constexpr auto vertex = R"(
layout(location = 0) in vec2 in_position;
layout(location = 1) in vec2 in_tex;
@@ -85,7 +81,7 @@ void main() {
}
)";
static constexpr auto fragment = CUSTOM_SYMBOL_ICON_SHADER_PRELUDE R"(
static constexpr auto fragment = R"(
layout(location = 0) in vec2 frag_tex;
layout(location = 0) out vec4 out_color;

View File

@@ -6,12 +6,7 @@
namespace mbgl {
namespace shaders {
#define DEBUG_SHADER_PRELUDE \
R"(
#define idDebugUBO drawableReservedUBOCount
)"
constexpr auto debugShaderPrelude = R"(#define idDebugUBO drawableReservedUBOCount)";
template <>
struct ShaderSource<BuiltIn::DebugShader, gfx::Backend::Type::Vulkan> {
@@ -21,7 +16,8 @@ struct ShaderSource<BuiltIn::DebugShader, gfx::Backend::Type::Vulkan> {
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 1> textures;
static constexpr auto vertex = DEBUG_SHADER_PRELUDE R"(
static constexpr auto prelude = debugShaderPrelude;
static constexpr auto vertex = R"(
layout(location = 0) in ivec2 in_position;
@@ -47,7 +43,7 @@ void main() {
}
)";
static constexpr auto fragment = DEBUG_SHADER_PRELUDE R"(
static constexpr auto fragment = R"(
layout(location = 0) in vec2 frag_uv;
layout(location = 0) out vec4 out_color;

View File

@@ -6,14 +6,13 @@
namespace mbgl {
namespace shaders {
#define FILL_SHADER_COMMON \
R"(
constexpr auto fillShaderPrelude = R"(
#define idFillDrawableUBO idDrawableReservedVertexOnlyUBO
#define idFillTilePropsUBO drawableReservedUBOCount
#define idFillEvaluatedPropsUBO layerUBOStartId
)"
)";
template <>
struct ShaderSource<BuiltIn::FillShader, gfx::Backend::Type::Vulkan> {
@@ -23,7 +22,8 @@ struct ShaderSource<BuiltIn::FillShader, gfx::Backend::Type::Vulkan> {
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 0> textures;
static constexpr auto vertex = FILL_SHADER_COMMON R"(
static constexpr auto prelude = fillShaderPrelude;
static constexpr auto vertex = R"(
layout(location = 0) in ivec2 in_position;
@@ -77,7 +77,7 @@ void main() {
}
)";
static constexpr auto fragment = FILL_SHADER_COMMON R"(
static constexpr auto fragment = R"(
#if !defined(HAS_UNIFORM_u_color)
layout(location = 0) in vec4 frag_color;
@@ -125,7 +125,8 @@ struct ShaderSource<BuiltIn::FillOutlineShader, gfx::Backend::Type::Vulkan> {
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 0> textures;
static constexpr auto vertex = FILL_SHADER_COMMON R"(
static constexpr auto prelude = fillShaderPrelude;
static constexpr auto vertex = R"(
layout(location = 0) in ivec2 in_position;
@@ -183,7 +184,7 @@ void main() {
}
)";
static constexpr auto fragment = FILL_SHADER_COMMON R"(
static constexpr auto fragment = R"(
#if !defined(HAS_UNIFORM_u_outline_color)
layout(location = 0) in vec4 frag_color;
@@ -240,7 +241,8 @@ struct ShaderSource<BuiltIn::FillPatternShader, gfx::Backend::Type::Vulkan> {
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 1> textures;
static constexpr auto vertex = FILL_SHADER_COMMON R"(
static constexpr auto prelude = fillShaderPrelude;
static constexpr auto vertex = R"(
layout(location = 0) in ivec2 in_position;
@@ -352,7 +354,7 @@ void main() {
}
)";
static constexpr auto fragment = FILL_SHADER_COMMON R"(
static constexpr auto fragment = R"(
layout(location = 0) in vec2 frag_pos_a;
layout(location = 1) in vec2 frag_pos_b;
@@ -451,7 +453,8 @@ struct ShaderSource<BuiltIn::FillOutlinePatternShader, gfx::Backend::Type::Vulka
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 1> textures;
static constexpr auto vertex = FILL_SHADER_COMMON R"(
static constexpr auto prelude = fillShaderPrelude;
static constexpr auto vertex = R"(
layout(location = 0) in ivec2 in_position;
@@ -566,7 +569,7 @@ void main() {
}
)";
static constexpr auto fragment = FILL_SHADER_COMMON R"(
static constexpr auto fragment = R"(
layout(location = 0) in vec2 frag_pos_a;
layout(location = 1) in vec2 frag_pos_b;
@@ -669,7 +672,8 @@ struct ShaderSource<BuiltIn::FillOutlineTriangulatedShader, gfx::Backend::Type::
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 0> textures;
static constexpr auto vertex = FILL_SHADER_COMMON R"(
static constexpr auto prelude = fillShaderPrelude;
static constexpr auto vertex = R"(
layout(location = 0) in ivec2 in_pos_normal;
layout(location = 1) in uvec4 in_data;
@@ -735,7 +739,7 @@ void main() {
}
)";
static constexpr auto fragment = FILL_SHADER_COMMON R"(
static constexpr auto fragment = R"(
layout(location = 0) in float frag_width2;
layout(location = 1) in vec2 frag_normal;

View File

@@ -6,14 +6,13 @@
namespace mbgl {
namespace shaders {
#define FILL_EXTRUSION_SHADER_COMMON \
R"(
constexpr auto fillExtrusionShaderPrelude = R"(
#define idFillExtrusionDrawableUBO idDrawableReservedVertexOnlyUBO
#define idFillExtrusionTilePropsUBO drawableReservedUBOCount
#define idFillExtrusionPropsUBO layerUBOStartId
)"
)";
template <>
struct ShaderSource<BuiltIn::FillExtrusionShader, gfx::Backend::Type::Vulkan> {
@@ -23,7 +22,8 @@ struct ShaderSource<BuiltIn::FillExtrusionShader, gfx::Backend::Type::Vulkan> {
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 0> textures;
static constexpr auto vertex = FILL_EXTRUSION_SHADER_COMMON R"(
static constexpr auto prelude = fillExtrusionShaderPrelude;
static constexpr auto vertex = R"(
layout(location = 0) in ivec2 in_position;
layout(location = 1) in ivec4 in_normal_ed;
@@ -151,7 +151,7 @@ void main() {
}
)";
static constexpr auto fragment = FILL_EXTRUSION_SHADER_COMMON R"(
static constexpr auto fragment = R"(
layout(location = 0) in vec4 frag_color;
layout(location = 0) out vec4 out_color;
@@ -170,7 +170,8 @@ struct ShaderSource<BuiltIn::FillExtrusionPatternShader, gfx::Backend::Type::Vul
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 1> textures;
static constexpr auto vertex = FILL_EXTRUSION_SHADER_COMMON R"(
static constexpr auto prelude = fillExtrusionShaderPrelude;
static constexpr auto vertex = R"(
layout(location = 0) in ivec2 in_position;
layout(location = 1) in ivec4 in_normal_ed;
@@ -336,7 +337,7 @@ void main() {
}
)";
static constexpr auto fragment = FILL_EXTRUSION_SHADER_COMMON R"(
static constexpr auto fragment = R"(
layout(location = 0) in mediump vec4 frag_lighting;
layout(location = 1) in mediump vec2 frag_pos_a;

View File

@@ -6,13 +6,12 @@
namespace mbgl {
namespace shaders {
#define HEATMAP_SHADER_PRELUDE \
R"(
constexpr auto heatmapShaderPrelude = R"(
#define idHeatmapDrawableUBO idDrawableReservedVertexOnlyUBO
#define idHeatmapEvaluatedPropsUBO layerUBOStartId
)"
)";
template <>
struct ShaderSource<BuiltIn::HeatmapShader, gfx::Backend::Type::Vulkan> {
@@ -22,7 +21,8 @@ struct ShaderSource<BuiltIn::HeatmapShader, gfx::Backend::Type::Vulkan> {
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 0> textures;
static constexpr auto vertex = HEATMAP_SHADER_PRELUDE R"(
static constexpr auto prelude = heatmapShaderPrelude;
static constexpr auto vertex = R"(
// Effective "0" in the kernel density texture to adjust the kernel size to;
// this empirically chosen number minimizes artifacts on overlapping kernels
@@ -117,7 +117,7 @@ void main() {
}
)";
static constexpr auto fragment = HEATMAP_SHADER_PRELUDE R"(
static constexpr auto fragment = R"(
// Gaussian kernel coefficient: 1 / sqrt(2 * PI)
#define GAUSS_COEF 0.3989422804014327

View File

@@ -6,12 +6,7 @@
namespace mbgl {
namespace shaders {
#define HEATMAP_TEXTURE_SHADER_PRELUDE \
R"(
#define idHeatmapTexturePropsUBO layerUBOStartId
)"
constexpr auto heatmapTextureShaderPrelude = R"(#define idHeatmapTexturePropsUBO layerUBOStartId)";
template <>
struct ShaderSource<BuiltIn::HeatmapTextureShader, gfx::Backend::Type::Vulkan> {
@@ -21,7 +16,8 @@ struct ShaderSource<BuiltIn::HeatmapTextureShader, gfx::Backend::Type::Vulkan> {
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 2> textures;
static constexpr auto vertex = HEATMAP_TEXTURE_SHADER_PRELUDE R"(
static constexpr auto prelude = heatmapTextureShaderPrelude;
static constexpr auto vertex = R"(
layout(location = 0) in ivec2 in_position;
@@ -44,7 +40,7 @@ void main() {
}
)";
static constexpr auto fragment = HEATMAP_TEXTURE_SHADER_PRELUDE R"(
static constexpr auto fragment = R"(
layout(location = 0) in vec2 frag_position;
layout(location = 0) out vec4 out_color;

View File

@@ -6,14 +6,13 @@
namespace mbgl {
namespace shaders {
#define HILLSHADE_SHADER_PRELUDE \
R"(
constexpr auto hillshadeShaderPrelude = R"(
#define idHillshadeDrawableUBO idDrawableReservedVertexOnlyUBO
#define idHillshadeTilePropsUBO idDrawableReservedFragmentOnlyUBO
#define idHillshadeEvaluatedPropsUBO layerUBOStartId
)"
)";
template <>
struct ShaderSource<BuiltIn::HillshadeShader, gfx::Backend::Type::Vulkan> {
@@ -23,7 +22,8 @@ struct ShaderSource<BuiltIn::HillshadeShader, gfx::Backend::Type::Vulkan> {
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 1> textures;
static constexpr auto vertex = HILLSHADE_SHADER_PRELUDE R"(
static constexpr auto prelude = hillshadeShaderPrelude;
static constexpr auto vertex = R"(
layout(location = 0) in ivec2 in_position;
layout(location = 1) in ivec2 in_texture_position;
@@ -53,7 +53,7 @@ void main() {
}
)";
static constexpr auto fragment = HILLSHADE_SHADER_PRELUDE R"(
static constexpr auto fragment = R"(
layout(location = 0) in vec2 frag_position;
layout(location = 0) out vec4 out_color;

View File

@@ -6,13 +6,12 @@
namespace mbgl {
namespace shaders {
#define HILLSHADE_PREPARE_SHADER_PRELUDE \
R"(
constexpr auto hillshadePrepareShaderPrelude = R"(
#define idHillshadePrepareDrawableUBO idDrawableReservedVertexOnlyUBO
#define idHillshadePrepareTilePropsUBO drawableReservedUBOCount
)"
)";
template <>
struct ShaderSource<BuiltIn::HillshadePrepareShader, gfx::Backend::Type::Vulkan> {
@@ -22,7 +21,8 @@ struct ShaderSource<BuiltIn::HillshadePrepareShader, gfx::Backend::Type::Vulkan>
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 1> textures;
static constexpr auto vertex = HILLSHADE_PREPARE_SHADER_PRELUDE R"(
static constexpr auto prelude = hillshadePrepareShaderPrelude;
static constexpr auto vertex = R"(
layout(location = 0) in ivec2 in_position;
layout(location = 1) in ivec2 in_texture_position;
@@ -51,7 +51,7 @@ void main() {
}
)";
static constexpr auto fragment = HILLSHADE_PREPARE_SHADER_PRELUDE R"(
static constexpr auto fragment = R"(
layout(location = 0) in vec2 frag_position;
layout(location = 0) out vec4 out_color;

View File

@@ -6,14 +6,13 @@
namespace mbgl {
namespace shaders {
#define LINE_SHADER_COMMON \
R"(
constexpr auto lineShadePrelude = R"(
#define idLineDrawableUBO idDrawableReservedVertexOnlyUBO
#define idLineTilePropsUBO idDrawableReservedFragmentOnlyUBO
#define idLineEvaluatedPropsUBO layerUBOStartId
)"
)";
template <>
struct ShaderSource<BuiltIn::LineShader, gfx::Backend::Type::Vulkan> {
@@ -23,7 +22,8 @@ struct ShaderSource<BuiltIn::LineShader, gfx::Backend::Type::Vulkan> {
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 0> textures;
static constexpr auto vertex = LINE_SHADER_COMMON R"(
static constexpr auto prelude = lineShadePrelude;
static constexpr auto vertex = R"(
layout(location = 0) in ivec2 in_pos_normal;
layout(location = 1) in uvec4 in_data;
@@ -182,7 +182,7 @@ void main() {
}
)";
static constexpr auto fragment = LINE_SHADER_COMMON R"(
static constexpr auto fragment = R"(
layout(location = 0) in lowp vec2 frag_normal;
layout(location = 1) in lowp vec2 frag_width2;
@@ -261,7 +261,8 @@ struct ShaderSource<BuiltIn::LineGradientShader, gfx::Backend::Type::Vulkan> {
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 1> textures;
static constexpr auto vertex = LINE_SHADER_COMMON R"(
static constexpr auto prelude = lineShadePrelude;
static constexpr auto vertex = R"(
layout(location = 0) in ivec2 in_pos_normal;
layout(location = 1) in uvec4 in_data;
@@ -410,7 +411,7 @@ void main() {
}
)";
static constexpr auto fragment = LINE_SHADER_COMMON R"(
static constexpr auto fragment = R"(
layout(location = 0) in lowp vec2 frag_normal;
layout(location = 1) in lowp vec2 frag_width2;
@@ -486,7 +487,8 @@ struct ShaderSource<BuiltIn::LinePatternShader, gfx::Backend::Type::Vulkan> {
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 1> textures;
static constexpr auto vertex = LINE_SHADER_COMMON R"(
static constexpr auto prelude = lineShadePrelude;
static constexpr auto vertex = R"(
layout(location = 0) in ivec2 in_pos_normal;
layout(location = 1) in uvec4 in_data;
@@ -660,7 +662,7 @@ void main() {
}
)";
static constexpr auto fragment = LINE_SHADER_COMMON R"(
static constexpr auto fragment = R"(
layout(location = 0) in lowp vec2 frag_normal;
layout(location = 1) in lowp vec2 frag_width2;
@@ -802,7 +804,8 @@ struct ShaderSource<BuiltIn::LineSDFShader, gfx::Backend::Type::Vulkan> {
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 1> textures;
static constexpr auto vertex = LINE_SHADER_COMMON R"(
static constexpr auto prelude = lineShadePrelude;
static constexpr auto vertex = R"(
layout(location = 0) in ivec2 in_pos_normal;
layout(location = 1) in uvec4 in_data;
@@ -987,7 +990,7 @@ void main() {
}
)";
static constexpr auto fragment = LINE_SHADER_COMMON R"(
static constexpr auto fragment = R"(
layout(location = 0) in lowp vec2 frag_normal;
layout(location = 1) in lowp vec2 frag_width2;

View File

@@ -6,12 +6,7 @@
namespace mbgl {
namespace shaders {
#define LOCATION_INDICATOR_SHADER_PRELUDE \
R"(
#define idLocationIndicatorDrawableUBO drawableReservedUBOCount
)"
constexpr auto locationIndicatorShaderPrelude = R"(#define idLocationIndicatorDrawableUBO drawableReservedUBOCount)";
template <>
struct ShaderSource<BuiltIn::LocationIndicatorShader, gfx::Backend::Type::Vulkan> {
@@ -21,7 +16,8 @@ struct ShaderSource<BuiltIn::LocationIndicatorShader, gfx::Backend::Type::Vulkan
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 0> textures;
static constexpr auto vertex = LOCATION_INDICATOR_SHADER_PRELUDE R"(
static constexpr auto prelude = locationIndicatorShaderPrelude;
static constexpr auto vertex = R"(
layout(location = 0) in vec2 in_position;
layout(set = DRAWABLE_UBO_SET_INDEX, binding = idLocationIndicatorDrawableUBO) uniform LocationIndicatorDrawableUBO {
@@ -35,7 +31,7 @@ void main() {
}
)";
static constexpr auto fragment = LOCATION_INDICATOR_SHADER_PRELUDE R"(
static constexpr auto fragment = R"(
layout(location = 0) out vec4 out_color;
layout(set = DRAWABLE_UBO_SET_INDEX, binding = idLocationIndicatorDrawableUBO) uniform LocationIndicatorDrawableUBO {
@@ -57,7 +53,8 @@ struct ShaderSource<BuiltIn::LocationIndicatorTexturedShader, gfx::Backend::Type
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 1> textures;
static constexpr auto vertex = LOCATION_INDICATOR_SHADER_PRELUDE R"(
static constexpr auto prelude = locationIndicatorShaderPrelude;
static constexpr auto vertex = R"(
layout(location = 0) in vec2 in_position;
layout(location = 1) in vec2 in_texcoord;

View File

@@ -3,13 +3,12 @@
#include <mbgl/shaders/shader_source.hpp>
#include <mbgl/shaders/vulkan/shader_program.hpp>
#define RASTER_SHADER_PRELUDE \
R"(
constexpr auto rasterShaderPrelude = R"(
#define idRasterDrawableUBO idDrawableReservedVertexOnlyUBO
#define idRasterEvaluatedPropsUBO layerUBOStartId
)"
)";
namespace mbgl {
namespace shaders {
@@ -22,7 +21,8 @@ struct ShaderSource<BuiltIn::RasterShader, gfx::Backend::Type::Vulkan> {
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 2> textures;
static constexpr auto vertex = RASTER_SHADER_PRELUDE R"(
static constexpr auto prelude = rasterShaderPrelude;
static constexpr auto vertex = R"(
layout(location = 0) in ivec2 in_position;
layout(location = 1) in ivec2 in_texture_position;
@@ -73,7 +73,7 @@ void main() {
}
)";
static constexpr auto fragment = RASTER_SHADER_PRELUDE R"(
static constexpr auto fragment = R"(
layout(location = 0) in vec2 frag_position0;
layout(location = 1) in vec2 frag_position1;

View File

@@ -47,6 +47,7 @@ public:
std::string_view /*firstAttribName*/) override {
using ShaderSource = shaders::ShaderSource<ShaderID, gfx::Backend::Type::Vulkan>;
constexpr auto& name = ShaderSource::name;
constexpr auto& prelude = ShaderSource::prelude;
constexpr auto& vert = ShaderSource::vertex;
constexpr auto& frag = ShaderSource::fragment;
@@ -60,8 +61,13 @@ public:
DefinesMap additionalDefines;
addAdditionalDefines(propertiesAsUniforms, additionalDefines);
const std::string preludeSource(prelude);
const std::string vertexSource = preludeSource + vert;
const std::string fragmentSource = preludeSource + frag;
auto& context = static_cast<Context&>(gfxContext);
shader = context.createProgram(ShaderID, shaderName, vert, frag, programParameters, additionalDefines);
shader = context.createProgram(
ShaderID, shaderName, vertexSource, fragmentSource, programParameters, additionalDefines);
assert(shader);
if (!shader || !registerShader(shader, shaderName)) {
assert(false);

View File

@@ -6,14 +6,13 @@
namespace mbgl {
namespace shaders {
#define SYMBOL_SHADER_COMMON \
R"(
constexpr auto symbolShaderPrelude = R"(
#define idSymbolDrawableUBO idDrawableReservedVertexOnlyUBO
#define idSymbolTilePropsUBO idDrawableReservedFragmentOnlyUBO
#define idSymbolEvaluatedPropsUBO layerUBOStartId
)"
)";
template <>
struct ShaderSource<BuiltIn::SymbolIconShader, gfx::Backend::Type::Vulkan> {
@@ -23,7 +22,8 @@ struct ShaderSource<BuiltIn::SymbolIconShader, gfx::Backend::Type::Vulkan> {
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 1> textures;
static constexpr auto vertex = SYMBOL_SHADER_COMMON R"(
static constexpr auto prelude = symbolShaderPrelude;
static constexpr auto vertex = R"(
layout(location = 0) in ivec4 in_pos_offset;
layout(location = 1) in uvec4 in_data;
@@ -144,7 +144,7 @@ void main() {
}
)";
static constexpr auto fragment = SYMBOL_SHADER_COMMON R"(
static constexpr auto fragment = R"(
layout(location = 0) in mediump vec2 frag_tex;
layout(location = 1) in mediump float frag_opacity;
@@ -210,7 +210,8 @@ struct ShaderSource<BuiltIn::SymbolSDFIconShader, gfx::Backend::Type::Vulkan> {
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 1> textures;
static constexpr auto vertex = SYMBOL_SHADER_COMMON R"(
static constexpr auto prelude = symbolShaderPrelude;
static constexpr auto vertex = R"(
layout(location = 0) in ivec4 in_pos_offset;
layout(location = 1) in uvec4 in_data;
@@ -386,7 +387,7 @@ void main() {
}
)";
static constexpr auto fragment = SYMBOL_SHADER_COMMON R"(
static constexpr auto fragment = R"(
layout(location = 0) in mediump vec2 frag_tex;
layout(location = 1) in mediump float frag_fade_opacity;
@@ -504,7 +505,8 @@ struct ShaderSource<BuiltIn::SymbolTextAndIconShader, gfx::Backend::Type::Vulkan
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 2> textures;
static constexpr auto vertex = SYMBOL_SHADER_COMMON R"(
static constexpr auto prelude = symbolShaderPrelude;
static constexpr auto vertex = R"(
#define SDF 1.0
#define ICON 0.0
@@ -687,7 +689,7 @@ void main() {
}
)";
static constexpr auto fragment = SYMBOL_SHADER_COMMON R"(
static constexpr auto fragment = R"(
layout(location = 0) in mediump vec2 frag_tex;
layout(location = 1) in mediump float frag_fade_opacity;

View File

@@ -6,13 +6,12 @@
namespace mbgl {
namespace shaders {
#define WIDEVECTOR_SHADER_PRELUDE \
R"(
constexpr auto wideVectorShaderPrelude = R"(
#define idWideVectorUniformsUBO idDrawableReservedVertexOnlyUBO
#define idWideVectorUniformWideVecUBO drawableReservedUBOCount
)"
)";
template <>
struct ShaderSource<BuiltIn::WideVectorShader, gfx::Backend::Type::Vulkan> {
@@ -22,7 +21,8 @@ struct ShaderSource<BuiltIn::WideVectorShader, gfx::Backend::Type::Vulkan> {
static const std::array<AttributeInfo, 4> instanceAttributes;
static const std::array<TextureInfo, 0> textures;
static constexpr auto vertex = WIDEVECTOR_SHADER_PRELUDE R"(
static constexpr auto prelude = wideVectorShaderPrelude;
static constexpr auto vertex = R"(
/** Expressions are used to change values like width and opacity over zoom levels. **/
#define WKSExpStops 8
@@ -58,7 +58,7 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = idWideVectorUniformWideVecUBO) un
float offset;
float edge;
float texRepeat;
vec4 texOffset;
vec2 texOffset;
float miterLimit;
int join;
int cap;
@@ -66,6 +66,17 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = idWideVectorUniformWideVecUBO) un
float interClipLimit;
} wideVec;
// Instance info for the wide vector (new) vertex shader
typedef struct
{
// Center of the point on the line
vec3 center;
// Color
vec4 color;
// Used to track loops and such
int prev,next; // set to -1 for non-loops
} VertexTriWideVecInstance;
struct IntersectInfo {
bool valid;
vec2 interPt;
@@ -110,16 +121,28 @@ IntersectInfo intersectWideLines(vec2 p0,vec2 p1,vec2 p2, vec2 n0,vec2 n1)
return intersectLines(p0 + n0, p1 + n0, p1 + n1, p2 + n1);
}
// Used to track what info we have about a center point
struct CenterInfo {
/// Screen coordinates of the line segment endpoint
vec2 screenPos;
/// Length of the segment (in screen coordinates)
float len;
/// Normalized direction of the segment
vec2 nDir;
/// Normalized plane normal, perpendicular to the segment
vec2 norm;
};
vec3 viewPos(const mat4 &mat, vec3 vec) {
const vec4 p = mat * vec4(vec, 1.0);
return p.xyz; // / p.w; ?
}
float2 screenPos_MVP(const Uniforms &u, float3 viewPos) {
const float4 p4 = float4(viewPos, 1.0);
vec2 screenPos_MVP(const Uniforms &u, vec3 viewPos) {
const vec4 p4 = vec4(viewPos, 1.0);
// Use the MVP matrix
const float4 s = u.mvpMatrix * p4;
const vec4 s = u.mvpMatrix * p4;
return s.xy / s.w;
}
@@ -156,7 +179,7 @@ void main() {
}
)";
static constexpr auto fragment = WIDEVECTOR_SHADER_PRELUDE R"(
static constexpr auto fragment = R"(
// TODO
)";
};

View File

@@ -35,17 +35,17 @@ class CustomDrawableLayerHost::Interface {
public:
enum class LineShaderType {
Classic,
MetalWideVector
WideVector
};
struct LineOptions {
gfx::PolylineGeneratorOptions geometry;
float blur = 0.f;
float opacity = 1.f;
float gapWidth = 0.f;
float offset = 0.f;
float width = 1.f;
LineShaderType shaderType = LineShaderType::Classic;
Color color;
};
@@ -58,12 +58,30 @@ public:
Size size;
gfx::Texture2DPtr texture;
std::array<float, 2> anchor{0.5f, 0.5f};
std::array<std::array<float, 2>, 2> textureCoordinates{{{0, 0}, {1, 1}}};
float angleDegrees{.0f};
bool scaleWithMap{false};
bool pitchWithMap{false};
};
struct GeometryVertex {
std::array<float, 3> position;
std::array<float, 2> texcoords;
};
struct GeometryOptions {
mat4 matrix = matrix::identity4();
Color color = Color::white();
gfx::Texture2DPtr texture;
};
template <typename T>
using TweakerCallback = std::function<void(mbgl::gfx::Drawable&, const mbgl::PaintParameters&, T&)>;
using LineTweakerCallback = TweakerCallback<LineOptions>;
using FillTweakerCallback = TweakerCallback<FillOptions>;
using SymbolTweakerCallback = TweakerCallback<SymbolOptions>;
using GeometryTweakerCallback = TweakerCallback<GeometryOptions>;
public:
/// @brief Construct a new Interface object (internal core use only)
Interface(RenderLayer& layer,
@@ -109,37 +127,59 @@ public:
*/
void setSymbolOptions(const SymbolOptions& options);
/**
* @brief Set the geometry options
*
* @param options
*/
void setGeometryOptions(const GeometryOptions& options);
void setLineTweakerCallback(LineTweakerCallback&& callback) { lineTweakerCallback = callback; }
void setFillTweakerCallback(FillTweakerCallback&& callback) { fillTweakerCallback = callback; }
void setSymbolTweakerCallback(SymbolTweakerCallback&& callback) { symbolTweakerCallback = callback; }
void setGeometryTweakerCallback(GeometryTweakerCallback&& callback) { geometryTweakerCallback = callback; }
/**
* @brief Add a polyline
*
* @param coordinates in tile range
* @return true if the polyline was added
* @param shaderType
* @return a valid util::SimpleIdentity if the polyline was added
*/
bool addPolyline(const GeometryCoordinates& coordinates);
util::SimpleIdentity addPolyline(const GeometryCoordinates& coordinates,
LineShaderType shaderType = LineShaderType::Classic);
/**
* @brief Add a polyline
*
* @param coordinates Geographic coordinates
* @return true if the polyline was added
* @param shaderType
* @return a valid util::SimpleIdentity if the poline was added
*/
bool addPolyline(const LineString<double>& coordinates);
util::SimpleIdentity addPolyline(const LineString<double>& coordinates,
LineShaderType shaderType = LineShaderType::Classic);
/**
* @brief Add a multipolygon area fill
*
* @param geometry a collection of rings with optional holes
* @return true if the fill was added
* @return a valid util::SimpleIdentity if the fill was added
*/
bool addFill(const GeometryCollection& geometry);
util::SimpleIdentity addFill(const GeometryCollection& geometry);
/**
* @brief Add a symbol
*
* @param point
* @return true if the symbol was added
* @param textureCoordinates (optional mapping)
* @return a valid util::SimpleIdentity if the symbol was added
*/
bool addSymbol(const GeometryCoordinate& point);
util::SimpleIdentity addSymbol(const GeometryCoordinate& point,
const std::array<std::array<float, 2>, 2>& textureCoordinates = {{{0, 0}, {1, 1}}});
util::SimpleIdentity addGeometry(std::shared_ptr<gfx::VertexVector<GeometryVertex>> vertices,
std::shared_ptr<gfx::IndexVector<gfx::Triangles>> indices,
bool is3D);
/**
* @brief Finish the current drawable building session
@@ -147,6 +187,8 @@ public:
*/
void finish();
void removeDrawable(const util::SimpleIdentity& id);
public:
RenderLayer& layer;
LayerGroupBasePtr& layerGroup;
@@ -162,13 +204,15 @@ private:
gfx::ShaderPtr lineShaderWideVector() const;
gfx::ShaderPtr fillShaderDefault() const;
gfx::ShaderPtr symbolShaderDefault() const;
gfx::ShaderPtr geometryShaderDefault() const;
enum class BuilderType {
None,
LineClassic,
LineWideVector,
Fill,
Symbol
Symbol,
Geometry
};
std::unique_ptr<gfx::DrawableBuilder> createBuilder(const std::string& name, gfx::ShaderPtr shader) const;
@@ -177,13 +221,15 @@ private:
std::unique_ptr<gfx::DrawableBuilder> builder;
std::optional<OverscaledTileID> tileID;
gfx::ShaderPtr lineShader;
gfx::ShaderPtr fillShader;
gfx::ShaderPtr symbolShader;
LineOptions lineOptions;
FillOptions fillOptions;
SymbolOptions symbolOptions;
GeometryOptions geometryOptions;
LineTweakerCallback lineTweakerCallback;
FillTweakerCallback fillTweakerCallback;
SymbolTweakerCallback symbolTweakerCallback;
GeometryTweakerCallback geometryTweakerCallback;
BuilderType builderType{BuilderType::None};
};

View File

@@ -43,6 +43,7 @@ class Texture2D;
using UniqueShaderProgram = std::unique_ptr<ShaderProgram>;
using UniqueVertexBufferResource = std::unique_ptr<VertexBufferResource>;
using UniqueUniformBufferArray = std::unique_ptr<gfx::UniformBufferArray>;
class Context final : public gfx::Context {
public:
@@ -79,6 +80,8 @@ public:
bool persistent,
bool ssbo = false) override;
UniqueUniformBufferArray createLayerUniformBufferArray() override;
gfx::ShaderProgramBasePtr getGenericShader(gfx::ShaderRegistry&, const std::string& name) override;
TileLayerGroupPtr createTileLayerGroup(int32_t layerIndex, std::size_t initialCapacity, std::string name) override;

View File

@@ -24,8 +24,8 @@ public:
void upload(gfx::UploadPass&) override;
void render(RenderOrchestrator&, PaintParameters&) override;
const gfx::UniformBufferArray& getUniformBuffers() const override { return uniformBuffers; };
gfx::UniformBufferArray& mutableUniformBuffers() override { return uniformBuffers; };
const gfx::UniformBufferArray& getUniformBuffers() const override { return uniformBuffers; }
gfx::UniformBufferArray& mutableUniformBuffers() override { return uniformBuffers; }
protected:
UniformBufferArray uniformBuffers;

View File

@@ -66,6 +66,8 @@ public:
void createOrUpdate(
const size_t id, const void* data, std::size_t size, gfx::Context& context, bool persistent = false) override;
void bind(gfx::RenderPass& renderPass) override;
void bindDescriptorSets(CommandEncoder& encoder);
void freeDescriptorSets() { descriptorSet.reset(); }

View File

@@ -58,12 +58,12 @@ public:
constexpr auto numLines = 6;
Interface::LineOptions options[numLines] {
{/*geometry=*/{}, /*blur=*/0.0f, /*opacity=*/1.0f, /*gapWidth=*/0.0f, /*offset=*/0.0f, /*width=*/8.0f, /*shaderType=*/{}, /*color=*/Color::red() },
{/*geometry=*/{}, /*blur=*/4.0f, /*opacity=*/1.0f, /*gapWidth=*/2.0f, /*offset=*/-1.0f, /*width=*/4.0f, /*shaderType=*/{}, /*color=*/Color::blue() },
{/*geometry=*/{}, /*blur=*/16.0f, /*opacity=*/1.0f, /*gapWidth=*/1.0f, /*offset=*/2.0f, /*width=*/16.0f, /*shaderType=*/{}, /*color=*/Color(1.f, 0.5f, 0, 0.5f) },
{/*geometry=*/{}, /*blur=*/2.0f, /*opacity=*/1.0f, /*gapWidth=*/1.0f, /*offset=*/-2.0f, /*width=*/2.0f, /*shaderType=*/{}, /*color=*/Color(1.f, 1.f, 0, 0.3f) },
{/*geometry=*/{}, /*blur=*/0.5f, /*opacity=*/0.5f, /*gapWidth=*/1.0f, /*offset=*/0.5f, /*width=*/0.5f, /*shaderType=*/{}, /*color=*/Color::black() },
{/*geometry=*/{}, /*blur=*/24.0f, /*opacity=*/0.5f, /*gapWidth=*/1.0f, /*offset=*/-5.0f, /*width=*/24.0f, /*shaderType=*/{}, /*color=*/Color(1.f, 0, 1.f, 0.2f) },
{/*geometry=*/{}, /*blur=*/0.0f, /*opacity=*/1.0f, /*gapWidth=*/0.0f, /*offset=*/0.0f, /*width=*/8.0f, /*color=*/Color::red() },
{/*geometry=*/{}, /*blur=*/4.0f, /*opacity=*/1.0f, /*gapWidth=*/2.0f, /*offset=*/-1.0f, /*width=*/4.0f, /*color=*/Color::blue() },
{/*geometry=*/{}, /*blur=*/16.0f, /*opacity=*/1.0f, /*gapWidth=*/1.0f, /*offset=*/2.0f, /*width=*/16.0f, /*color=*/Color(1.f, 0.5f, 0, 0.5f) },
{/*geometry=*/{}, /*blur=*/2.0f, /*opacity=*/1.0f, /*gapWidth=*/1.0f, /*offset=*/-2.0f, /*width=*/2.0f, /*color=*/Color(1.f, 1.f, 0, 0.3f) },
{/*geometry=*/{}, /*blur=*/0.5f, /*opacity=*/0.5f, /*gapWidth=*/1.0f, /*offset=*/0.5f, /*width=*/0.5f, /*color=*/Color::black() },
{/*geometry=*/{}, /*blur=*/24.0f, /*opacity=*/0.5f, /*gapWidth=*/1.0f, /*offset=*/-5.0f, /*width=*/24.0f, /*color=*/Color(1.f, 0, 1.f, 0.2f) },
};
for(auto& opt: options) {
opt.geometry.beginCap = style::LineCapType::Butt;
@@ -86,7 +86,7 @@ public:
interface.setLineOptions(options[index]);
// add polyline
interface.addPolyline(polyline);
interface.addPolyline(polyline, Interface::LineShaderType::Classic);
}
}
@@ -99,12 +99,12 @@ public:
constexpr auto numLines = 6;
Interface::LineOptions options[numLines] {
{/*geometry=*/{}, /*blur=*/0.0f, /*opacity=*/1.0f, /*gapWidth=*/0.0f, /*offset=*/0.0f, /*width=*/8.0f, /*shaderType=*/Interface::LineShaderType::MetalWideVector, /*color=*/Color::red() },
{/*geometry=*/{}, /*blur=*/4.0f, /*opacity=*/1.0f, /*gapWidth=*/2.0f, /*offset=*/-1.0f, /*width=*/4.0f, /*shaderType=*/Interface::LineShaderType::MetalWideVector, /*color=*/Color::blue() },
{/*geometry=*/{}, /*blur=*/16.0f, /*opacity=*/1.0f, /*gapWidth=*/1.0f, /*offset=*/2.0f, /*width=*/16.0f, /*shaderType=*/Interface::LineShaderType::MetalWideVector, /*color=*/Color(1.f, 0.5f, 0, 0.5f) },
{/*geometry=*/{}, /*blur=*/2.0f, /*opacity=*/1.0f, /*gapWidth=*/1.0f, /*offset=*/-2.0f, /*width=*/2.0f, /*shaderType=*/Interface::LineShaderType::MetalWideVector, /*color=*/Color(1.f, 1.f, 0, 0.3f) },
{/*geometry=*/{}, /*blur=*/0.5f, /*opacity=*/0.5f, /*gapWidth=*/1.0f, /*offset=*/0.5f, /*width=*/0.5f, /*shaderType=*/Interface::LineShaderType::MetalWideVector, /*color=*/Color::black() },
{/*geometry=*/{}, /*blur=*/24.0f, /*opacity=*/0.5f, /*gapWidth=*/1.0f, /*offset=*/-5.0f, /*width=*/24.0f, /*shaderType=*/Interface::LineShaderType::MetalWideVector, /*color=*/Color(1.f, 0, 1.f, 0.2f) },
{/*geometry=*/{}, /*blur=*/0.0f, /*opacity=*/1.0f, /*gapWidth=*/0.0f, /*offset=*/0.0f, /*width=*/8.0f, /*color=*/Color::red() },
{/*geometry=*/{}, /*blur=*/4.0f, /*opacity=*/1.0f, /*gapWidth=*/2.0f, /*offset=*/-1.0f, /*width=*/4.0f, /*color=*/Color::blue() },
{/*geometry=*/{}, /*blur=*/16.0f, /*opacity=*/1.0f, /*gapWidth=*/1.0f, /*offset=*/2.0f, /*width=*/16.0f, /*color=*/Color(1.f, 0.5f, 0, 0.5f) },
{/*geometry=*/{}, /*blur=*/2.0f, /*opacity=*/1.0f, /*gapWidth=*/1.0f, /*offset=*/-2.0f, /*width=*/2.0f, /*color=*/Color(1.f, 1.f, 0, 0.3f) },
{/*geometry=*/{}, /*blur=*/0.5f, /*opacity=*/0.5f, /*gapWidth=*/1.0f, /*offset=*/0.5f, /*width=*/0.5f, /*color=*/Color::black() },
{/*geometry=*/{}, /*blur=*/24.0f, /*opacity=*/0.5f, /*gapWidth=*/1.0f, /*offset=*/-5.0f, /*width=*/24.0f, /*color=*/Color(1.f, 0, 1.f, 0.2f) },
};
for(auto& opt: options) {
opt.geometry.beginCap = style::LineCapType::Butt;
@@ -128,13 +128,13 @@ public:
interface.setLineOptions(options[index]);
// add polyline
interface.addPolyline(polyline);
interface.addPolyline(polyline, Interface::LineShaderType::WideVector);
// add clone
for(auto &p : polyline) {
p.y += 0.05f * extent / numLines;
}
interface.addPolyline(polyline);
interface.addPolyline(polyline, Interface::LineShaderType::WideVector);
for(auto &p : polyline) {
p.y -= 0.05f * extent / numLines;
}
@@ -193,9 +193,9 @@ public:
options.texture = interface.context.createTexture2D();
options.texture->setImage(image);
options.texture->setSamplerConfiguration({gfx::TextureFilterType::Linear, gfx::TextureWrapType::Clamp, gfx::TextureWrapType::Clamp});
options.textureCoordinates = {{{0.0f, 0.08f}, {1.0f, 0.9f}}};
const float xspan = options.textureCoordinates[1][0] - options.textureCoordinates[0][0];
const float yspan = options.textureCoordinates[1][1] - options.textureCoordinates[0][1];
const std::array<std::array<float, 2>, 2> textureCoordinates = {{{0.0f, 0.08f}, {1.0f, 0.9f}}};
const float xspan = textureCoordinates[1][0] - textureCoordinates[0][0];
const float yspan = textureCoordinates[1][1] - textureCoordinates[0][1];
assert(xspan > 0.0f && yspan > 0.0f);
options.size = {static_cast<uint32_t>(image->size.width * xspan), static_cast<uint32_t>(image->size.height * yspan)};
options.anchor = {0.5f, 0.95f};
@@ -205,7 +205,7 @@ public:
interface.setSymbolOptions(options);
// add symbol
interface.addSymbol(position);
interface.addSymbol(position, textureCoordinates);
}
// add polylines using wide vectors using geographic coordinates
@@ -213,7 +213,7 @@ public:
using namespace mbgl;
// add polyline with geographic coordinates
Interface::LineOptions options = {/*geometry=*/{}, /*blur=*/0.0f, /*opacity=*/1.0f, /*gapWidth=*/0.0f, /*offset=*/0.0f, /*width=*/12.0f, /*shaderType=*/Interface::LineShaderType::MetalWideVector, /*color=*/{.0f, .0f, .0f, .5f} };
Interface::LineOptions options = {/*geometry=*/{}, /*blur=*/0.0f, /*opacity=*/1.0f, /*gapWidth=*/0.0f, /*offset=*/0.0f, /*width=*/12.0f, /*color=*/{.0f, .0f, .0f, .5f} };
options.geometry.beginCap = style::LineCapType::Square;
options.geometry.endCap = style::LineCapType::Square;
options.geometry.joinType = style::LineJoinType::Bevel;
@@ -235,7 +235,7 @@ public:
// New York
{-74.04454331829972, 40.6892168305434},
};
interface.addPolyline(polyline_geo);
interface.addPolyline(polyline_geo, Interface::LineShaderType::WideVector);
}
// add polylines using wide vectors in tile coordinates
@@ -246,7 +246,7 @@ public:
interface.setTileID({11, 327, 790});
Interface::LineOptions options
{/*geometry=*/{}, /*blur=*/0.0f, /*opacity=*/1.0f, /*gapWidth=*/0.0f, /*offset=*/0.0f, /*width=*/7.0f, /*shaderType=*/Interface::LineShaderType::MetalWideVector, /*color=*/{1.0f, 0, 0, .5f} };
{/*geometry=*/{}, /*blur=*/0.0f, /*opacity=*/1.0f, /*gapWidth=*/0.0f, /*offset=*/0.0f, /*width=*/7.0f, /*color=*/{1.0f, 0, 0, .5f} };
options.geometry.beginCap = style::LineCapType::Round;
options.geometry.endCap = style::LineCapType::Round;
options.geometry.joinType = style::LineJoinType::Round;
@@ -271,8 +271,8 @@ public:
options.geometry.type = FeatureType::Polygon;
interface.setLineOptions(options);
interface.addPolyline(polyline_tile[0]);
interface.addPolyline(polyline_tile[1]);
interface.addPolyline(polyline_tile[0], Interface::LineShaderType::WideVector);
interface.addPolyline(polyline_tile[1], Interface::LineShaderType::WideVector);
}

View File

@@ -70,12 +70,9 @@ LayerManagerDefault::LayerManagerDefault() {
addLayerType(std::make_unique<CustomLayerFactory>());
#endif
#endif
#if defined(MLN_RENDER_BACKEND_OPENGL) || MLN_RENDER_BACKEND_VULKAN
#if !defined(MBGL_LAYER_LOCATION_INDICATOR_DISABLE_ALL)
addLayerType(std::make_unique<LocationIndicatorLayerFactory>());
#endif
#endif
#if MLN_DRAWABLE_RENDERER
#if !defined(MLN_LAYER_CUSTOM_DRAWABLE_DISABLE_ALL)
addLayerType(std::make_unique<CustomDrawableLayerFactory>());

View File

@@ -16,13 +16,6 @@ objc_library(
],
)
filegroup(
name = "mapbox_puck_assets",
srcs = glob([
"assets/*.png",
]),
)
cc_binary(
name = "glfw_app",
srcs = glob(
@@ -43,11 +36,9 @@ cc_binary(
],
}),
copts = CPP_FLAGS + MAPLIBRE_FLAGS,
data = [
":mapbox_puck_assets",
],
data = glob(["assets/*"]),
defines = [
r"MAPBOX_PUCK_ASSETS_PATH=\"./platform/glfw/assets/\"",
r"MLN_ASSETS_PATH=\"assets/\"",
],
linkopts = [
"-lglfw",
@@ -64,6 +55,7 @@ cc_binary(
deps = [
"//:maplibre_lib",
"@glfw",
"@tinyobjloader",
] + select({
"@platforms//os:macos": ["metal_backend"],
"@platforms//os:linux": ["//platform/linux:impl"],

View File

@@ -22,11 +22,20 @@ add_executable(
${PROJECT_SOURCE_DIR}/platform/glfw/settings_json.cpp
${PROJECT_SOURCE_DIR}/platform/glfw/test_writer.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/map/map_snapshotter.cpp
${PROJECT_SOURCE_DIR}/platform/glfw/example_custom_drawable_style_layer.cpp
)
include(${PROJECT_SOURCE_DIR}/vendor/tinyobjloader.cmake)
target_link_libraries(
mbgl-glfw
PRIVATE tinyobjloader
)
set_property(
SOURCE ${PROJECT_SOURCE_DIR}/platform/glfw/glfw_view.cpp
PROPERTY COMPILE_DEFINITIONS MAPBOX_PUCK_ASSETS_PATH=\"${PROJECT_SOURCE_DIR}/platform/glfw/assets/\"
PROPERTY COMPILE_DEFINITIONS MLN_ASSETS_PATH=\"${PROJECT_SOURCE_DIR}/platform/glfw/assets/\"
)
if(MLN_WITH_OPENGL)
@@ -87,10 +96,12 @@ target_include_directories(
PRIVATE ${PROJECT_SOURCE_DIR}/src
)
include(${PROJECT_SOURCE_DIR}/vendor/tinyobjloader.cmake)
# Use target_link_directories when we move away from CMake 3.10.
target_link_libraries(
mbgl-glfw
PRIVATE $<$<BOOL:${GLFW_LIBRARY_DIRS}>:-L${GLFW_LIBRARY_DIRS}>
PRIVATE $<$<BOOL:${GLFW_LIBRARY_DIRS}>:-L${GLFW_LIBRARY_DIRS}> tinyobjloader
)
if(WIN32)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,606 @@
#include "example_custom_drawable_style_layer.hpp"
#if MLN_DRAWABLE_RENDERER
#include <mbgl/style/layer.hpp>
#include <mbgl/style/layers/custom_drawable_layer.hpp>
#include <mbgl/util/io.hpp>
#include <mbgl/gfx/drawable.hpp>
#include <mbgl/util/logging.hpp>
#include <memory>
#include <cmath>
#include <filesystem>
#define TINYOBJLOADER_IMPLEMENTATION
#include "tiny_obj_loader.h"
ExampleCustomDrawableStyleLayerHost::ExampleCustomDrawableStyleLayerHost(const std::string& assetsPath_)
: assetsPath(assetsPath_) {}
ExampleCustomDrawableStyleLayerHost::~ExampleCustomDrawableStyleLayerHost() {}
void ExampleCustomDrawableStyleLayerHost::initialize() {}
void ExampleCustomDrawableStyleLayerHost::deinitialize() {}
void ExampleCustomDrawableStyleLayerHost::update(Interface& interface) {
// if we have built our drawable(s) already, either update or skip
if (interface.getDrawableCount() == 0) {
createDrawables(interface);
return;
}
}
mbgl::Point<double> ExampleCustomDrawableStyleLayerHost::project(const mbgl::LatLng& c, const mbgl::TransformState& s) {
mbgl::LatLng unwrappedLatLng = c.wrapped();
unwrappedLatLng.unwrapForShortestPath(s.getLatLng(mbgl::LatLng::Wrapped));
return mbgl::Projection::project(unwrappedLatLng, s.getScale());
}
void ExampleCustomDrawableStyleLayerHost::createDrawables(Interface& interface) {
constexpr float extent = mbgl::util::EXTENT;
// add classic polylines
{
using namespace mbgl;
// set tile
interface.setTileID({11, 327, 792});
constexpr auto numLines = 6;
Interface::LineOptions options[numLines]{
{/*geometry=*/{},
/*blur=*/0.0f,
/*opacity=*/1.0f,
/*gapWidth=*/0.0f,
/*offset=*/0.0f,
/*width=*/8.0f,
/*color=*/Color::red()},
{/*geometry=*/{},
/*blur=*/4.0f,
/*opacity=*/1.0f,
/*gapWidth=*/2.0f,
/*offset=*/-1.0f,
/*width=*/4.0f,
/*color=*/Color::blue()},
{/*geometry=*/{},
/*blur=*/16.0f,
/*opacity=*/1.0f,
/*gapWidth=*/1.0f,
/*offset=*/2.0f,
/*width=*/16.0f,
/*color=*/Color(1.f, 0.5f, 0, 0.5f)},
{/*geometry=*/{},
/*blur=*/2.0f,
/*opacity=*/1.0f,
/*gapWidth=*/1.0f,
/*offset=*/-2.0f,
/*width=*/2.0f,
/*color=*/Color(1.f, 1.f, 0, 0.3f)},
{/*geometry=*/{},
/*blur=*/0.5f,
/*opacity=*/0.5f,
/*gapWidth=*/1.0f,
/*offset=*/0.5f,
/*width=*/0.5f,
/*color=*/Color::black()},
{/*geometry=*/{},
/*blur=*/24.0f,
/*opacity=*/0.5f,
/*gapWidth=*/1.0f,
/*offset=*/-5.0f,
/*width=*/24.0f,
/*color=*/Color(1.f, 0, 1.f, 0.2f)},
};
for (auto& opt : options) {
opt.geometry.beginCap = style::LineCapType::Butt;
opt.geometry.endCap = style::LineCapType::Butt;
opt.geometry.joinType = style::LineJoinType::Miter;
}
constexpr auto numPoints = 10;
GeometryCoordinates polyline;
for (auto ipoint{0}; ipoint < numPoints; ++ipoint) {
polyline.emplace_back(
static_cast<int16_t>(ipoint * extent / numPoints),
static_cast<int16_t>(std::sin(ipoint * 2 * M_PI / numPoints) * extent / numLines / 2.f));
}
for (auto index{0}; index < numLines; ++index) {
for (auto& p : polyline) {
p.y += extent / numLines;
}
// set property values
interface.setLineOptions(options[index]);
// add polyline
interface.addPolyline(polyline, Interface::LineShaderType::Classic);
}
}
// add wide vector polylines with tile coordinates
{
using namespace mbgl;
// set tile
interface.setTileID({11, 327, 792});
constexpr auto numLines = 6;
Interface::LineOptions options[numLines]{
{/*geometry=*/{},
/*blur=*/0.0f,
/*opacity=*/1.0f,
/*gapWidth=*/0.0f,
/*offset=*/0.0f,
/*width=*/8.0f,
/*color=*/Color::red()},
{/*geometry=*/{},
/*blur=*/4.0f,
/*opacity=*/1.0f,
/*gapWidth=*/2.0f,
/*offset=*/-1.0f,
/*width=*/4.0f,
/*color=*/Color::blue()},
{/*geometry=*/{},
/*blur=*/16.0f,
/*opacity=*/1.0f,
/*gapWidth=*/1.0f,
/*offset=*/2.0f,
/*width=*/16.0f,
/*color=*/Color(1.f, 0.5f, 0, 0.5f)},
{/*geometry=*/{},
/*blur=*/2.0f,
/*opacity=*/1.0f,
/*gapWidth=*/1.0f,
/*offset=*/-2.0f,
/*width=*/2.0f,
/*color=*/Color(1.f, 1.f, 0, 0.3f)},
{/*geometry=*/{},
/*blur=*/0.5f,
/*opacity=*/0.5f,
/*gapWidth=*/1.0f,
/*offset=*/0.5f,
/*width=*/0.5f,
/*color=*/Color::black()},
{/*geometry=*/{},
/*blur=*/24.0f,
/*opacity=*/0.5f,
/*gapWidth=*/1.0f,
/*offset=*/-5.0f,
/*width=*/24.0f,
/*color=*/Color(1.f, 0, 1.f, 0.2f)},
};
for (auto& opt : options) {
opt.geometry.beginCap = style::LineCapType::Butt;
opt.geometry.endCap = style::LineCapType::Butt;
opt.geometry.joinType = style::LineJoinType::Miter;
}
constexpr auto numPoints = 10;
GeometryCoordinates polyline;
for (auto ipoint{0}; ipoint < numPoints; ++ipoint) {
polyline.emplace_back(
static_cast<int16_t>(ipoint * extent / numPoints),
static_cast<int16_t>(std::sin(ipoint * 2 * M_PI / numPoints) * extent / numLines / 2.f));
}
for (auto index{0}; index < numLines; ++index) {
for (auto& p : polyline) {
if (0 == index) p.y += 0.25f * extent / numLines;
p.y += extent / numLines;
}
// set property values
interface.setLineOptions(options[index]);
// add polyline
interface.addPolyline(polyline, Interface::LineShaderType::WideVector);
// add clone
for (auto& p : polyline) {
p.y += 0.05f * extent / numLines;
}
interface.addPolyline(polyline, Interface::LineShaderType::WideVector);
for (auto& p : polyline) {
p.y -= 0.05f * extent / numLines;
}
}
}
// add fill polygon
{
using namespace mbgl;
// set tile
interface.setTileID({11, 327, 790});
GeometryCollection geometry{
{
// ring 1
{static_cast<int16_t>(extent * 0.1f), static_cast<int16_t>(extent * 0.2f)},
{static_cast<int16_t>(extent * 0.5f), static_cast<int16_t>(extent * 0.5f)},
{static_cast<int16_t>(extent * 0.7f), static_cast<int16_t>(extent * 0.5f)},
{static_cast<int16_t>(extent * 0.5f), static_cast<int16_t>(extent * 1.0f)},
{static_cast<int16_t>(extent * 0.0f), static_cast<int16_t>(extent * 0.5f)},
{static_cast<int16_t>(extent * 0.1f), static_cast<int16_t>(extent * 0.2f)},
},
{
// ring 2
{static_cast<int16_t>(extent * 0.1f), static_cast<int16_t>(extent * 0.25f)},
{static_cast<int16_t>(extent * 0.15f), static_cast<int16_t>(extent * 0.5f)},
{static_cast<int16_t>(extent * 0.25f), static_cast<int16_t>(extent * 0.45f)},
{static_cast<int16_t>(extent * 0.1f), static_cast<int16_t>(extent * 0.25f)},
},
};
// set properties
interface.setFillOptions({/*color=*/Color::green(), /*opacity=*/0.5f});
// add fill
interface.addFill(geometry);
}
// add symbol
{
using namespace mbgl;
// set tile
interface.setTileID({11, 327, 789});
GeometryCoordinate position{static_cast<int16_t>(extent * 0.0f), static_cast<int16_t>(extent * 0.5f)};
// load image
std::shared_ptr<PremultipliedImage> image = std::make_shared<PremultipliedImage>(
mbgl::decodeImage(mbgl::util::read_file(assetsPath + "puck_hat.png")));
// set symbol options
Interface::SymbolOptions options;
options.texture = interface.context.createTexture2D();
options.texture->setImage(image);
options.texture->setSamplerConfiguration(
{gfx::TextureFilterType::Linear, gfx::TextureWrapType::Repeat, gfx::TextureWrapType::Repeat});
const std::array<std::array<float, 2>, 2> textureCoordinates = {{{0.0f, 0.0f}, {10.0f, 10.0f}}};
options.size = {static_cast<uint32_t>(image->size.width), static_cast<uint32_t>(image->size.height)};
options.anchor = {0.5f, 0.95f};
options.angleDegrees = 45.0f;
options.scaleWithMap = true;
options.pitchWithMap = false;
interface.setSymbolOptions(options);
// add symbol
interface.addSymbol(position, textureCoordinates);
}
{
using namespace mbgl;
GeometryCoordinate position{static_cast<int16_t>(extent * 1.0f), static_cast<int16_t>(extent * 0.5f)};
// load image
std::shared_ptr<PremultipliedImage> image = std::make_shared<PremultipliedImage>(
mbgl::decodeImage(mbgl::util::read_file(assetsPath + "puck_hat.png")));
// set symbol options
Interface::SymbolOptions options;
options.texture = interface.context.createTexture2D();
options.texture->setImage(image);
options.texture->setSamplerConfiguration(
{gfx::TextureFilterType::Linear, gfx::TextureWrapType::Clamp, gfx::TextureWrapType::Clamp});
options.size = {static_cast<uint32_t>(image->size.width), static_cast<uint32_t>(image->size.height)};
options.anchor = {0.5f, 0.95f};
options.angleDegrees = 45.0f;
options.scaleWithMap = true;
options.pitchWithMap = false;
interface.setSymbolOptions(options);
// add symbol
interface.addSymbol(position);
}
// add polylines using wide vectors using geographic coordinates
{
using namespace mbgl;
// add polyline with geographic coordinates
Interface::LineOptions options = {/*geometry=*/{},
/*blur=*/0.0f,
/*opacity=*/1.0f,
/*gapWidth=*/0.0f,
/*offset=*/0.0f,
/*width=*/12.0f,
/*color=*/{.0f, .0f, .0f, .5f}};
options.geometry.beginCap = style::LineCapType::Square;
options.geometry.endCap = style::LineCapType::Square;
options.geometry.joinType = style::LineJoinType::Bevel;
options.geometry.type = FeatureType::LineString;
interface.setLineOptions(options);
LineString<double> polyline_geo{
// San Francisco
{-122.38186800073211, 37.77466003457463},
{-122.3869373450997, 37.774352128895615},
{-122.38680767979824, 37.773294612880306},
{-122.38476465260224, 37.773350946288765},
{-122.38146223043374, 37.77194168964067},
{-122.6813560305925, 37.666084247570964},
{-122.26765538866474, 37.65037232584494},
{-122.42528413673159, 38.020443518012584},
// Seattle
{-122.34927775216809, 47.62050663596438},
// New York
{-74.04454331829972, 40.6892168305434},
};
interface.addPolyline(polyline_geo, Interface::LineShaderType::WideVector);
}
// add polylines using wide vectors in tile coordinates
{
using namespace mbgl;
// set tile
interface.setTileID({11, 327, 790});
Interface::LineOptions options{/*geometry=*/{},
/*blur=*/0.0f,
/*opacity=*/1.0f,
/*gapWidth=*/0.0f,
/*offset=*/0.0f,
/*width=*/7.0f,
/*color=*/{1.0f, 0, 0, .5f}};
options.geometry.beginCap = style::LineCapType::Round;
options.geometry.endCap = style::LineCapType::Round;
options.geometry.joinType = style::LineJoinType::Round;
// add polyline with tile coordinates
GeometryCollection polyline_tile{
{
// ring 1
{static_cast<int16_t>(extent * 0.1f), static_cast<int16_t>(extent * 0.2f)},
{static_cast<int16_t>(extent * 0.5f), static_cast<int16_t>(extent * 0.5f)},
{static_cast<int16_t>(extent * 0.7f), static_cast<int16_t>(extent * 0.5f)},
{static_cast<int16_t>(extent * 0.5f), static_cast<int16_t>(extent * 1.0f)},
{static_cast<int16_t>(extent * 0.0f), static_cast<int16_t>(extent * 0.5f)},
},
{
// ring 2
{static_cast<int16_t>(extent * 0.1f), static_cast<int16_t>(extent * 0.25f)},
{static_cast<int16_t>(extent * 0.15f), static_cast<int16_t>(extent * 0.5f)},
{static_cast<int16_t>(extent * 0.25f), static_cast<int16_t>(extent * 0.45f)},
},
};
options.geometry.type = FeatureType::Polygon;
interface.setLineOptions(options);
interface.addPolyline(polyline_tile[0], Interface::LineShaderType::WideVector);
interface.addPolyline(polyline_tile[1], Interface::LineShaderType::WideVector);
}
generateGeometry(interface);
loadGeometry(interface);
// finish
interface.finish();
}
void ExampleCustomDrawableStyleLayerHost::generateGeometry(Interface& interface) {
constexpr float itemScale = 10.0f;
const mbgl::LatLng location{37.78, -122.47};
Interface::GeometryOptions options;
// load image
std::shared_ptr<mbgl::PremultipliedImage> image = std::make_shared<mbgl::PremultipliedImage>(
mbgl::decodeImage(mbgl::util::read_file(assetsPath + "puck.png")));
options.texture = interface.context.createTexture2D();
options.texture->setImage(image);
options.texture->setSamplerConfiguration(
{mbgl::gfx::TextureFilterType::Linear, mbgl::gfx::TextureWrapType::Clamp, mbgl::gfx::TextureWrapType::Clamp});
const std::shared_ptr<VertexVector> sharedVertices = std::make_shared<VertexVector>();
VertexVector& vertices = *sharedVertices;
const std::shared_ptr<TriangleIndexVector> sharedIndices = std::make_shared<TriangleIndexVector>();
TriangleIndexVector& indices = *sharedIndices;
const unsigned long numVtxCircumference = 72;
const float bearingStep = 360.0f / static_cast<float>(numVtxCircumference - 1);
vertices.emplace_back(Interface::GeometryVertex{{0.0f, 0.0f, 0.0f}, {0.5f, 0.5f}});
for (unsigned long i = 1; i <= numVtxCircumference; ++i) {
const float rad = mbgl::util::deg2radf((i - 1) * bearingStep);
Interface::GeometryVertex vertex;
vertex.position = {sinf(rad) / 2.0f, cosf(rad) / 2.0f, 0.0f};
vertex.texcoords = {0.5f + vertex.position[0], 0.5f - vertex.position[1]};
vertices.emplace_back(std::move(vertex));
}
for (uint16_t i = 1; i < vertices.elements() - 1; ++i) {
indices.emplace_back(0, i, static_cast<uint16_t>(i + 1));
}
indices.emplace_back(0, static_cast<uint16_t>(vertices.elements() - 1), 1);
interface.setGeometryOptions(options);
interface.setGeometryTweakerCallback([=, frameCount = 0]([[maybe_unused]] mbgl::gfx::Drawable& drawable,
const mbgl::PaintParameters& params,
Interface::GeometryOptions& currentOptions) mutable {
frameCount++;
const mbgl::Point<double>& center = project(location, params.state);
const float scale = itemScale * static_cast<float>(std::pow(2.f, params.state.getZoom())) *
params.pixelsToGLUnits[0];
mbgl::mat4 matrix = mbgl::matrix::identity4();
mbgl::matrix::translate(matrix, matrix, center.x, center.y, 0.0);
mbgl::matrix::rotate_z(matrix, matrix, frameCount * 0.05f);
mbgl::matrix::scale(matrix, matrix, scale, scale, 1.0f);
mbgl::matrix::multiply(currentOptions.matrix, params.transformParams.nearClippedProjMatrix, matrix);
if (frameCount % 100 == 0) {
if (currentOptions.color.g > 0.0f) {
currentOptions.color = mbgl::Color::red();
} else {
currentOptions.color = mbgl::Color::white();
}
}
});
interface.addGeometry(sharedVertices, sharedIndices, false);
}
void ExampleCustomDrawableStyleLayerHost::loadGeometry(Interface& interface) {
constexpr float itemScale = 0.1f;
constexpr std::array<float, 3> itemRotation = {90.0f, 0.0f, 0.0f};
const mbgl::LatLng location{37.76, -122.47};
Interface::GeometryOptions options;
interface.setGeometryTweakerCallback([=]([[maybe_unused]] mbgl::gfx::Drawable& drawable,
const mbgl::PaintParameters& params,
Interface::GeometryOptions& currentOptions) mutable {
const mbgl::Point<double>& center = project(location, params.state);
const float scale = itemScale * static_cast<float>(std::pow(2.f, params.state.getZoom())) *
params.pixelsToGLUnits[0];
mbgl::mat4 matrix = mbgl::matrix::identity4();
mbgl::matrix::translate(matrix, matrix, center.x, center.y, 0.0);
mbgl::matrix::rotate_x(matrix, matrix, mbgl::util::deg2radf(itemRotation[0]));
mbgl::matrix::rotate_y(matrix, matrix, mbgl::util::deg2radf(itemRotation[1]));
mbgl::matrix::rotate_z(matrix, matrix, mbgl::util::deg2radf(itemRotation[2]));
mbgl::matrix::scale(matrix, matrix, scale, scale, scale);
mbgl::matrix::multiply(currentOptions.matrix, params.transformParams.nearClippedProjMatrix, matrix);
});
const std::shared_ptr<VertexVector> sharedVertices = std::make_shared<VertexVector>();
const std::shared_ptr<TriangleIndexVector> sharedIndices = std::make_shared<TriangleIndexVector>();
// importObj(interface, "../../_deps/tinyobjloader-src/models/cube.obj", *sharedVertices, *sharedIndices, options);
importObj(interface, assetsPath + "sphere.obj", *sharedVertices, *sharedIndices, options);
interface.setGeometryOptions(options);
interface.addGeometry(sharedVertices, sharedIndices, true);
}
void ExampleCustomDrawableStyleLayerHost::importObj(Interface& interface,
const std::string& filename,
VertexVector& vertices,
TriangleIndexVector& indices,
Interface::GeometryOptions& options) {
tinyobj::ObjReaderConfig readerConfig;
readerConfig.triangulate = true;
readerConfig.vertex_color = false;
tinyobj::ObjReader reader;
if (!reader.ParseFromFile(filename, readerConfig)) {
if (!reader.Error().empty()) {
mbgl::Log::Error(mbgl::Event::General, reader.Error());
}
assert(false);
throw std::runtime_error(std::string("Cannot read obj file ") + filename);
}
if (!reader.Warning().empty()) {
mbgl::Log::Error(mbgl::Event::General, reader.Warning());
}
const tinyobj::attrib_t& attributes = reader.GetAttrib();
const std::vector<tinyobj::shape_t>& shapes = reader.GetShapes();
if (attributes.texcoords.empty()) {
options.color = mbgl::Color::green();
} else {
// TODO parse material
options.texture = createCheckerboardTexture(interface, 32, 32, 40, {255, 255, 255, 255}, {0, 0, 0, 255});
}
for (const auto& shape : shapes) {
const auto shapeIndexStart = static_cast<uint16_t>(indices.elements());
for (uint16_t face = 0; face < shape.mesh.indices.size(); face += 3) {
for (size_t i = 0; i < 3; ++i) {
const tinyobj::index_t index = shape.mesh.indices[face + i];
Interface::GeometryVertex vertex = {};
std::copy(attributes.vertices.begin() + vertex.position.size() * index.vertex_index,
attributes.vertices.begin() + vertex.position.size() * (index.vertex_index + 1),
vertex.position.begin());
if (!attributes.texcoords.empty()) {
std::copy(attributes.texcoords.begin() + vertex.texcoords.size() * index.texcoord_index,
attributes.texcoords.begin() + vertex.texcoords.size() * (index.texcoord_index + 1),
vertex.texcoords.begin());
}
vertices.emplace_back(std::move(vertex));
}
indices.emplace_back(shapeIndexStart + face, shapeIndexStart + face + 1, shapeIndexStart + face + 2);
}
}
}
mbgl::gfx::Texture2DPtr ExampleCustomDrawableStyleLayerHost::createCheckerboardTexture(
Interface& interface,
uint16_t wb,
uint16_t hb,
uint16_t blockSize,
const std::array<uint8_t, 4>& color1,
const std::array<uint8_t, 4>& color2) {
std::shared_ptr<mbgl::PremultipliedImage> image = std::make_shared<mbgl::PremultipliedImage>(
mbgl::Size(wb * blockSize, hb * blockSize));
constexpr uint8_t pixelSize = sizeof(uint8_t) * 4;
for (uint16_t row = 0; row < hb; ++row) {
for (uint16_t blockRow = 0; blockRow < blockSize; ++blockRow) {
for (uint16_t col = 0; col < wb; ++col) {
for (uint16_t blockCol = 0; blockCol < blockSize; ++blockCol) {
auto index = (row * blockSize + blockRow) * image->stride() +
(col * blockSize + blockCol) * pixelSize;
memcpy(image->data.get() + index, (row + col) % 2 == 0 ? color1.data() : color2.data(), pixelSize);
}
}
}
}
auto texture = interface.context.createTexture2D();
texture->setSamplerConfiguration(
{mbgl::gfx::TextureFilterType::Linear, mbgl::gfx::TextureWrapType::Clamp, mbgl::gfx::TextureWrapType::Clamp});
texture->setImage(std::move(image));
return texture;
}
#endif

View File

@@ -0,0 +1,43 @@
#pragma once
#include <mbgl/style/layers/custom_drawable_layer.hpp>
#if MLN_DRAWABLE_RENDERER
class ExampleCustomDrawableStyleLayerHost : public mbgl::style::CustomDrawableLayerHost {
public:
using VertexVector = mbgl::gfx::VertexVector<Interface::GeometryVertex>;
using TriangleIndexVector = mbgl::gfx::IndexVector<mbgl::gfx::Triangles>;
ExampleCustomDrawableStyleLayerHost(const std::string& assetsPath);
~ExampleCustomDrawableStyleLayerHost();
void initialize() override;
void deinitialize() override;
void update(Interface& interface) override;
protected:
static mbgl::Point<double> project(const mbgl::LatLng& c, const mbgl::TransformState& s);
void createDrawables(Interface& interface);
void generateGeometry(Interface& interface);
void loadGeometry(Interface& interface);
void importObj(Interface& interface,
const std::string& filename,
VertexVector& vertices,
TriangleIndexVector& indices,
Interface::GeometryOptions& options);
mbgl::gfx::Texture2DPtr createCheckerboardTexture(Interface& interface,
uint16_t wb,
uint16_t hb,
uint16_t blockSize,
const std::array<uint8_t, 4>& color1,
const std::array<uint8_t, 4>& color2);
protected:
const std::string assetsPath;
};
#endif

View File

@@ -6,7 +6,7 @@
#include <GLFW/glfw3.h>
#include <GLFW/glfw3native.h>
GLFWMetalBackend::GLFWMetalBackend(GLFWwindow* window_, const bool capFrameRate)
GLFWMetalBackend::GLFWMetalBackend(GLFWwindow* window_, [[maybe_unused]] const bool capFrameRate)
:
window(glfwGetCocoaWindow(window_)),
rendererBackend(window)

View File

@@ -28,6 +28,10 @@
#include <mbgl/util/platform.hpp>
#include <mbgl/util/string.hpp>
#if !defined(MBGL_LAYER_CUSTOM_DISABLE_ALL) && MLN_DRAWABLE_RENDERER
#include "example_custom_drawable_style_layer.hpp"
#endif
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4244)
@@ -66,7 +70,7 @@ using namespace std::numbers;
#ifdef ENABLE_LOCATION_INDICATOR
namespace {
const std::string mbglPuckAssetsPath{MAPBOX_PUCK_ASSETS_PATH};
const std::string mbglPuckAssetsPath{MLN_ASSETS_PATH};
mbgl::Color premultiply(mbgl::Color c) {
c.r *= c.a;
@@ -366,6 +370,9 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action,
case GLFW_KEY_C:
view->clearAnnotations();
break;
case GLFW_KEY_V:
view->toggleCustomDrawableStyle();
break;
case GLFW_KEY_I:
view->resetDatabaseCallback();
break;
@@ -823,6 +830,23 @@ void GLFWView::popAnnotation() {
annotationIDs.pop_back();
}
void GLFWView::toggleCustomDrawableStyle() {
#if !defined(MBGL_LAYER_CUSTOM_DISABLE_ALL) && MLN_DRAWABLE_RENDERER
auto &style = map->getStyle();
const std::string identifier = "ExampleCustomDrawableStyleLayer";
const auto &existingLayer = style.getLayer(identifier);
if (!existingLayer) {
style.addLayer(std::make_unique<mbgl::style::CustomDrawableLayer>(
identifier, std::make_unique<ExampleCustomDrawableStyleLayerHost>(MLN_ASSETS_PATH)));
} else {
style.removeLayer(identifier);
}
#endif
}
void GLFWView::makeSnapshot(bool withOverlay) {
MLN_TRACE_FUNC();

View File

@@ -113,6 +113,7 @@ private:
void clearAnnotations();
void popAnnotation();
void toggleCustomDrawableStyle();
void makeSnapshot(bool withOverlay = false);
mbgl::AnnotationIDs annotationIDs;

View File

@@ -0,0 +1,11 @@
layout (std140) uniform CustomGeometryDrawableUBO {
mat4 u_matrix;
vec4 u_color;
};
in vec2 frag_uv;
uniform sampler2D u_image;
void main() {
fragColor = texture(u_image, frag_uv) * u_color;
}

View File

@@ -0,0 +1,14 @@
layout (std140) uniform CustomGeometryDrawableUBO {
mat4 u_matrix;
vec4 u_color;
};
layout(location = 0) in vec3 a_pos;
layout(location = 1) in vec2 a_uv;
out vec2 frag_uv;
void main() {
frag_uv = a_uv;
gl_Position = u_matrix * vec4(a_pos, 1.0);
}

View File

@@ -0,0 +1,8 @@
layout (std140) uniform LocationIndicatorDrawableUBO {
mat4 u_matrix;
vec4 u_color;
};
void main() {
fragColor = u_color;
}

View File

@@ -0,0 +1,10 @@
layout (std140) uniform LocationIndicatorDrawableUBO {
mat4 u_matrix;
vec4 u_color;
};
layout(location = 0) in vec2 a_pos;
void main() {
gl_Position = u_matrix * vec4(a_pos, 0.0, 1.0);
}

View File

@@ -0,0 +1,11 @@
layout (std140) uniform LocationIndicatorDrawableUBO {
mat4 u_matrix;
vec4 u_color;
};
in vec2 frag_uv;
uniform sampler2D u_image;
void main() {
fragColor = texture(u_image, frag_uv);
}

View File

@@ -0,0 +1,14 @@
layout (std140) uniform LocationIndicatorDrawableUBO {
mat4 u_matrix;
vec4 u_color;
};
layout(location = 0) in vec2 a_pos;
layout(location = 1) in vec2 a_uv;
out vec2 frag_uv;
void main() {
frag_uv = a_uv;
gl_Position = u_matrix * vec4(a_pos, 0.0, 1.0);
}

View File

@@ -34,6 +34,13 @@
"glsl_frag": "drawable.collision_circle.fragment.glsl",
"uses_ubos": true
},
{
"name": "CustomGeometryShader",
"header": "drawable_custom_geometry",
"glsl_vert": "drawable.custom_geometry.vertex.glsl",
"glsl_frag": "drawable.custom_geometry.fragment.glsl",
"uses_ubos": true
},
{
"name": "CustomSymbolIconShader",
"header": "drawable_custom_symbol_icon",
@@ -149,15 +156,15 @@
{
"name": "LocationIndicatorShader",
"header": "drawable_location_indicator",
"glsl_vert": "_empty.glsl",
"glsl_frag": "_empty.glsl",
"glsl_vert": "drawable.location_indicator.vertex.glsl",
"glsl_frag": "drawable.location_indicator.fragment.glsl",
"uses_ubos": true
},
{
"name": "LocationIndicatorTexturedShader",
"header": "drawable_location_indicator_textured",
"glsl_vert": "_empty.glsl",
"glsl_frag": "_empty.glsl",
"glsl_vert": "drawable.location_indicator_textured.vertex.glsl",
"glsl_frag": "drawable.location_indicator_textured.fragment.glsl",
"uses_ubos": true
},
{

View File

@@ -5,8 +5,8 @@
#include <mbgl/gfx/drawable_impl.hpp>
#include <mbgl/gfx/index_vector.hpp>
#include <mbgl/gfx/types.hpp>
#include <mbgl/renderer/render_pass.hpp>
#include <mbgl/renderer/render_tile.hpp>
#include <mbgl/renderer/render_pass.hpp>
namespace mbgl {
namespace gfx {
@@ -24,7 +24,7 @@ struct Drawable::Impl {
Drawable::Drawable(std::string name_)
: name(name_),
renderPass(RenderPass::Opaque),
renderPass(mbgl::RenderPass::Opaque),
depthType(DepthMaskType::ReadOnly),
impl(std::make_unique<Impl>()) {}

View File

@@ -620,6 +620,10 @@ gfx::UniformBufferPtr Context::createUniformBuffer(const void* data,
return std::make_shared<gl::UniformBufferGL>(data, size, *uboAllocator);
}
gfx::UniqueUniformBufferArray Context::createLayerUniformBufferArray() {
return std::make_unique<UniformBufferArrayGL>();
}
gfx::ShaderProgramBasePtr Context::getGenericShader(gfx::ShaderRegistry& shaders, const std::string& name) {
MLN_TRACE_FUNC();

View File

@@ -125,6 +125,8 @@ public:
bool persistent = false,
bool ssbo = false) override;
gfx::UniqueUniformBufferArray createLayerUniformBufferArray() override;
gfx::ShaderProgramBasePtr getGenericShader(gfx::ShaderRegistry&, const std::string& name) override;
TileLayerGroupPtr createTileLayerGroup(int32_t layerIndex, std::size_t initialCapacity, std::string name) override;

View File

@@ -115,6 +115,11 @@ void TileLayerGroupGL::render(RenderOrchestrator&, PaintParameters& parameters)
const auto debugGroupTile = parameters.encoder->createDebugGroup(labelPtr);
#endif
if (!bindUBOs) {
uniformBuffers.bind();
bindUBOs = true;
}
for (const auto& tweaker : drawable.getTweakers()) {
tweaker->execute(drawable, parameters);
}
@@ -126,11 +131,6 @@ void TileLayerGroupGL::render(RenderOrchestrator&, PaintParameters& parameters)
context.setStencilMode(drawable.getEnableStencil() ? stencilMode3d : gfx::StencilMode::disabled());
}
if (!bindUBOs) {
uniformBuffers.bind();
bindUBOs = true;
}
drawable.draw(parameters);
});
@@ -176,16 +176,15 @@ void LayerGroupGL::render(RenderOrchestrator&, PaintParameters& parameters) {
#if !defined(NDEBUG)
const auto debugGroup = parameters.encoder->createDebugGroup(drawable.getName().c_str());
#endif
for (const auto& tweaker : drawable.getTweakers()) {
tweaker->execute(drawable, parameters);
}
if (!bindUBOs) {
uniformBuffers.bind();
bindUBOs = true;
}
for (const auto& tweaker : drawable.getTweakers()) {
tweaker->execute(drawable, parameters);
}
drawable.draw(parameters);
});

View File

@@ -125,6 +125,7 @@ void RendererBackend::initShaders(gfx::ShaderRegistry& shaders, const ProgramPar
shaders::BuiltIn::CircleShader,
shaders::BuiltIn::CollisionBoxShader,
shaders::BuiltIn::CollisionCircleShader,
shaders::BuiltIn::CustomGeometryShader,
shaders::BuiltIn::CustomSymbolIconShader,
shaders::BuiltIn::DebugShader,
shaders::BuiltIn::FillShader,
@@ -142,6 +143,8 @@ void RendererBackend::initShaders(gfx::ShaderRegistry& shaders, const ProgramPar
shaders::BuiltIn::LineGradientShader,
shaders::BuiltIn::LinePatternShader,
shaders::BuiltIn::LineSDFShader,
shaders::BuiltIn::LocationIndicatorShader,
shaders::BuiltIn::LocationIndicatorTexturedShader,
shaders::BuiltIn::RasterShader,
shaders::BuiltIn::SymbolIconShader,
shaders::BuiltIn::SymbolSDFIconShader,

View File

@@ -204,6 +204,10 @@ gfx::UniformBufferPtr Context::createUniformBuffer(const void* data, std::size_t
createBuffer(data, size, gfx::BufferUsageType::StaticDraw, /*isIndexBuffer=*/false, persistent));
}
UniqueUniformBufferArray Context::createLayerUniformBufferArray() {
return std::make_unique<UniformBufferArray>();
}
gfx::ShaderProgramBasePtr Context::getGenericShader(gfx::ShaderRegistry& shaders, const std::string& name) {
const auto shaderGroup = shaders.getShaderGroup(name);
auto shader = shaderGroup ? shaderGroup->getOrCreateShader(*this, {}) : gfx::ShaderProgramBasePtr{};
@@ -226,7 +230,7 @@ RenderTargetPtr Context::createRenderTarget(const Size size, const gfx::TextureC
return std::make_shared<RenderTarget>(*this, size, type);
}
void Context::resetState(gfx::DepthMode depthMode, gfx::ColorMode colorMode) {}
void Context::resetState(gfx::DepthMode, gfx::ColorMode) {}
bool Context::emplaceOrUpdateUniformBuffer(gfx::UniformBufferPtr& buffer,
const void* data,
@@ -459,7 +463,7 @@ std::unique_ptr<gfx::TextureResource> Context::createTextureResource(Size,
return nullptr;
}
std::unique_ptr<gfx::RenderbufferResource> Context::createRenderbufferResource(gfx::RenderbufferPixelType, Size size) {
std::unique_ptr<gfx::RenderbufferResource> Context::createRenderbufferResource(gfx::RenderbufferPixelType, Size) {
return std::make_unique<RenderbufferResource>();
}
@@ -475,7 +479,7 @@ gfx::VertexAttributeArrayPtr Context::createVertexAttributeArray() const {
#if !defined(NDEBUG)
void Context::visualizeStencilBuffer() {}
void Context::visualizeDepthBuffer(float depthRangeSize) {}
void Context::visualizeDepthBuffer(float) {}
#endif // !defined(NDEBUG)
void Context::clearStencilBuffer(int32_t) {
@@ -625,7 +629,7 @@ MTLDepthStencilStatePtr Context::makeDepthStencilState(const gfx::DepthMode& dep
void Context::bindGlobalUniformBuffers(gfx::RenderPass& renderPass) const noexcept {
auto& mtlRenderPass = static_cast<mtl::RenderPass&>(renderPass);
globalUniformBuffers.bind(mtlRenderPass);
globalUniformBuffers.bindMtl(mtlRenderPass);
}
} // namespace mtl

View File

@@ -316,7 +316,6 @@ void Drawable::draw(PaintParameters& parameters) const {
}
}
impl->uniformBuffers.unbind(renderPass);
unbindTextures(renderPass);
unbindAttributes(renderPass);
}

View File

@@ -51,21 +51,17 @@ void LayerGroup::render(RenderOrchestrator&, PaintParameters& parameters) {
return;
}
if (!bindUBOs) {
uniformBuffers.bindMtl(renderPass);
bindUBOs = true;
}
for (const auto& tweaker : drawable.getTweakers()) {
tweaker->execute(drawable, parameters);
}
if (!bindUBOs) {
uniformBuffers.bind(renderPass);
bindUBOs = true;
}
drawable.draw(parameters);
});
if (bindUBOs) {
uniformBuffers.unbind(renderPass);
}
}
} // namespace mtl

View File

@@ -15,6 +15,7 @@
#include <mbgl/shaders/mtl/circle.hpp>
#include <mbgl/shaders/mtl/clipping_mask.hpp>
#include <mbgl/shaders/mtl/collision.hpp>
#include <mbgl/shaders/mtl/custom_geometry.hpp>
#include <mbgl/shaders/mtl/custom_symbol_icon.hpp>
#include <mbgl/shaders/mtl/debug.hpp>
#include <mbgl/shaders/mtl/fill.hpp>
@@ -24,6 +25,7 @@
#include <mbgl/shaders/mtl/hillshade.hpp>
#include <mbgl/shaders/mtl/hillshade_prepare.hpp>
#include <mbgl/shaders/mtl/line.hpp>
#include <mbgl/shaders/mtl/location_indicator.hpp>
#include <mbgl/shaders/mtl/raster.hpp>
#include <mbgl/shaders/mtl/symbol.hpp>
#include <mbgl/shaders/mtl/widevector.hpp>
@@ -57,21 +59,21 @@ PremultipliedImage RendererBackend::readFramebuffer(const Size& size) {
return PremultipliedImage(size);
}
void RendererBackend::assumeFramebufferBinding(const mtl::FramebufferID fbo) {}
void RendererBackend::assumeFramebufferBinding(const mtl::FramebufferID) {}
void RendererBackend::assumeViewport(int32_t x, int32_t y, const Size& size) {}
void RendererBackend::assumeViewport(int32_t, int32_t, const Size&) {}
void RendererBackend::assumeScissorTest(bool enabled) {}
void RendererBackend::assumeScissorTest(bool) {}
bool RendererBackend::implicitFramebufferBound() {
return false;
}
void RendererBackend::setFramebufferBinding(const mtl::FramebufferID fbo) {}
void RendererBackend::setFramebufferBinding(const mtl::FramebufferID) {}
void RendererBackend::setViewport(int32_t x, int32_t y, const Size& size) {}
void RendererBackend::setViewport(int32_t, int32_t, const Size&) {}
void RendererBackend::setScissorTest(bool enabled) {}
void RendererBackend::setScissorTest(bool) {}
/// @brief Register a list of types with a shader registry instance
/// @tparam ...ShaderID Pack of BuiltIn:: shader IDs
@@ -105,6 +107,7 @@ void RendererBackend::initShaders(gfx::ShaderRegistry& shaders, const ProgramPar
shaders::BuiltIn::ClippingMaskProgram,
shaders::BuiltIn::CollisionBoxShader,
shaders::BuiltIn::CollisionCircleShader,
shaders::BuiltIn::CustomGeometryShader,
shaders::BuiltIn::CustomSymbolIconShader,
shaders::BuiltIn::DebugShader,
shaders::BuiltIn::FillShader,
@@ -122,6 +125,8 @@ void RendererBackend::initShaders(gfx::ShaderRegistry& shaders, const ProgramPar
shaders::BuiltIn::LineGradientShader,
shaders::BuiltIn::LineSDFShader,
shaders::BuiltIn::LinePatternShader,
shaders::BuiltIn::LocationIndicatorShader,
shaders::BuiltIn::LocationIndicatorTexturedShader,
shaders::BuiltIn::RasterShader,
shaders::BuiltIn::SymbolIconShader,
shaders::BuiltIn::SymbolSDFIconShader,

View File

@@ -125,6 +125,11 @@ void TileLayerGroup::render(RenderOrchestrator&, PaintParameters& parameters) {
return;
}
if (!bindUBOs) {
uniformBuffers.bindMtl(renderPass);
bindUBOs = true;
}
for (const auto& tweaker : drawable.getTweakers()) {
tweaker->execute(drawable, parameters);
}
@@ -137,17 +142,8 @@ void TileLayerGroup::render(RenderOrchestrator&, PaintParameters& parameters) {
renderPass.setDepthStencilState(state);
}
if (!bindUBOs) {
uniformBuffers.bind(renderPass);
bindUBOs = true;
}
drawable.draw(parameters);
});
if (bindUBOs) {
uniformBuffers.unbind(renderPass);
}
}
} // namespace mtl

View File

@@ -39,7 +39,7 @@ void UniformBuffer::update(const void* data, std::size_t dataSize) {
buffer.update(data, dataSize, /*offset=*/0);
}
void UniformBufferArray::bind(RenderPass& renderPass) const noexcept {
void UniformBufferArray::bindMtl(RenderPass& renderPass) const noexcept {
for (size_t id = 0; id < allocatedSize(); id++) {
const auto& uniformBuffer = get(id);
if (!uniformBuffer) continue;
@@ -54,5 +54,9 @@ void UniformBufferArray::bind(RenderPass& renderPass) const noexcept {
}
}
void UniformBufferArray::bind(gfx::RenderPass& renderPass) {
bindMtl(static_cast<RenderPass&>(renderPass));
}
} // namespace mtl
} // namespace mbgl

View File

@@ -81,30 +81,27 @@ void UploadPass::updateIndexBufferResource(gfx::IndexBufferResource& resource, c
static_cast<IndexBufferResource&>(resource).get().update(data, size, /*offset=*/0);
}
std::unique_ptr<gfx::TextureResource> UploadPass::createTextureResource(const Size size,
const void* data,
gfx::TexturePixelType format,
gfx::TextureChannelDataType type) {
std::unique_ptr<gfx::TextureResource> UploadPass::createTextureResource(const Size,
const void*,
gfx::TexturePixelType,
gfx::TextureChannelDataType) {
assert(false);
throw std::runtime_error("UploadPass::createTextureResource not implemented on Metal!");
}
void UploadPass::updateTextureResource(gfx::TextureResource& resource,
const Size size,
const void* data,
gfx::TexturePixelType format,
gfx::TextureChannelDataType type) {
void UploadPass::updateTextureResource(
gfx::TextureResource&, const Size, const void*, gfx::TexturePixelType, gfx::TextureChannelDataType) {
assert(false);
throw std::runtime_error("UploadPass::updateTextureResource not implemented on Metal!");
}
void UploadPass::updateTextureResourceSub(gfx::TextureResource& resource,
const uint16_t xOffset,
const uint16_t yOffset,
const Size size,
const void* data,
gfx::TexturePixelType format,
gfx::TextureChannelDataType type) {
void UploadPass::updateTextureResourceSub(gfx::TextureResource&,
const uint16_t,
const uint16_t,
const Size,
const void*,
gfx::TexturePixelType,
gfx::TextureChannelDataType) {
assert(false);
throw std::runtime_error("UploadPass::updateTextureResourceSub not implemented on Metal!");
}
@@ -151,10 +148,10 @@ const gfx::UniqueVertexBufferResource& UploadPass::getBuffer(const gfx::VertexVe
}
gfx::AttributeBindingArray UploadPass::buildAttributeBindings(
const std::size_t vertexCount,
const gfx::AttributeDataType vertexType,
const std::size_t vertexAttributeIndex,
const std::vector<std::uint8_t>& vertexData,
[[maybe_unused]] const std::size_t vertexCount,
[[maybe_unused]] const gfx::AttributeDataType vertexType,
[[maybe_unused]] const std::size_t vertexAttributeIndex,
[[maybe_unused]] const std::vector<std::uint8_t>& vertexData,
const gfx::VertexAttributeArray& defaults,
const gfx::VertexAttributeArray& overrides,
const gfx::BufferUsageType usage,
@@ -166,7 +163,7 @@ gfx::AttributeBindingArray UploadPass::buildAttributeBindings(
bindings.resize(defaults.allocatedSize());
// For each attribute in the program, with the corresponding default and optional override...
const auto resolveAttr = [&](const size_t id, auto& default_, auto& override_) -> void {
const auto resolveAttr = [&]([[maybe_unused]] const size_t id, auto& default_, auto& override_) -> void {
auto& effectiveAttr = override_ ? *override_ : default_;
const auto& defaultAttr = static_cast<const VertexAttribute&>(default_);
const auto index = static_cast<std::size_t>(defaultAttr.getIndex());

View File

@@ -42,7 +42,7 @@
#endif
#if !MLN_RENDER_BACKEND_OPENGL
#ifdef MLN_DRAWABLE_LOCATION_INDICATOR
#include <mbgl/gfx/vertex_attribute.hpp>
#include <mbgl/renderer/render_static_data.hpp>
@@ -145,7 +145,7 @@ public:
friend vec2 operator-(const vec2& v1, const vec2& v2) { return {v1.x - v2.x, v1.y - v2.y}; }
};
#if MLN_RENDER_BACKEND_OPENGL
#ifndef MLN_DRAWABLE_LOCATION_INDICATOR
struct Shader {
virtual ~Shader() { release(); }
void release() {
@@ -420,7 +420,7 @@ public:
#endif
#if !MLN_RENDER_BACKEND_OPENGL
#ifdef MLN_DRAWABLE_LOCATION_INDICATOR
struct TextureInfo {
std::shared_ptr<gfx::Texture2D> texture;
std::optional<Immutable<style::Image::Impl>> image;
@@ -485,7 +485,7 @@ public:
}
void release() {
#if MLN_RENDER_BACKEND_OPENGL
#ifndef MLN_DRAWABLE_LOCATION_INDICATOR
if (!simpleShader.program) return;
for (const auto& t : textures) t.second->release();
buffer.release();
@@ -515,7 +515,7 @@ public:
params.puckShadowScale != oldParams.puckShadowScale)
bearingChanged = true; // changes puck geometry but not necessarily the location
if (params.errorRadiusMeters != oldParams.errorRadiusMeters) radiusChanged = true;
#if MLN_RENDER_BACKEND_OPENGL
#ifndef MLN_DRAWABLE_LOCATION_INDICATOR
bearingChanged |= setTextureFromImageID(params.puckImagePath, texPuck, params);
bearingChanged |= setTextureFromImageID(params.puckShadowImagePath, texShadow, params);
bearingChanged |= setTextureFromImageID(params.puckHatImagePath, texPuckHat, params);
@@ -551,7 +551,7 @@ public:
if (!dirtyFeature) return;
dirtyFeature = false;
featureEnvelope->clear();
#if MLN_RENDER_BACKEND_OPENGL
#ifndef MLN_DRAWABLE_LOCATION_INDICATOR
if (!texPuck || !texPuck->isValid()) return;
#else
if (!puckDrawableInfo.textureInfo.texture) return;
@@ -593,7 +593,7 @@ protected:
}
void updateRadius(const mbgl::LocationIndicatorRenderParameters& params) {
#if !MLN_RENDER_BACKEND_OPENGL
#ifdef MLN_DRAWABLE_LOCATION_INDICATOR
auto& circle = circleDrawableInfo.geometry;
circleDrawableInfo.dirty = true;
#endif
@@ -711,7 +711,7 @@ protected:
params.perspectiveCompensation; // Compensation factor for the perspective deformation
// ^ clamping this to 0.8 to avoid growing the puck too much close to the camera.
#if MLN_RENDER_BACKEND_OPENGL
#ifndef MLN_DRAWABLE_LOCATION_INDICATOR
const double shadowRadius = ((texShadow) ? texShadow->width / texShadow->pixelRatio : 0.0) *
params.puckShadowScale * M_SQRT2 * 0.5 *
horizontalScaleFactor; // Technically it's not the radius, but
@@ -756,7 +756,7 @@ protected:
}
}
#if MLN_RENDER_BACKEND_OPENGL
#ifndef MLN_DRAWABLE_LOCATION_INDICATOR
void drawRadius(const mbgl::LocationIndicatorRenderParameters& params) {
if (!(params.errorRadiusMeters > 0.0) ||
(params.errorRadiusColor.a == 0.0 && params.errorRadiusBorderColor.a == 0.0))
@@ -818,7 +818,7 @@ protected:
return s.screenCoordinateToLatLng(flippedPoint, wrapMode);
}
#if MLN_RENDER_BACKEND_OPENGL
#ifndef MLN_DRAWABLE_LOCATION_INDICATOR
bool setTextureFromImageID(const std::string& imagePath,
std::shared_ptr<Texture>& texture,
const mbgl::LocationIndicatorRenderParameters& params) {
@@ -879,7 +879,7 @@ protected:
bool initialized = false;
bool dirtyFeature = true;
#if !MLN_RENDER_BACKEND_OPENGL
#ifdef MLN_DRAWABLE_LOCATION_INDICATOR
public:
struct QuadDrawableInfo {
@@ -1015,7 +1015,7 @@ void RenderLocationIndicatorLayer::populateDynamicRenderFeatureIndex(DynamicFeat
if (!renderImpl->featureEnvelope->empty()) index.insert(renderImpl->feature, renderImpl->featureEnvelope);
}
#if MLN_RENDER_BACKEND_OPENGL
#ifndef MLN_DRAWABLE_LOCATION_INDICATOR
void RenderLocationIndicatorLayer::render(PaintParameters& paintParameters) {
auto& glContext = static_cast<gl::Context&>(paintParameters.context);
@@ -1035,7 +1035,7 @@ void RenderLocationIndicatorLayer::render(PaintParameters& paintParameters) {
}
#endif
#if !MLN_RENDER_BACKEND_OPENGL
#ifdef MLN_DRAWABLE_LOCATION_INDICATOR
void RenderLocationIndicatorLayer::update(gfx::ShaderRegistry& shaders,
gfx::Context& context,
@@ -1092,8 +1092,11 @@ void RenderLocationIndicatorLayer::update(gfx::ShaderRegistry& shaders,
const auto createQuadGeometry = [&](gfx::Drawable& drawable, const auto& geometry) {
auto vertexAttrs = context.createVertexAttributeArray();
drawable.setVertices({}, 4, gfx::AttributeDataType::Float2);
vertexAttrs->set(shaders::idLocationIndicatorPosVertexAttribute, 0, gfx::AttributeDataType::Float2, 4);
if (const auto& attr = vertexAttrs->set(
shaders::idCommonTexVertexAttribute, 0, gfx::AttributeDataType::Float2)) {
shaders::idLocationIndicatorTexVertexAttribute, 0, gfx::AttributeDataType::Float2, 4)) {
const std::array<RenderLocationIndicatorImpl::vec2, 4> texCoords = {
{{0.0f, 1.0f}, {0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}}};
@@ -1125,7 +1128,9 @@ void RenderLocationIndicatorLayer::update(gfx::ShaderRegistry& shaders,
drawable->setName(name);
drawable->setRenderPass(drawPasses);
drawable->setDepthType(gfx::DepthMaskType::ReadWrite);
drawable->setDepthType(gfx::DepthMaskType::ReadOnly);
drawable->setEnableDepth(false);
drawable->setEnableStencil(false);
drawable->setColorMode(drawPasses == RenderPass::Translucent ? gfx::ColorMode::alphaBlended()
: gfx::ColorMode::unblended());
@@ -1146,7 +1151,9 @@ void RenderLocationIndicatorLayer::update(gfx::ShaderRegistry& shaders,
drawable->setName(name);
drawable->setRenderPass(drawPasses);
drawable->setDepthType(gfx::DepthMaskType::ReadWrite);
drawable->setDepthType(gfx::DepthMaskType::ReadOnly);
drawable->setEnableDepth(false);
drawable->setEnableStencil(false);
drawable->setColorMode(drawPasses == RenderPass::Translucent ? gfx::ColorMode::alphaBlended()
: gfx::ColorMode::unblended());
@@ -1240,7 +1247,7 @@ void RenderLocationIndicatorLayer::update(gfx::ShaderRegistry& shaders,
}
auto& circleVertexAttrs = circleDrawable.getVertexAttributes();
if (const auto& attr = circleVertexAttrs->set(shaders::idCommonPosVertexAttribute)) {
if (const auto& attr = circleVertexAttrs->set(shaders::idLocationIndicatorPosVertexAttribute)) {
attr->setSharedRawData(
verts, 0, 0, sizeof(RenderLocationIndicatorImpl::vec2), gfx::AttributeDataType::Float2);
}
@@ -1254,7 +1261,7 @@ void RenderLocationIndicatorLayer::update(gfx::ShaderRegistry& shaders,
auto vertexAttrs = drawable.getVertexAttributes();
if (const auto& attr = vertexAttrs->set(
shaders::idCommonPosVertexAttribute, 0, gfx::AttributeDataType::Float2)) {
shaders::idLocationIndicatorPosVertexAttribute, 0, gfx::AttributeDataType::Float2)) {
auto geoDataPtr = reinterpret_cast<const uint8_t*>(info.geometry.data());
auto geoDataSize = info.geometry.size() * sizeof(RenderLocationIndicatorImpl::vec2);
@@ -1281,7 +1288,7 @@ void RenderLocationIndicatorLayer::update(gfx::ShaderRegistry& shaders,
info.textureInfo.image.reset();
}
drawable.setTexture(info.textureInfo.texture, shaders::idCommonTexture);
drawable.setTexture(info.textureInfo.texture, shaders::idLocationIndicatorTexture);
info.textureInfo.dirty = false;
}
};

View File

@@ -5,6 +5,10 @@
#include <mbgl/style/layers/location_indicator_layer_impl.hpp>
#include <mbgl/style/layers/location_indicator_layer_properties.hpp>
#if !MLN_RENDER_BACKEND_OPENGL
#define MLN_DRAWABLE_LOCATION_INDICATOR
#endif
namespace mbgl {
class RenderLocationIndicatorImpl;
class RenderLocationIndicatorLayer final : public RenderLayer {
@@ -21,7 +25,7 @@ public:
explicit RenderLocationIndicatorLayer(Immutable<style::LocationIndicatorLayer::Impl>);
~RenderLocationIndicatorLayer() override;
#if !MLN_RENDER_BACKEND_OPENGL
#ifdef MLN_DRAWABLE_LOCATION_INDICATOR
void update(gfx::ShaderRegistry &,
gfx::Context &,
const TransformState &,
@@ -38,7 +42,7 @@ private:
void markContextDestroyed() override;
void prepare(const LayerPrepareParameters &) override;
#if MLN_RENDER_BACKEND_OPENGL
#ifndef MLN_DRAWABLE_LOCATION_INDICATOR
void render(PaintParameters &) override;
#endif
@@ -49,7 +53,7 @@ private:
std::unique_ptr<RenderLocationIndicatorImpl> renderImpl;
style::LocationIndicatorPaintProperties::Unevaluated unevaluated;
#if !MLN_RENDER_BACKEND_OPENGL
#ifdef MLN_DRAWABLE_LOCATION_INDICATOR
// Drawable shaders
gfx::ShaderProgramBasePtr quadShader;
gfx::ShaderProgramBasePtr circleShader;

View File

@@ -95,6 +95,20 @@ const std::vector<AttributeInfo> CollisionCircleShaderInfo::attributes = {
};
const std::vector<TextureInfo> CollisionCircleShaderInfo::textures = {};
// Custom Geometry
using CustomGeometryInfo = ShaderInfo<BuiltIn::CustomGeometryShader, gfx::Backend::Type::OpenGL>;
const std::vector<UniformBlockInfo> CustomGeometryInfo::uniformBlocks = {
UniformBlockInfo{"CustomGeometryDrawableUBO", idCustomGeometryDrawableUBO},
};
const std::vector<AttributeInfo> CustomGeometryInfo::attributes = {
AttributeInfo{"a_pos", idCustomGeometryPosVertexAttribute},
AttributeInfo{"a_uv", idCustomGeometryTexVertexAttribute},
};
const std::vector<TextureInfo> CustomGeometryInfo::textures = {
TextureInfo{"u_image", idCustomGeometryTexture},
};
// Custom Symbol Icon
using CustomSymbolIconShaderInfo = ShaderInfo<BuiltIn::CustomSymbolIconShader, gfx::Backend::Type::OpenGL>;
@@ -322,6 +336,30 @@ const std::vector<AttributeInfo> LineShaderInfo::attributes = {
};
const std::vector<TextureInfo> LineShaderInfo::textures = {};
// Location Indicator
using LocationIndicatorInfo = ShaderInfo<BuiltIn::LocationIndicatorShader, gfx::Backend::Type::OpenGL>;
const std::vector<UniformBlockInfo> LocationIndicatorInfo::uniformBlocks = {
UniformBlockInfo{"LocationIndicatorDrawableUBO", idLocationIndicatorDrawableUBO},
};
const std::vector<AttributeInfo> LocationIndicatorInfo::attributes = {
AttributeInfo{"a_pos", idLocationIndicatorPosVertexAttribute},
};
const std::vector<TextureInfo> LocationIndicatorInfo::textures = {};
using LocationIndicatorTexturedInfo = ShaderInfo<BuiltIn::LocationIndicatorTexturedShader, gfx::Backend::Type::OpenGL>;
const std::vector<UniformBlockInfo> LocationIndicatorTexturedInfo::uniformBlocks = {
UniformBlockInfo{"LocationIndicatorDrawableUBO", idLocationIndicatorDrawableUBO},
};
const std::vector<AttributeInfo> LocationIndicatorTexturedInfo::attributes = {
AttributeInfo{"a_pos", idLocationIndicatorPosVertexAttribute},
AttributeInfo{"a_uv", idLocationIndicatorTexVertexAttribute},
};
const std::vector<TextureInfo> LocationIndicatorTexturedInfo::textures = {
TextureInfo{"u_image", idLocationIndicatorTexture},
};
// Line Gradient
using LineGradientShaderInfo = ShaderInfo<BuiltIn::LineGradientShader, gfx::Backend::Type::OpenGL>;

View File

@@ -0,0 +1,17 @@
#include <mbgl/shaders/mtl/custom_geometry.hpp>
#include <mbgl/shaders/shader_defines.hpp>
namespace mbgl {
namespace shaders {
using CustomGeometryShaderSource = ShaderSource<BuiltIn::CustomGeometryShader, gfx::Backend::Type::Metal>;
const std::array<AttributeInfo, 2> CustomGeometryShaderSource::attributes = {
AttributeInfo{customGeometryUBOCount + 0, gfx::AttributeDataType::Float3, idCustomGeometryPosVertexAttribute},
AttributeInfo{customGeometryUBOCount + 1, gfx::AttributeDataType::Float2, idCustomGeometryTexVertexAttribute},
};
const std::array<TextureInfo, 1> CustomGeometryShaderSource::textures = {TextureInfo{0, idCustomGeometryTexture}};
} // namespace shaders
} // namespace mbgl

View File

@@ -0,0 +1,25 @@
#include <mbgl/shaders/mtl/location_indicator.hpp>
#include <mbgl/shaders/shader_defines.hpp>
namespace mbgl {
namespace shaders {
using LocationIndicatorShaderSource = ShaderSource<BuiltIn::LocationIndicatorShader, gfx::Backend::Type::Metal>;
const std::array<AttributeInfo, 1> LocationIndicatorShaderSource::attributes = {AttributeInfo{
locationIndicatorUBOCount + 0, gfx::AttributeDataType::Float2, idLocationIndicatorPosVertexAttribute}};
using LocationIndicatorTexturedShaderSource =
ShaderSource<BuiltIn::LocationIndicatorTexturedShader, gfx::Backend::Type::Metal>;
const std::array<AttributeInfo, 2> LocationIndicatorTexturedShaderSource::attributes = {
AttributeInfo{locationIndicatorUBOCount + 0, gfx::AttributeDataType::Float2, idLocationIndicatorPosVertexAttribute},
AttributeInfo{locationIndicatorUBOCount + 1, gfx::AttributeDataType::Float2, idLocationIndicatorTexVertexAttribute},
};
const std::array<TextureInfo, 1> LocationIndicatorTexturedShaderSource::textures = {
TextureInfo{0, idLocationIndicatorTexture},
};
} // namespace shaders
} // namespace mbgl

View File

@@ -0,0 +1,20 @@
#include <mbgl/shaders/vulkan/custom_geometry.hpp>
#include <mbgl/shaders/shader_defines.hpp>
#include <mbgl/shaders/custom_geometry_ubo.hpp>
namespace mbgl {
namespace shaders {
using CustomGeometryShaderSource = ShaderSource<BuiltIn::CustomGeometryShader, gfx::Backend::Type::Vulkan>;
const std::array<AttributeInfo, 2> CustomGeometryShaderSource::attributes = {
AttributeInfo{0, gfx::AttributeDataType::Float3, idCustomGeometryPosVertexAttribute},
AttributeInfo{1, gfx::AttributeDataType::Float2, idCustomGeometryTexVertexAttribute},
};
const std::array<TextureInfo, 1> CustomGeometryShaderSource::textures = {
TextureInfo{0, idCustomGeometryTexture},
};
} // namespace shaders
} // namespace mbgl

View File

@@ -11,7 +11,7 @@ namespace shaders {
using LocationIndicatorShaderSource = ShaderSource<BuiltIn::LocationIndicatorShader, gfx::Backend::Type::Vulkan>;
const std::array<AttributeInfo, 1> LocationIndicatorShaderSource::attributes = {
AttributeInfo{0, gfx::AttributeDataType::Float2, idCommonPosVertexAttribute},
AttributeInfo{0, gfx::AttributeDataType::Float2, idLocationIndicatorPosVertexAttribute},
};
const std::array<TextureInfo, 0> LocationIndicatorShaderSource::textures = {};
@@ -22,11 +22,11 @@ using LocationIndicatorShaderTexturedSource =
ShaderSource<BuiltIn::LocationIndicatorTexturedShader, gfx::Backend::Type::Vulkan>;
const std::array<AttributeInfo, 2> LocationIndicatorShaderTexturedSource::attributes = {
AttributeInfo{0, gfx::AttributeDataType::Float2, idCommonPosVertexAttribute},
AttributeInfo{1, gfx::AttributeDataType::Float2, idCommonTexVertexAttribute},
AttributeInfo{0, gfx::AttributeDataType::Float2, idLocationIndicatorPosVertexAttribute},
AttributeInfo{1, gfx::AttributeDataType::Float2, idLocationIndicatorTexVertexAttribute},
};
const std::array<TextureInfo, 1> LocationIndicatorShaderTexturedSource::textures = {
TextureInfo{0, idCommonTexture},
TextureInfo{0, idLocationIndicatorTexture},
};
} // namespace shaders

View File

@@ -26,9 +26,11 @@
#include <mbgl/gfx/renderable.hpp>
#include <mbgl/gfx/renderer_backend.hpp>
#include <mbgl/shaders/widevector_ubo.hpp>
#include <mbgl/shaders/custom_geometry_ubo.hpp>
#include <mbgl/util/projection.hpp>
#include <mbgl/util/mat4.hpp>
#include <mbgl/renderer/render_tile.hpp>
#include <mbgl/gfx/uniform_buffer.hpp>
#include <cmath>
@@ -89,8 +91,11 @@ const LayerTypeInfo* CustomDrawableLayer::Impl::staticTypeInfo() noexcept {
class LineDrawableTweaker : public gfx::DrawableTweaker {
public:
LineDrawableTweaker(const shaders::LineEvaluatedPropsUBO& properties)
: propsUBO(properties) {}
LineDrawableTweaker(const CustomDrawableLayerHost::Interface::LineOptions& options_,
CustomDrawableLayerHost::Interface::LineTweakerCallback&& callback_)
: options(options_),
callback(callback_) {}
~LineDrawableTweaker() override = default;
void init(gfx::Drawable&) override {}
@@ -100,14 +105,55 @@ public:
return;
}
if (callback) {
callback(drawable, parameters, options);
}
#if MLN_UBO_CONSOLIDATION
if (!layerUniforms) {
layerUniforms = parameters.context.createLayerUniformBufferArray();
}
#endif
const UnwrappedTileID tileID = drawable.getTileID()->toUnwrapped();
const auto zoom = parameters.state.getZoom();
mat4 tileMatrix;
parameters.state.matrixFor(/*out*/ tileMatrix, tileID);
const auto matrix = LayerTweaker::getTileMatrix(
tileID, parameters, {{0, 0}}, style::TranslateAnchorType::Viewport, false, false, drawable, false);
const shaders::LineEvaluatedPropsUBO propsUBO = {options.color,
options.blur,
options.opacity,
options.gapWidth,
options.offset,
options.width,
/*floorwidth=*/0.0f,
LineExpressionMask::None,
0};
// We would need to set up `idLineExpressionUBO` if the expression mask isn't empty
assert(propsUBO.expressionMask == LineExpressionMask::None);
if (!expressionUniformBuffer) {
const LineExpressionUBO exprUBO = {
/* .color = */ nullptr,
/* .blur = */ nullptr,
/* .opacity = */ nullptr,
/* .gapwidth = */ nullptr,
/* .offset = */ nullptr,
/* .width = */ nullptr,
/* .floorWidth = */ nullptr,
};
expressionUniformBuffer = parameters.context.createUniformBuffer(&exprUBO, sizeof(exprUBO));
#if MLN_UBO_CONSOLIDATION
layerUniforms->set(idLineExpressionUBO, expressionUniformBuffer);
#else
auto& drawableUniforms = drawable.mutableUniformBuffers();
drawableUniforms.set(idLineExpressionUBO, expressionUniformBuffer);
#endif
}
#if MLN_UBO_CONSOLIDATION
shaders::LineDrawableUnionUBO drawableUBO;
drawableUBO.lineDrawableUBO = {
@@ -125,33 +171,45 @@ public:
/* .width_t = */ 0.f,
/* .pad1 = */ 0
};
#if MLN_UBO_CONSOLIDATION
if (!drawableUniformBuffer) {
drawableUniformBuffer = parameters.context.createUniformBuffer(
&drawableUBO, sizeof(drawableUBO), false, true);
layerUniforms->set(idLineDrawableUBO, drawableUniformBuffer);
drawable.setUBOIndex(0);
} else {
drawableUniformBuffer->update(&drawableUBO, sizeof(drawableUBO));
}
layerUniforms->createOrUpdate(idLineEvaluatedPropsUBO, &propsUBO, sizeof(propsUBO), parameters.context);
layerUniforms->bind(*parameters.renderPass);
#else
auto& drawableUniforms = drawable.mutableUniformBuffers();
drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, parameters.context, true);
drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, parameters.context);
drawableUniforms.createOrUpdate(idLineEvaluatedPropsUBO, &propsUBO, parameters.context);
// We would need to set up `idLineExpressionUBO` if the expression mask isn't empty
assert(propsUBO.expressionMask == LineExpressionMask::None);
const LineExpressionUBO exprUBO = {
/* .color = */ nullptr,
/* .blur = */ nullptr,
/* .opacity = */ nullptr,
/* .gapwidth = */ nullptr,
/* .offset = */ nullptr,
/* .width = */ nullptr,
/* .floorWidth = */ nullptr,
};
drawableUniforms.createOrUpdate(idLineExpressionUBO, &exprUBO, parameters.context);
#endif
};
private:
shaders::LineEvaluatedPropsUBO propsUBO;
CustomDrawableLayerHost::Interface::LineOptions options;
CustomDrawableLayerHost::Interface::LineTweakerCallback callback;
#if MLN_UBO_CONSOLIDATION
gfx::UniqueUniformBufferArray layerUniforms;
gfx::UniformBufferPtr drawableUniformBuffer;
#endif
gfx::UniformBufferPtr expressionUniformBuffer;
};
class WideVectorDrawableTweaker : public gfx::DrawableTweaker {
public:
WideVectorDrawableTweaker(const CustomDrawableLayerHost::Interface::LineOptions& options_)
: options(options_) {}
WideVectorDrawableTweaker(const CustomDrawableLayerHost::Interface::LineOptions& options_,
CustomDrawableLayerHost::Interface::LineTweakerCallback&& callback_)
: options(options_),
callback(callback_) {}
void init(gfx::Drawable&) override {}
@@ -160,6 +218,10 @@ public:
return;
}
if (callback) {
callback(drawable, parameters, options);
}
const UnwrappedTileID tileID = drawable.getTileID()->toUnwrapped();
mat4 tileMatrix;
@@ -211,13 +273,16 @@ public:
private:
CustomDrawableLayerHost::Interface::LineOptions options;
CustomDrawableLayerHost::Interface::LineTweakerCallback callback;
};
class FillDrawableTweaker : public gfx::DrawableTweaker {
public:
FillDrawableTweaker(const Color& color_, float opacity_)
: color(color_),
opacity(opacity_) {}
FillDrawableTweaker(const CustomDrawableLayerHost::Interface::FillOptions& options_,
CustomDrawableLayerHost::Interface::FillTweakerCallback&& callback_)
: options(options_),
callback(callback_) {}
~FillDrawableTweaker() override = default;
void init(gfx::Drawable&) override {}
@@ -227,15 +292,29 @@ public:
return;
}
const UnwrappedTileID tileID = drawable.getTileID()->toUnwrapped();
mat4 tileMatrix;
parameters.state.matrixFor(/*out*/ tileMatrix, tileID);
if (callback) {
callback(drawable, parameters, options);
}
#if MLN_UBO_CONSOLIDATION
if (!layerUniforms) {
layerUniforms = parameters.context.createLayerUniformBufferArray();
}
#endif
const UnwrappedTileID tileID = drawable.getTileID()->toUnwrapped();
const auto matrix = LayerTweaker::getTileMatrix(
tileID, parameters, {{0, 0}}, style::TranslateAnchorType::Viewport, false, false, drawable, false);
const shaders::FillEvaluatedPropsUBO propsUBO = {/* .color = */ options.color,
/* .outline_color = */ Color::white(),
/* .opacity = */ options.opacity,
/* .fade = */ 0.f,
/* .from_scale = */ 0.f,
/* .to_scale = */ 0.f};
#if MLN_UBO_CONSOLIDATION
shaders::FillDrawableUnionUBO drawableUBO;
FillDrawableUnionUBO drawableUBO;
drawableUBO.fillDrawableUBO = {
#else
const shaders::FillDrawableUBO drawableUBO = {
@@ -248,26 +327,42 @@ public:
/* .pad2 = */ 0
};
const shaders::FillEvaluatedPropsUBO propsUBO = {/* .color = */ color,
/* .outline_color = */ Color::white(),
/* .opacity = */ opacity,
/* .fade = */ 0.f,
/* .from_scale = */ 0.f,
/* .to_scale = */ 0.f};
#if MLN_UBO_CONSOLIDATION
if (!drawableUniformBuffer) {
drawableUniformBuffer = parameters.context.createUniformBuffer(
&drawableUBO, sizeof(drawableUBO), false, true);
layerUniforms->set(idFillDrawableUBO, drawableUniformBuffer);
drawable.setUBOIndex(0);
} else {
drawableUniformBuffer->update(&drawableUBO, sizeof(drawableUBO));
}
layerUniforms->createOrUpdate(idFillEvaluatedPropsUBO, &propsUBO, sizeof(propsUBO), parameters.context);
layerUniforms->bind(*parameters.renderPass);
#else
auto& drawableUniforms = drawable.mutableUniformBuffers();
drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, parameters.context);
drawableUniforms.createOrUpdate(idFillEvaluatedPropsUBO, &propsUBO, parameters.context);
#endif
};
private:
Color color;
float opacity;
CustomDrawableLayerHost::Interface::FillOptions options;
CustomDrawableLayerHost::Interface::FillTweakerCallback callback;
#if MLN_UBO_CONSOLIDATION
gfx::UniqueUniformBufferArray layerUniforms;
gfx::UniformBufferPtr drawableUniformBuffer;
#endif
};
class SymbolDrawableTweaker : public gfx::DrawableTweaker {
public:
SymbolDrawableTweaker(const CustomDrawableLayerHost::Interface::SymbolOptions& options_)
: options(options_) {}
SymbolDrawableTweaker(const CustomDrawableLayerHost::Interface::SymbolOptions& options_,
CustomDrawableLayerHost::Interface::SymbolTweakerCallback&& callback_)
: options(options_),
callback(callback_) {}
~SymbolDrawableTweaker() override = default;
void init(gfx::Drawable&) override {}
@@ -277,9 +372,11 @@ public:
return;
}
if (callback) {
callback(drawable, parameters, options);
}
const UnwrappedTileID tileID = drawable.getTileID()->toUnwrapped();
mat4 tileMatrix;
parameters.state.matrixFor(/*out*/ tileMatrix, tileID);
const auto matrix = LayerTweaker::getTileMatrix(
tileID, parameters, {{0, 0}}, style::TranslateAnchorType::Viewport, false, false, drawable, false);
@@ -312,6 +409,38 @@ public:
private:
CustomDrawableLayerHost::Interface::SymbolOptions options;
CustomDrawableLayerHost::Interface::SymbolTweakerCallback callback;
};
class GeometryDrawableTweaker : public gfx::DrawableTweaker {
public:
GeometryDrawableTweaker(const CustomDrawableLayerHost::Interface::GeometryOptions& options_,
CustomDrawableLayerHost::Interface::GeometryTweakerCallback&& callback_)
: options(options_),
callback(callback_) {}
~GeometryDrawableTweaker() override = default;
void init(gfx::Drawable&) override {}
void execute(gfx::Drawable& drawable, PaintParameters& parameters) override {
if (!drawable.getTileID().has_value()) {
return;
}
if (callback) {
callback(drawable, parameters, options);
}
CustomGeometryDrawableUBO drawableUBO = {/* .matrix = */ util::cast<float>(options.matrix),
/* .color = */ options.color};
auto& drawableUniforms = drawable.mutableUniformBuffers();
drawableUniforms.createOrUpdate(idCustomGeometryDrawableUBO, &drawableUBO, parameters.context);
};
private:
CustomDrawableLayerHost::Interface::GeometryOptions options;
CustomDrawableLayerHost::Interface::GeometryTweakerCallback callback;
};
CustomDrawableLayerHost::Interface::Interface(RenderLayer& layer_,
@@ -364,6 +493,11 @@ void CustomDrawableLayerHost::Interface::setSymbolOptions(const SymbolOptions& o
symbolOptions = options;
}
void CustomDrawableLayerHost::Interface::setGeometryOptions(const GeometryOptions& options) {
finish();
geometryOptions = options;
}
bool CustomDrawableLayerHost::Interface::updateBuilder(BuilderType type,
const std::string& name,
gfx::ShaderPtr shader) {
@@ -378,17 +512,22 @@ bool CustomDrawableLayerHost::Interface::updateBuilder(BuilderType type,
return true;
};
bool CustomDrawableLayerHost::Interface::addPolyline(const LineString<double>& coordinates) {
switch (lineOptions.shaderType) {
util::SimpleIdentity CustomDrawableLayerHost::Interface::addPolyline(const LineString<double>& coordinates,
LineShaderType shaderType) {
#if !MLN_RENDER_BACKEND_METAL
shaderType = LineShaderType::Classic;
#endif
switch (shaderType) {
case LineShaderType::Classic: {
// TODO: build classic polyline with Geo coordinates
return false;
return util::SimpleIdentity::Empty;
} break;
case LineShaderType::MetalWideVector: {
case LineShaderType::WideVector: {
// build wide vector polyline with Geo coordinates
if (!updateBuilder(BuilderType::LineWideVector, "custom-lines-widevector", lineShaderWideVector()))
return false;
return util::SimpleIdentity::Empty;
// geographic coordinates require tile {0, 0, 0}
setTileID({0, 0, 0});
@@ -397,32 +536,42 @@ bool CustomDrawableLayerHost::Interface::addPolyline(const LineString<double>& c
} break;
}
return true;
return builder->getCurrentDrawable(true)->getID();
}
bool CustomDrawableLayerHost::Interface::addPolyline(const GeometryCoordinates& coordinates) {
switch (lineOptions.shaderType) {
util::SimpleIdentity CustomDrawableLayerHost::Interface::addPolyline(const GeometryCoordinates& coordinates,
LineShaderType shaderType) {
#if !MLN_RENDER_BACKEND_METAL
shaderType = LineShaderType::Classic;
#endif
switch (shaderType) {
case LineShaderType::Classic: {
// build classic polyline with Tile coordinates
if (!updateBuilder(BuilderType::LineClassic, "custom-lines", lineShaderDefault())) return false;
if (!updateBuilder(BuilderType::LineClassic, "custom-lines", lineShaderDefault())) {
return util::SimpleIdentity::Empty;
}
builder->addPolyline(coordinates, lineOptions.geometry);
} break;
case LineShaderType::MetalWideVector: {
case LineShaderType::WideVector: {
// build wide vector polyline
if (!updateBuilder(BuilderType::LineWideVector, "custom-lines-widevector", lineShaderWideVector()))
return false;
return util::SimpleIdentity::Empty;
builder->addWideVectorPolylineLocal(coordinates, lineOptions.geometry);
} break;
}
return true;
return builder->getCurrentDrawable(true)->getID();
}
bool CustomDrawableLayerHost::Interface::addFill(const GeometryCollection& geometry) {
util::SimpleIdentity CustomDrawableLayerHost::Interface::addFill(const GeometryCollection& geometry) {
// build fill
if (!updateBuilder(BuilderType::Fill, "custom-fill", fillShaderDefault())) return false;
if (!updateBuilder(BuilderType::Fill, "custom-fill", fillShaderDefault())) {
return util::SimpleIdentity::Empty;
}
// provision buffers for fill vertices, indexes and segments
using VertexVector = gfx::VertexVector<FillLayoutVertex>;
@@ -451,15 +600,20 @@ bool CustomDrawableLayerHost::Interface::addFill(const GeometryCollection& geome
builder->setRawVertices({}, vertices.elements(), gfx::AttributeDataType::Short2);
builder->setSegments(gfx::Triangles(), sharedTriangles, triangleSegments.data(), triangleSegments.size());
const auto& id = builder->getCurrentDrawable(true)->getID();
// flush current builder drawable
builder->flush(context);
return true;
return id;
}
bool CustomDrawableLayerHost::Interface::addSymbol(const GeometryCoordinate& point) {
util::SimpleIdentity CustomDrawableLayerHost::Interface::addSymbol(
const GeometryCoordinate& point, const std::array<std::array<float, 2>, 2>& textureCoordinates) {
// build symbol
if (!updateBuilder(BuilderType::Symbol, "custom-symbol", symbolShaderDefault())) return false;
if (!updateBuilder(BuilderType::Symbol, "custom-symbol", symbolShaderDefault())) {
return util::SimpleIdentity::Empty;
}
// temporary: buffers
struct CustomSymbolIcon {
@@ -477,7 +631,7 @@ bool CustomDrawableLayerHost::Interface::addSymbol(const GeometryCoordinate& poi
for (int x = 0; x <= 1; ++x) {
vertices.emplace_back(
CustomSymbolIcon{{static_cast<float>(point.x * 2 + x), static_cast<float>(point.y * 2 + y)},
{symbolOptions.textureCoordinates[x][0], symbolOptions.textureCoordinates[y][1]}});
{textureCoordinates[x][0], textureCoordinates[y][1]}});
}
}
@@ -517,13 +671,83 @@ bool CustomDrawableLayerHost::Interface::addSymbol(const GeometryCoordinate& poi
}
// create symbol tweaker
auto tweaker = std::make_shared<SymbolDrawableTweaker>(symbolOptions);
auto tweaker = std::make_shared<SymbolDrawableTweaker>(symbolOptions, std::move(symbolTweakerCallback));
builder->addTweaker(tweaker);
const auto& id = builder->getCurrentDrawable(true)->getID();
// flush current builder drawable
builder->flush(context);
return true;
return id;
}
util::SimpleIdentity CustomDrawableLayerHost::Interface::addGeometry(
std::shared_ptr<gfx::VertexVector<GeometryVertex>> vertices,
std::shared_ptr<gfx::IndexVector<gfx::Triangles>> indices,
bool is3D) {
if (!vertices || !indices) {
return util::SimpleIdentity::Empty;
}
if (!updateBuilder(BuilderType::Geometry, "custom-geometry", geometryShaderDefault())) {
return util::SimpleIdentity::Empty;
}
// geographic coordinates require tile {0, 0, 0}
setTileID({0, 0, 0});
SegmentVector<GeometryVertex> triangleSegments;
triangleSegments.emplace_back(Segment<GeometryVertex>{0, 0, vertices->elements(), indices->elements()});
// add to builder
auto attrs = context.createVertexAttributeArray();
if (const auto& attr = attrs->set(idCustomGeometryPosVertexAttribute)) {
attr->setSharedRawData(vertices,
offsetof(GeometryVertex, position),
/*vertexOffset=*/0,
sizeof(GeometryVertex),
gfx::AttributeDataType::Float3);
}
if (const auto& attr = attrs->set(idCustomGeometryTexVertexAttribute)) {
attr->setSharedRawData(vertices,
offsetof(GeometryVertex, texcoords),
/*vertexOffset=*/0,
sizeof(GeometryVertex),
gfx::AttributeDataType::Float2);
}
builder->setVertexAttributes(std::move(attrs));
builder->setRawVertices({}, vertices->elements(), gfx::AttributeDataType::Float3);
builder->setSegments(gfx::Triangles(), indices, triangleSegments.data(), triangleSegments.size());
builder->setEnableDepth(true);
if (is3D) {
builder->setDepthType(gfx::DepthMaskType::ReadWrite);
builder->setIs3D(true);
}
// white texture
if (!geometryOptions.texture) {
auto image = std::make_shared<PremultipliedImage>(mbgl::Size(2, 2));
image->fill(255);
geometryOptions.texture = context.createTexture2D();
geometryOptions.texture->setImage(std::move(image));
}
builder->setTexture(geometryOptions.texture, shaders::idCustomGeometryTexture);
builder->addTweaker(std::make_shared<GeometryDrawableTweaker>(geometryOptions, std::move(geometryTweakerCallback)));
const auto& id = builder->getCurrentDrawable(true)->getID();
// flush current builder drawable
builder->flush(context);
return id;
}
void CustomDrawableLayerHost::Interface::finish() {
@@ -552,16 +776,7 @@ void CustomDrawableLayerHost::Interface::finish() {
// finish building classic lines
// create line tweaker
const shaders::LineEvaluatedPropsUBO linePropertiesUBO = {lineOptions.color,
lineOptions.blur,
lineOptions.opacity,
lineOptions.gapWidth,
lineOptions.offset,
lineOptions.width,
/*floorwidth=*/0,
LineExpressionMask::None,
0};
auto tweaker = std::make_shared<LineDrawableTweaker>(linePropertiesUBO);
auto tweaker = std::make_shared<LineDrawableTweaker>(lineOptions, std::move(lineTweakerCallback));
// finish drawables
finish_(tweaker);
@@ -570,7 +785,7 @@ void CustomDrawableLayerHost::Interface::finish() {
// finish building wide vector lines
// create line tweaker
auto tweaker = std::make_shared<WideVectorDrawableTweaker>(lineOptions);
auto tweaker = std::make_shared<WideVectorDrawableTweaker>(lineOptions, std::move(lineTweakerCallback));
// finish drawables
finish_(tweaker);
@@ -579,7 +794,7 @@ void CustomDrawableLayerHost::Interface::finish() {
// finish building fills
// create fill tweaker
auto tweaker = std::make_shared<FillDrawableTweaker>(fillOptions.color, fillOptions.opacity);
auto tweaker = std::make_shared<FillDrawableTweaker>(fillOptions, std::move(fillTweakerCallback));
// finish drawables
finish_(tweaker);
@@ -588,12 +803,21 @@ void CustomDrawableLayerHost::Interface::finish() {
// finish building symbols
finish_(nullptr);
break;
case BuilderType::Geometry:
finish_(nullptr);
break;
default:
break;
}
}
}
void CustomDrawableLayerHost::Interface::removeDrawable(const util::SimpleIdentity& id) {
TileLayerGroup* tileLayerGroup = static_cast<TileLayerGroup*>(layerGroup.get());
tileLayerGroup->removeDrawablesIf([&](gfx::Drawable& drawable) { return drawable.getID() == id; });
}
gfx::ShaderPtr CustomDrawableLayerHost::Interface::lineShaderDefault() const {
gfx::ShaderGroupPtr shaderGroup = shaders.getShaderGroup("LineShader");
assert(shaderGroup);
@@ -630,6 +854,10 @@ gfx::ShaderPtr CustomDrawableLayerHost::Interface::symbolShaderDefault() const {
return context.getGenericShader(shaders, "CustomSymbolIconShader");
}
gfx::ShaderPtr CustomDrawableLayerHost::Interface::geometryShaderDefault() const {
return context.getGenericShader(shaders, "CustomGeometryShader");
}
std::unique_ptr<gfx::DrawableBuilder> CustomDrawableLayerHost::Interface::createBuilder(const std::string& name,
gfx::ShaderPtr shader) const {
std::unique_ptr<gfx::DrawableBuilder> builder_ = context.createDrawableBuilder(name);

View File

@@ -366,6 +366,11 @@ gfx::UniformBufferPtr Context::createUniformBuffer(const void* data, std::size_t
data, size, ssbo ? VK_BUFFER_USAGE_STORAGE_BUFFER_BIT : VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, persistent));
}
UniqueUniformBufferArray Context::createLayerUniformBufferArray() {
return std::make_unique<UniformBufferArray>(
DescriptorSetType::Layer, shaders::globalUBOCount, shaders::maxSSBOCountPerLayer, shaders::maxUBOCountPerLayer);
}
gfx::ShaderProgramBasePtr Context::getGenericShader(gfx::ShaderRegistry& shaders, const std::string& name) {
const auto shaderGroup = shaders.getShaderGroup(name);
auto shader = shaderGroup ? shaderGroup->getOrCreateShader(*this, {}) : gfx::ShaderProgramBasePtr{};

View File

@@ -260,23 +260,30 @@ void Drawable::draw(PaintParameters& parameters) const {
sizeof(uboIndex),
&uboIndex);
if (is3D) {
impl->pipelineInfo.setDepthMode(impl->depthFor3D);
impl->pipelineInfo.setStencilMode(impl->stencilFor3D);
} else {
if (enableDepth) {
if (enableDepth) {
if (impl->depthFor3D.has_value()) {
impl->pipelineInfo.setDepthMode(impl->depthFor3D.value());
} else if (is3D) {
impl->pipelineInfo.setDepthMode(parameters.depthModeFor3D());
} else {
const auto& depthMode = parameters.depthModeForSublayer(getSubLayerIndex(), getDepthType());
impl->pipelineInfo.setDepthMode(depthMode);
} else {
impl->pipelineInfo.setDepthMode(gfx::DepthMode::disabled());
}
} else {
impl->pipelineInfo.setDepthMode(gfx::DepthMode::disabled());
}
if (enableStencil) {
if (enableStencil) {
if (impl->stencilFor3D.has_value()) {
impl->pipelineInfo.setStencilMode(impl->stencilFor3D.value());
} else if (is3D) {
impl->pipelineInfo.setStencilMode(parameters.stencilModeFor3D());
} else {
const auto& stencilMode = parameters.stencilModeForClipping(tileID->toUnwrapped());
impl->pipelineInfo.setStencilMode(stencilMode);
} else {
impl->pipelineInfo.setStencilMode(gfx::StencilMode::disabled());
}
} else {
impl->pipelineInfo.setStencilMode(gfx::StencilMode::disabled());
}
impl->pipelineInfo.setRenderable(renderPass_.getDescriptor().renderable);

View File

@@ -44,8 +44,8 @@ public:
std::optional<gfx::RenderPassDescriptor> renderPassDescriptor;
gfx::DepthMode depthFor3D = gfx::DepthMode::disabled();
gfx::StencilMode stencilFor3D = gfx::StencilMode::disabled();
std::optional<gfx::DepthMode> depthFor3D;
std::optional<gfx::StencilMode> stencilFor3D;
PipelineInfo pipelineInfo;

View File

@@ -56,15 +56,15 @@ void LayerGroup::render(RenderOrchestrator&, PaintParameters& parameters) {
return;
}
for (const auto& tweaker : drawable.getTweakers()) {
tweaker->execute(drawable, parameters);
}
if (!bindUBOs) {
uniformBuffers.bindDescriptorSets(encoder);
bindUBOs = true;
}
for (const auto& tweaker : drawable.getTweakers()) {
tweaker->execute(drawable, parameters);
}
drawable.draw(parameters);
});
}

View File

@@ -12,6 +12,7 @@
#include <mbgl/shaders/vulkan/circle.hpp>
#include <mbgl/shaders/vulkan/clipping_mask.hpp>
#include <mbgl/shaders/vulkan/collision.hpp>
#include <mbgl/shaders/vulkan/custom_geometry.hpp>
#include <mbgl/shaders/vulkan/custom_symbol_icon.hpp>
#include <mbgl/shaders/vulkan/debug.hpp>
#include <mbgl/shaders/vulkan/fill.hpp>
@@ -669,6 +670,7 @@ void RendererBackend::initShaders(gfx::ShaderRegistry& shaders, const ProgramPar
shaders::BuiltIn::ClippingMaskProgram,
shaders::BuiltIn::CollisionBoxShader,
shaders::BuiltIn::CollisionCircleShader,
shaders::BuiltIn::CustomGeometryShader,
shaders::BuiltIn::CustomSymbolIconShader,
shaders::BuiltIn::DebugShader,
shaders::BuiltIn::FillShader,

View File

@@ -92,15 +92,15 @@ void TileLayerGroup::render(RenderOrchestrator&, PaintParameters& parameters) {
return;
}
for (const auto& tweaker : drawable.getTweakers()) {
tweaker->execute(drawable, parameters);
}
if (!bindUBOs) {
uniformBuffers.bindDescriptorSets(encoder);
bindUBOs = true;
}
for (const auto& tweaker : drawable.getTweakers()) {
tweaker->execute(drawable, parameters);
}
if (features3d) {
auto& drawableImpl = static_cast<Drawable&>(drawable);

View File

@@ -3,6 +3,7 @@
#include <mbgl/vulkan/context.hpp>
#include <mbgl/util/logging.hpp>
#include <mbgl/vulkan/command_encoder.hpp>
#include <mbgl/vulkan/render_pass.hpp>
#include <cassert>
@@ -68,6 +69,10 @@ void UniformBufferArray::createOrUpdate(
gfx::UniformBufferArray::createOrUpdate(id, data, size, context, persistent);
}
void UniformBufferArray::bind(gfx::RenderPass& renderPass) {
bindDescriptorSets(static_cast<RenderPass&>(renderPass).getEncoder());
}
void UniformBufferArray::bindDescriptorSets(CommandEncoder& encoder) {
if (!descriptorSet) {
descriptorSet = std::make_unique<UniformDescriptorSet>(encoder.getContext(), descriptorSetType);

View File

@@ -48,7 +48,6 @@ public:
/*gapWidth=*/0.0f,
/*offset=*/0.0f,
/*width=*/8.0f,
/*shaderType*/ {},
/*color=*/Color::red(),
},
{
@@ -58,7 +57,6 @@ public:
/*gapWidth=*/2.0f,
/*offset=*/-1.0f,
/*width=*/4.0f,
{},
/*color=*/Color::blue(),
},
{
@@ -68,7 +66,6 @@ public:
/*gapWidth=*/1.0f,
/*offset=*/2.0f,
/*width=*/16.0f,
{},
/*color=*/Color(1.f, 0.5f, 0, 0.5f),
},
{
@@ -78,7 +75,6 @@ public:
/*gapWidth=*/1.0f,
/*offset=*/-2.0f,
/*width=*/2.0f,
{},
/*color=*/Color(1.f, 1.f, 0, 0.3f),
},
{
@@ -88,7 +84,6 @@ public:
/*gapWidth=*/1.0f,
/*offset=*/0.5f,
/*width=*/0.5f,
{},
/*color=*/Color::black(),
},
{
@@ -98,7 +93,6 @@ public:
/*gapWidth=*/1.0f,
/*offset=*/-5.0f,
/*width=*/24.0f,
{},
/*color=*/Color(1.f, 0, 1.f, 0.2f),
},
};
@@ -125,7 +119,7 @@ public:
interface.setLineOptions(options[index]);
// add polyline
interface.addPolyline(polyline);
interface.addPolyline(polyline, Interface::LineShaderType::Classic);
}
}
@@ -219,10 +213,10 @@ public:
options.texture->setImage(image);
options.texture->setSamplerConfiguration(
{gfx::TextureFilterType::Linear, gfx::TextureWrapType::Clamp, gfx::TextureWrapType::Clamp});
options.textureCoordinates = {{{0.0f, 0.08f}, {1.0f, 0.9f}}};
const float xspan = options.textureCoordinates[1][0] - options.textureCoordinates[0][0];
const float yspan = options.textureCoordinates[1][1] - options.textureCoordinates[0][1];
assert(xspan > 0.0f && yspan > 0.0f);
constexpr std::array<std::array<float, 2>, 2> textureCoordinates = {{{0.0f, 0.08f}, {1.0f, 0.9f}}};
constexpr float xspan = textureCoordinates[1][0] - textureCoordinates[0][0];
constexpr float yspan = textureCoordinates[1][1] - textureCoordinates[0][1];
static_assert(xspan > 0.0f && yspan > 0.0f);
options.size = {static_cast<uint32_t>(image->size.width * 0.2f * xspan),
static_cast<uint32_t>(image->size.height * 0.2f * yspan)};
options.anchor = {0.5f, 0.95f};
@@ -232,7 +226,7 @@ public:
interface.setSymbolOptions(options);
// add symbol
interface.addSymbol(position);
interface.addSymbol(position, textureCoordinates);
}
// finish

View File

@@ -14,6 +14,8 @@
#include <mbgl/shaders/mtl/circle.hpp>
#include <mbgl/shaders/mtl/clipping_mask.hpp>
#include <mbgl/shaders/mtl/collision.hpp>
#include <mbgl/shaders/mtl/custom_geometry.hpp>
#include <mbgl/shaders/mtl/custom_symbol_icon.hpp>
#include <mbgl/shaders/mtl/debug.hpp>
#include <mbgl/shaders/mtl/fill.hpp>
#include <mbgl/shaders/mtl/fill_extrusion.hpp>
@@ -22,6 +24,7 @@
#include <mbgl/shaders/mtl/hillshade.hpp>
#include <mbgl/shaders/mtl/hillshade_prepare.hpp>
#include <mbgl/shaders/mtl/line.hpp>
#include <mbgl/shaders/mtl/location_indicator.hpp>
#include <mbgl/shaders/mtl/fill.hpp>
#include <mbgl/shaders/mtl/raster.hpp>
#include <mbgl/shaders/mtl/symbol.hpp>
@@ -128,6 +131,8 @@ TEST(OrderIndependentHash, Shaders) {
BuiltIn::CircleShader,
BuiltIn::CollisionBoxShader,
BuiltIn::CollisionCircleShader,
BuiltIn::CustomGeometryShader,
BuiltIn::CustomSymbolIconShader,
BuiltIn::DebugShader,
BuiltIn::FillShader,
BuiltIn::FillOutlineShader,
@@ -144,6 +149,8 @@ TEST(OrderIndependentHash, Shaders) {
BuiltIn::LineGradientShader,
BuiltIn::LinePatternShader,
BuiltIn::LineSDFShader,
BuiltIn::LocationIndicatorShader,
BuiltIn::LocationIndicatorTexturedShader,
BuiltIn::RasterShader,
BuiltIn::SymbolIconShader,
BuiltIn::SymbolSDFIconShader,

19
vendor/tinyobjloader.cmake vendored Normal file
View File

@@ -0,0 +1,19 @@
include(FetchContent)
FetchContent_Declare(
tinyobjloader
GIT_REPOSITORY "https://github.com/tinyobjloader/tinyobjloader.git"
GIT_TAG release
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(tinyobjloader)
set_target_properties(
tinyobjloader
PROPERTIES
INTERFACE_MAPLIBRE_NAME "tinyobjloader"
INTERFACE_MAPLIBRE_URL "https://github.com/tinyobjloader/tinyobjloader.git"
INTERFACE_MAPLIBRE_LICENSE ${CMAKE_CURRENT_LIST_DIR}/tinyobjloader/LICENSE
)