Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom drawable layer v3 #3210

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
207d4b4
Add custom drawable layer sample to glfw
adrian-cojocaru Jan 21, 2025
83b7232
Merge branch 'maplibre:main' into custom-drawable-layer
adrian-cojocaru Jan 28, 2025
e2c1251
Add Context::createLayerUniformBufferArray()
adrian-cojocaru Jan 29, 2025
17b448e
Add common geometry example
adrian-cojocaru Jan 31, 2025
b836f70
Add tweaker callbacks
adrian-cojocaru Feb 3, 2025
d1747c9
Fix drawable depth options order
adrian-cojocaru Feb 6, 2025
838dd85
Add custom obj drawable example
adrian-cojocaru Feb 6, 2025
1f5fc1f
Some renaming
adrian-cojocaru Feb 7, 2025
d0b0362
Add GL location indicator shaders
adrian-cojocaru Feb 7, 2025
4ec3cd7
Add tinyobjloader.cmake
adrian-cojocaru Feb 7, 2025
579e8f2
Merge branch 'maplibre:main' into custom-drawable-layer
adrian-cojocaru Feb 7, 2025
1be0c16
Fix merge compile error
adrian-cojocaru Feb 7, 2025
93e9d2d
Fix clang compile errors
adrian-cojocaru Feb 7, 2025
4830051
Add metal location indicator
adrian-cojocaru Feb 7, 2025
9dbb8f9
Add bazel obj loader
adrian-cojocaru Feb 10, 2025
8b37843
Fix metal location indicator depth
adrian-cojocaru Feb 10, 2025
335398a
Update iOS example
adrian-cojocaru Feb 11, 2025
32de1f1
Enable location indicator for vulkan/metal backends
adrian-cojocaru Feb 11, 2025
754986e
Merge branch 'custom-drawable-layer' of https://github.com/adrian-coj…
adrian-cojocaru Feb 11, 2025
51421cb
Merge branch 'main' into custom-drawable-layer
adrian-cojocaru Feb 11, 2025
e5e87ad
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 11, 2025
708e620
Fix custom drawable tests
adrian-cojocaru Feb 11, 2025
c0eb8fa
Fix vulkan shader macros
adrian-cojocaru Feb 11, 2025
79bcf5a
Disable example for legacy builds
adrian-cojocaru Feb 11, 2025
4ffec46
Allow drawable tweakers to override layer uniforms
adrian-cojocaru Feb 11, 2025
12e0507
Missing tweaker update
adrian-cojocaru Feb 11, 2025
b91de83
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 12, 2025
1e25a3d
Add custom geometry shader
adrian-cojocaru Feb 13, 2025
55cacd7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 13, 2025
6275c51
Add missing bazel include
adrian-cojocaru Feb 14, 2025
e2233fb
Merge branch 'main' into custom-drawable-layer
adrian-cojocaru Feb 14, 2025
918eb90
Fix example LineShaderType
adrian-cojocaru Feb 17, 2025
6b240c3
Merge branch 'custom-drawable-layer' of https://github.com/adrian-coj…
adrian-cojocaru Feb 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -1313,6 +1318,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
Expand Down Expand Up @@ -1353,6 +1359,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
Expand Down
8 changes: 8 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions bazel/core.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions include/mbgl/gfx/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ class Context {
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;

Expand Down
3 changes: 3 additions & 0 deletions include/mbgl/gfx/uniform_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down Expand Up @@ -75,6 +76,8 @@ class UniformBufferArray {
createOrUpdate(id, data, sizeof(T), context, persistent);
}

virtual void bind(gfx::RenderPass& renderPass) = 0;

UniformBufferArray& operator=(UniformBufferArray&&);
UniformBufferArray& operator=(const UniformBufferArray&);

Expand Down
2 changes: 2 additions & 0 deletions include/mbgl/gl/uniform_buffer_gl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class UniformBufferArrayGL final : public gfx::UniformBufferArray {
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());
Expand Down
3 changes: 3 additions & 0 deletions include/mbgl/mtl/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -88,6 +89,8 @@ class Context final : public gfx::Context {
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;
Expand Down
1 change: 0 additions & 1 deletion include/mbgl/mtl/index_buffer_resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace mtl {

class IndexBufferResource : public gfx::IndexBufferResource {
public:
IndexBufferResource() noexcept = default;
IndexBufferResource(BufferResource&&) noexcept;
IndexBufferResource(IndexBufferResource&& other) noexcept
: buffer(std::move(other.buffer)) {}
Expand Down
4 changes: 2 additions & 2 deletions include/mbgl/mtl/uniform_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class UniformBufferArray final : public gfx::UniformBufferArray {
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 {
Expand Down
1 change: 0 additions & 1 deletion include/mbgl/mtl/vertex_buffer_resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace mtl {

class VertexBufferResource : public gfx::VertexBufferResource {
public:
VertexBufferResource() noexcept = default;
VertexBufferResource(BufferResource&&) noexcept;
VertexBufferResource(VertexBufferResource&& other) noexcept
: buffer(std::move(other.buffer)) {}
Expand Down
16 changes: 16 additions & 0 deletions include/mbgl/shaders/custom_geometry_ubo.hpp
Original file line number Diff line number Diff line change
@@ -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
39 changes: 39 additions & 0 deletions include/mbgl/shaders/gl/drawable_custom_geometry.hpp
Original file line number Diff line number Diff line change
@@ -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 CustomDrawableDrawableUBO {
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 CustomDrawableDrawableUBO {
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
20 changes: 18 additions & 2 deletions include/mbgl/shaders/gl/drawable_location_indicator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 25 additions & 2 deletions include/mbgl/shaders/gl/drawable_location_indicator_textured.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions include/mbgl/shaders/gl/shader_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Loading
Loading