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

Use drawables for location indicator layer #2836

Merged
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
52eeb40
Added Android Vulkan backend
adrian-cojocaru Aug 7, 2024
f3527a2
Merge branch 'maplibre:main' into vulkan-backend-android
adrian-cojocaru Aug 7, 2024
7dd0389
Added check for wideLine feature
adrian-cojocaru Aug 9, 2024
c044f1c
Merge branch 'maplibre:main' into vulkan-backend-android
adrian-cojocaru Aug 9, 2024
4b86554
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 9, 2024
782dce4
Fixed style errors
adrian-cojocaru Aug 12, 2024
109dbbd
Fix build errors
adrian-cojocaru Aug 14, 2024
b2a0ec1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 14, 2024
c9c2fee
Android Render Test for Vulkan on CI
louwers Aug 15, 2024
e113318
remove caps
louwers Aug 15, 2024
83ff68f
Fix workflow
louwers Aug 16, 2024
ec0cfc5
Free disk space
louwers Aug 16, 2024
1cae7c4
fix typo
louwers Aug 16, 2024
035d078
Merge branch 'main' of https://github.com/adrian-cojocaru/maplibre-na…
adrian-cojocaru Aug 19, 2024
6562379
Merge branch 'vulkan-backend-android' of https://github.com/adrian-co…
adrian-cojocaru Aug 19, 2024
a8f28ca
Fixed surface init order
adrian-cojocaru Aug 19, 2024
93bb259
Fixed benchmark crash
adrian-cojocaru Aug 21, 2024
2404dbf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 21, 2024
36f34b4
Use shader integer types
adrian-cojocaru Aug 22, 2024
6fbdfa1
Fixed SwapBehaviour
adrian-cojocaru Aug 23, 2024
ba47e68
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 23, 2024
880fda6
Merge branch 'maplibre:main' into vulkan-backend-android
adrian-cojocaru Aug 27, 2024
21aec56
Moved frame submission
adrian-cojocaru Aug 28, 2024
ddbd594
Merge branch 'vulkan-backend-android' of https://github.com/adrian-co…
adrian-cojocaru Aug 28, 2024
3980fee
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 28, 2024
266f939
Add drawable implementation for location indicator layer
adrian-cojocaru Aug 29, 2024
edb23ac
Update shared vertices only once
adrian-cojocaru Aug 30, 2024
ddebd2a
Merge branch 'main' of https://github.com/adrian-cojocaru/maplibre-na…
adrian-cojocaru Sep 6, 2024
9cf750b
Fixed merge conflicts
adrian-cojocaru Sep 6, 2024
c53d119
Fix compile error
adrian-cojocaru Sep 10, 2024
16d993f
Merge branch 'main' of https://github.com/adrian-cojocaru/maplibre-na…
adrian-cojocaru Sep 16, 2024
89651cd
Select RenderDoc capture device
adrian-cojocaru Sep 16, 2024
8c5e993
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 16, 2024
3c288e0
Add missing files
adrian-cojocaru Sep 16, 2024
73308f0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 16, 2024
494c9ff
Compile errors
adrian-cojocaru Sep 16, 2024
c2eb6a4
Update preprocessor guards
adrian-cojocaru Sep 16, 2024
31b2207
Merge branch 'maplibre:main' into drawable-location-indicator
adrian-cojocaru Sep 20, 2024
4744604
Move uniform updates to tweaker
adrian-cojocaru Sep 24, 2024
55595d1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 24, 2024
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
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,7 @@ if(MLN_WITH_OPENGL)
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/background_layer_ubo.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/circle_layer_ubo.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/collision_layer_ubo.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/common_ubo.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/style/layers/custom_drawable_layer.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/layermanager/custom_drawable_layer_factory.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/debug_layer_ubo.hpp
Expand Down Expand Up @@ -1349,6 +1350,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/common.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/debug.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/fill.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/heatmap.cpp
Expand Down
1 change: 1 addition & 0 deletions bazel/core.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,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/common_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
3 changes: 3 additions & 0 deletions include/mbgl/gfx/texture2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class Texture2D {
TextureWrapType wrapU{TextureWrapType::Clamp};
/// Wrapping behavior along V coordinate
TextureWrapType wrapV{TextureWrapType::Clamp};

uint8_t maxAnisotropy{1};
bool mipmapped{false};
};

public:
Expand Down
20 changes: 20 additions & 0 deletions include/mbgl/shaders/common_ubo.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include <mbgl/shaders/layer_ubo.hpp>

namespace mbgl {
namespace shaders {

struct alignas(16) CommonUBO {
std::array<float, 4 * 4> matrix;
Color color;
};
static_assert(sizeof(CommonUBO) % 16 == 0);

enum {
idCommonUBO = globalUBOCount,
commonUBOCount
};

} // namespace shaders
} // namespace mbgl
15 changes: 15 additions & 0 deletions include/mbgl/shaders/shader_defines.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <mbgl/shaders/common_ubo.hpp>
#include <mbgl/shaders/background_layer_ubo.hpp>
#include <mbgl/shaders/circle_layer_ubo.hpp>
#include <mbgl/shaders/collision_layer_ubo.hpp>
Expand Down Expand Up @@ -31,6 +32,7 @@ static constexpr auto maxUBOCountPerShader = std::max({static_cast<size_t>(backg
static_cast<size_t>(circleUBOCount),
static_cast<size_t>(clippingMaskUBOCount),
static_cast<size_t>(collisionUBOCount),
static_cast<size_t>(commonUBOCount),
static_cast<size_t>(customSymbolUBOCount),
static_cast<size_t>(debugUBOCount),
static_cast<size_t>(fillUBOCount),
Expand Down Expand Up @@ -62,6 +64,11 @@ enum {
collisionTextureCount
};

enum {
louwers marked this conversation as resolved.
Show resolved Hide resolved
idCommonTexture,
commonTextureCount
};

enum {
idCustomSymbolImageTexture,
customSymbolTextureCount
Expand Down Expand Up @@ -114,6 +121,7 @@ static constexpr auto maxTextureCountPerShader = std::max({static_cast<size_t>(b
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),
Expand Down Expand Up @@ -159,6 +167,12 @@ enum {
collisionVertexAttributeCount
};

enum {
idCommonPosVertexAttribute,
idCommonTexVertexAttribute,
commonVertexAttributeCount
};

enum {
idCustomSymbolPosVertexAttribute,
idCustomSymbolTexVertexAttribute,
Expand Down Expand Up @@ -276,6 +290,7 @@ static constexpr auto maxVertexAttributeCountPerShader = std::max({
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),
Expand Down
2 changes: 2 additions & 0 deletions include/mbgl/shaders/shader_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ enum class BuiltIn {
CircleShader,
CollisionBoxShader,
CollisionCircleShader,
CommonShader,
CommonTexturedShader,
DebugShader,
FillShader,
FillOutlineShader,
Expand Down
78 changes: 78 additions & 0 deletions include/mbgl/shaders/vulkan/common.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <mbgl/shaders/shader_source.hpp>
#include <mbgl/shaders/vulkan/shader_program.hpp>

namespace mbgl {
namespace shaders {
Expand Down Expand Up @@ -100,5 +101,82 @@ layout(set = 0, binding = 0) uniform GlobalPaintParamsUBO {
)";
};

template <>
struct ShaderSource<BuiltIn::CommonShader, gfx::Backend::Type::Vulkan> {
static constexpr const char* name = "CommonShader";

static const std::array<UniformBlockInfo, 1> uniforms;
static const std::array<AttributeInfo, 1> attributes;
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static constexpr std::array<TextureInfo, 0> textures{};

static constexpr auto vertex = R"(
layout(location = 0) in vec2 in_position;

layout(set = 0, binding = 1) uniform CommonUBO {
mat4 matrix;
vec4 color;
} ubo;

void main() {
gl_Position = ubo.matrix * vec4(in_position, 0, 1);
gl_Position.y *= -1.0;
}
)";

static constexpr auto fragment = R"(
layout(location = 0) out vec4 out_color;

layout(set = 0, binding = 1) uniform CommonUBO {
mat4 matrix;
vec4 color;
} ubo;

void main() {
out_color = ubo.color;
}
)";
};

template <>
struct ShaderSource<BuiltIn::CommonTexturedShader, gfx::Backend::Type::Vulkan> {
static constexpr const char* name = "CommonTexturedShader";

static const std::array<UniformBlockInfo, 1> uniforms;
static const std::array<AttributeInfo, 2> attributes;
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 1> textures;

static constexpr auto vertex = R"(
layout(location = 0) in vec2 in_position;
layout(location = 1) in vec2 in_texcoord;

layout(set = 0, binding = 1) uniform CommonUBO {
mat4 matrix;
vec4 color;
} ubo;

layout(location = 0) out vec2 frag_uv;

void main() {
gl_Position = ubo.matrix * vec4(in_position, 0, 1);
gl_Position.y *= -1.0;

frag_uv = in_texcoord;
}
)";

static constexpr auto fragment = R"(
layout(location = 0) in vec2 frag_uv;
layout(location = 0) out vec4 out_color;

layout(set = 1, binding = 0) uniform sampler2D image_sampler;

void main() {
out_color = texture(image_sampler, frag_uv);
}
)";
};

} // namespace shaders
} // namespace mbgl
3 changes: 3 additions & 0 deletions include/mbgl/vulkan/texture2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ class Texture2D : public gfx::Texture2D {
void transitionToShaderReadLayout(const vk::UniqueCommandBuffer&);
void transitionToGeneralLayout(const vk::UniqueCommandBuffer&);

uint32_t getMipLevels() const;
void generateMips(const vk::UniqueCommandBuffer& buffer);

private:
Context& context;

Expand Down
2 changes: 1 addition & 1 deletion platform/android/gradle/download-vulkan-validation.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ task unzip(dependsOn: download, type: Copy) {

android.sourceSets.vulkan.jniLibs {
srcDir(tasks.unzip)
}
}
2 changes: 2 additions & 0 deletions platform/default/src/mbgl/layermanager/layer_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ LayerManagerDefault::LayerManagerDefault() {
#if !defined(MBGL_LAYER_CUSTOM_DISABLE_ALL)
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
Expand Down
7 changes: 3 additions & 4 deletions platform/glfw/glfw_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@

using namespace std::numbers;

#if defined(MLN_RENDER_BACKEND_OPENGL) && !defined(MBGL_LAYER_LOCATION_INDICATOR_DISABLE_ALL)
#include <mbgl/style/layers/location_indicator_layer.hpp>
#ifdef ENABLE_LOCATION_INDICATOR

namespace {
const std::string mbglPuckAssetsPath{MAPBOX_PUCK_ASSETS_PATH};
Expand Down Expand Up @@ -1210,7 +1209,7 @@ void GLFWView::toggleCustomSource() {
void GLFWView::toggleLocationIndicatorLayer() {
MLN_TRACE_FUNC();

#if defined(MLN_RENDER_BACKEND_OPENGL) && !defined(MBGL_LAYER_LOCATION_INDICATOR_DISABLE_ALL)
#ifdef ENABLE_LOCATION_INDICATOR
puck = static_cast<mbgl::style::LocationIndicatorLayer *>(map->getStyle().getLayer("puck"));
static const mbgl::LatLng puckLocation{35.683389, 139.76525}; // A location on the crossing of 4 tiles
if (puck == nullptr) {
Expand Down Expand Up @@ -1275,7 +1274,7 @@ using Nanoseconds = std::chrono::nanoseconds;
void GLFWView::onWillStartRenderingFrame() {
MLN_TRACE_FUNC();

#if defined(MLN_RENDER_BACKEND_OPENGL) && !defined(MBGL_LAYER_LOCATION_INDICATOR_DISABLE_ALL)
#ifdef ENABLE_LOCATION_INDICATOR
puck = static_cast<mbgl::style::LocationIndicatorLayer *>(map->getStyle().getLayer("puck"));
if (puck) {
uint64_t ns = mbgl::Clock::now().time_since_epoch().count();
Expand Down
14 changes: 10 additions & 4 deletions platform/glfw/glfw_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
#include <mbgl/util/geometry.hpp>
#include <mbgl/util/run_loop.hpp>
#include <mbgl/util/timer.hpp>
#if defined(MLN_RENDER_BACKEND_OPENGL) && !defined(MBGL_LAYER_CUSTOM_DISABLE_ALL)
#include <mbgl/style/layers/location_indicator_layer.hpp>
#endif

#include <utility>
#include <optional>

#if (defined(MLN_RENDER_BACKEND_OPENGL) || defined(MLN_RENDER_BACKEND_VULKAN)) && \
!defined(MBGL_LAYER_CUSTOM_DISABLE_ALL)
#define ENABLE_LOCATION_INDICATOR
#endif

#ifdef ENABLE_LOCATION_INDICATOR
#include <mbgl/style/layers/location_indicator_layer.hpp>
#endif

struct GLFWwindow;
class GLFWBackend;
class GLFWRendererFrontend;
Expand Down Expand Up @@ -160,7 +166,7 @@ class GLFWView : public mbgl::MapObserver {
mbgl::ResourceOptions mapResourceOptions;
mbgl::ClientOptions mapClientOptions;

#if defined(MLN_RENDER_BACKEND_OPENGL) && !defined(MBGL_LAYER_CUSTOM_DISABLE_ALL)
#ifdef ENABLE_LOCATION_INDICATOR
bool puckFollowsCameraCenter = false;
mbgl::style::LocationIndicatorLayer *puck = nullptr;
#endif
Expand Down
Loading
Loading