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

MLNCustomStyleLayer + Metal example #2041

Merged
merged 53 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
0a2cdc9
rename MLNOpenGLStyleLayer to MLNCustomStyleLayer
stefankarschti Jan 19, 2024
c65b600
collapse bazel file groups
stefankarschti Jan 19, 2024
19c6ff4
Merge branch 'main' into mlncustomstylelayer-refactor
stefankarschti Jan 19, 2024
3be46d0
adapt comments
stefankarschti Jan 22, 2024
9b6e19e
rename MLNOpenGLLayerHost to MLNCustomLayerHost
stefankarschti Jan 22, 2024
1262bc9
blank LimeGreenStyleLayer implementation for Metal
stefankarschti Jan 22, 2024
3165e7c
Merge branch 'main' into mlncustomstylelayer-refactor
stefankarschti Jan 22, 2024
0bd120b
Merge branch 'main' into mlncustomstylelayer-refactor
stefankarschti Jan 22, 2024
d2059f2
Metal Custom Layer example: first cut
stefankarschti Jan 24, 2024
f1d5023
fix iOS build
stefankarschti Jan 24, 2024
094a709
Metal example: take 2 (crashing)
stefankarschti Jan 25, 2024
f1b0f3f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 25, 2024
af793ed
Merge branch 'main' into mlncustomstylelayer-refactor
stefankarschti Jan 25, 2024
d2f8429
temporary fix
stefankarschti Jan 25, 2024
2272d6f
Merge branch 'mlncustomstylelayer-refactor' of https://github.com/map…
stefankarschti Jan 25, 2024
57a3693
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 25, 2024
8ff2f8b
Merge branch 'main' into mlncustomstylelayer-refactor
stefankarschti Jan 29, 2024
89a0cd1
working Metal custom layer
stefankarschti Jan 29, 2024
858c6f6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 29, 2024
c9f4a09
fix legacy build
stefankarschti Jan 29, 2024
c26eb55
Merge branch 'mlncustomstylelayer-refactor' of https://github.com/map…
stefankarschti Jan 29, 2024
4162aeb
warnings
stefankarschti Jan 29, 2024
f2d1de7
fix test
stefankarschti Jan 29, 2024
8ec43cb
fix android build
stefankarschti Jan 29, 2024
8762216
make MLNMapViewMetalRenderableResource.bind callable from the custom …
stefankarschti Jan 29, 2024
7ee1f41
upload_pass and render_pass don't need conditional resource binding a…
stefankarschti Jan 29, 2024
7ade61f
re-enable custom layer in testAddingLayersWithDuplicateIdentifiers test
stefankarschti Jan 29, 2024
cdd673d
fix Android example custom layer
stefankarschti Jan 29, 2024
d1d526c
Merge branch 'main' into mlncustomstylelayer-refactor
stefankarschti Jan 30, 2024
8c0d4cd
revert some changes
stefankarschti Jan 30, 2024
a46948a
Merge branch 'main' into mlncustomstylelayer-refactor
stefankarschti Jan 30, 2024
da6547e
Merge branch 'main' into mlncustomstylelayer-refactor
stefankarschti Jan 30, 2024
118b133
Merge branch 'main' into mlncustomstylelayer-refactor
stefankarschti Feb 1, 2024
5059a41
Merge branch 'main' into mlncustomstylelayer-refactor
stefankarschti Feb 1, 2024
e9815e7
Merge branch 'main' into mlncustomstylelayer-refactor
stefankarschti Feb 1, 2024
b0bff78
Merge branch 'main' into mlncustomstylelayer-refactor
stefankarschti Feb 2, 2024
07e3f2a
Merge branch 'main' into mlncustomstylelayer-refactor
stefankarschti Feb 6, 2024
9e5ae86
Merge branch 'main' of https://github.com/maplibre/maplibre-gl-native…
stefankarschti Feb 8, 2024
103ca99
merge fixes
stefankarschti Feb 8, 2024
d86a99a
include MLNBackendResource in MLN_DARWIN_OBJC_HEADERS
stefankarschti Feb 8, 2024
246c6c1
Merge branch 'main' into mlncustomstylelayer-refactor
stefankarschti Feb 8, 2024
6ae0e97
remove ex-OpenGL custom layer leftover in bazel build
stefankarschti Feb 9, 2024
358d994
Merge branch 'main' into mlncustomstylelayer-refactor
stefankarschti Feb 12, 2024
dbb48b8
Merge branch 'main' into mlncustomstylelayer-refactor
stefankarschti Feb 12, 2024
41e1cb4
Merge branch 'main' into mlncustomstylelayer-refactor
stefankarschti Feb 12, 2024
40a48d8
make renderEncoder a property
stefankarschti Feb 12, 2024
fb35da9
Merge branch 'main' into mlncustomstylelayer-refactor
stefankarschti Feb 13, 2024
2421fd9
plug a leak
stefankarschti Feb 13, 2024
02f2be0
Merge branch 'main' into mlncustomstylelayer-refactor
stefankarschti Feb 13, 2024
9e4cd57
fix android and node build
stefankarschti Feb 13, 2024
906f295
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 13, 2024
215c000
Merge branch 'main' of https://github.com/maplibre/maplibre-gl-native…
stefankarschti Feb 15, 2024
517c173
update Metal example. fix stencil interaction
stefankarschti Feb 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,8 @@ if(MLN_WITH_OPENGL)
INCLUDE_FILES
${PROJECT_SOURCE_DIR}/include/mbgl/gfx/backend.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/style/layers/custom_layer.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/style/layers/custom_layer_render_parameters.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/style/layers/mtl/custom_layer_render_parameters.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/layermanager/custom_layer_factory.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/gl/renderable_resource.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/gl/renderer_backend.hpp
Expand Down Expand Up @@ -1072,6 +1074,7 @@ if(MLN_WITH_OPENGL)
${PROJECT_SOURCE_DIR}/src/mbgl/gl/fence.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/gl/fence.hpp
${PROJECT_SOURCE_DIR}/src/mbgl/style/layers/custom_layer.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/style/layers/custom_layer_render_parameters.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/layermanager/custom_layer_factory.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/style/layers/custom_layer_impl.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/style/layers/custom_layer_impl.hpp
Expand Down
4 changes: 4 additions & 0 deletions bazel/core.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ MLN_CORE_SOURCE = [
"src/mbgl/style/layers/circle_layer_impl.cpp",
"src/mbgl/style/layers/circle_layer_impl.hpp",
"src/mbgl/style/layers/custom_layer.cpp",
"src/mbgl/style/layers/custom_layer_render_parameters.cpp",
"src/mbgl/style/layers/custom_layer_impl.cpp",
"src/mbgl/style/layers/custom_layer_impl.hpp",
"src/mbgl/style/layers/fill_extrusion_layer_impl.cpp",
Expand Down Expand Up @@ -774,6 +775,7 @@ MLN_CORE_HEADERS = [
"include/mbgl/style/layer.hpp",
"include/mbgl/style/layer_properties.hpp",
"include/mbgl/style/layers/custom_layer.hpp",
"include/mbgl/style/layers/custom_layer_render_parameters.hpp",
"include/mbgl/style/position.hpp",
"include/mbgl/style/property_expression.hpp",
"include/mbgl/style/property_value.hpp",
Expand Down Expand Up @@ -1066,6 +1068,7 @@ MLN_DRAWABLES_MTL_SOURCE = [
"src/mbgl/shaders/mtl/symbol_icon.cpp",
"src/mbgl/shaders/mtl/symbol_sdf.cpp",
"src/mbgl/shaders/mtl/symbol_text_and_icon.cpp",
"src/mbgl/style/layers/mtl/custom_layer_render_parameters.cpp",
]

MLN_DRAWABLES_MTL_HEADERS = [
Expand Down Expand Up @@ -1111,4 +1114,5 @@ MLN_DRAWABLES_MTL_HEADERS = [
"include/mbgl/shaders/mtl/symbol_icon.hpp",
"include/mbgl/shaders/mtl/symbol_sdf.hpp",
"include/mbgl/shaders/mtl/symbol_text_and_icon.hpp",
"include/mbgl/style/layers/mtl/custom_layer_render_parameters.hpp",
]
3 changes: 2 additions & 1 deletion include/mbgl/gfx/drawable_atlases_tweaker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ namespace mbgl {
class TileAtlasTextures;
using TileAtlasTexturesPtr = std::shared_ptr<TileAtlasTextures>;

namespace gfx {
class PaintParameters;

namespace gfx {
class Drawable;

/**
Expand Down
2 changes: 2 additions & 0 deletions include/mbgl/gfx/drawable_custom_layer_host_tweaker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

namespace mbgl {

class PaintParameters;

namespace gfx {

class Drawable;
Expand Down
1 change: 1 addition & 0 deletions include/mbgl/gl/drawable_gl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace mbgl {

template <class AttributeList>
class Segment;
class PaintParameters;

namespace gfx {

Expand Down
3 changes: 3 additions & 0 deletions include/mbgl/gl/layer_group_gl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include <mbgl/renderer/layer_group.hpp>

namespace mbgl {

class PaintParameters;

namespace gl {

/**
Expand Down
1 change: 1 addition & 0 deletions include/mbgl/mtl/drawable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace mbgl {

template <class AttributeList>
class Segment;
class PaintParameters;

namespace gfx {

Expand Down
3 changes: 3 additions & 0 deletions include/mbgl/mtl/layer_group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include <mbgl/renderer/layer_group.hpp>

namespace mbgl {

class PaintParameters;

namespace mtl {

/**
Expand Down
3 changes: 3 additions & 0 deletions include/mbgl/mtl/tile_layer_group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#include <optional>

namespace mbgl {

class PaintParameters;

namespace mtl {

/**
Expand Down
31 changes: 9 additions & 22 deletions include/mbgl/style/layers/custom_layer.hpp
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
#pragma once

#include <mbgl/style/layer.hpp>
#include <mbgl/style/layers/custom_layer_render_parameters.hpp>

#include <array>
#include <memory>

namespace mbgl {
namespace style {

/**
* Parameters that define the current camera position for a
* `CustomLayerHost::render()` function.
*/
struct CustomLayerRenderParameters {
double width;
double height;
double latitude;
double longitude;
double zoom;
double bearing;
double pitch;
double fieldOfView;
std::array<double, 16> projectionMatrix;
};
namespace style {

class CustomLayerHost {
public:
virtual ~CustomLayerHost() = default;
/**
* Initialize any GL state needed by the custom layer. This method is called
* Initialize any GL/Metal state needed by the custom layer. This method is called
* once, from the main thread, at a point when the GL context is active but
* before rendering for the first time.
*
Expand All @@ -38,28 +25,28 @@ class CustomLayerHost {

/**
* Render the layer. This method is called once per frame. The
* implementation should not make any assumptions about the GL state (other
* implementation should not make any assumptions about the GL/Metal state (other
* than that the correct context is active). It may make changes to the
* state, and is not required to reset values such as the depth mask,
* stencil mask, and corresponding test flags to their original values. Make
* sure that you are drawing your fragments with a z value of 1 to take
* advantage of the opaque fragment culling in case there are opaque layers
* above your custom layer.
*/
virtual void render(const CustomLayerRenderParameters&) = 0;
virtual void render(const mbgl::style::CustomLayerRenderParameters&) = 0;

/**
* Called when the system has destroyed the underlying GL context. The
* Called when the system has destroyed the underlying GL/Metal context. The
* `deinitialize` function will not be called in this case, however
* `initialize` will be called instead to prepare for a new render.
*
*/
virtual void contextLost() = 0;

/**
* Destroy any GL state needed by the custom layer, and deallocate context,
* Destroy any GL/Metal state needed by the custom layer, and deallocate context,
* if necessary. This method is called once, from the main thread, at a
* point when the GL context is active.
* point when the GL/Metal context is active.
*
* Note that it may be called even when the `initialize` function has not
* been called.
Expand Down
31 changes: 31 additions & 0 deletions include/mbgl/style/layers/custom_layer_render_parameters.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include <memory>
#include <array>

namespace mbgl {

class PaintParameters;

namespace style {

/**
* Parameters that define the current camera position for a
* `CustomLayerHost::render()` function.
*/
struct CustomLayerRenderParameters {
double width;
double height;
double latitude;
double longitude;
double zoom;
double bearing;
double pitch;
double fieldOfView;
std::array<double, 16> projectionMatrix;

CustomLayerRenderParameters(const PaintParameters&);
};

} // namespace style
} // namespace mbgl
30 changes: 30 additions & 0 deletions include/mbgl/style/layers/mtl/custom_layer_render_parameters.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include <mbgl/style/layers/custom_layer_render_parameters.hpp>

#include <mbgl/mtl/mtl_fwd.hpp>
#include <Foundation/Foundation.hpp>
#include <Metal/Metal.hpp>

#include <memory>

namespace mbgl {

class PaintParameters;

namespace style {

namespace mtl {

/**
* Metal subclass of CustomLayerRenderParameters
*/
struct CustomLayerRenderParameters : mbgl::style::CustomLayerRenderParameters {
mbgl::mtl::MTLRenderCommandEncoderPtr encoder;

CustomLayerRenderParameters(const PaintParameters&);
};

} // namespace mtl
} // namespace style
} // namespace mbgl
17 changes: 4 additions & 13 deletions platform/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ objc_library(
"//platform/ios:ios_public_hdrs",
"//platform/ios:ios_sdk_hdrs",
] + select({
"//:metal_renderer": [],
"//conditions:default": [
"//platform/darwin:darwin_objcpp_opengl_srcs",
],
}) + select({
"//:legacy_renderer": [],
"//conditions:default": [
"//platform/darwin:darwin_objcpp_custom_drawable_srcs",
Expand Down Expand Up @@ -193,13 +188,9 @@ objc_library(
name = "iosapp",
srcs = [
"//platform/ios:ios_app_srcs",
] + select({
"//:metal_renderer": [],
"//conditions:default": [
"//platform/darwin:app/LimeGreenStyleLayer.h",
"//platform/darwin:app/LimeGreenStyleLayer.m",
],
}),
"//platform/darwin:app/CustomStyleLayerExample.h",
"//platform/darwin:app/CustomStyleLayerExample.m",
],
defines = ["GLES_SILENCE_DEPRECATION"],
includes = [
"darwin/app",
Expand All @@ -211,7 +202,7 @@ objc_library(
"MetalKit",
],
"//conditions:default": [
"GLKit", # needed for LimeGreenStyleLayer
"GLKit", # needed for CustomStyleLayerExample
],
}),
visibility = ["//visibility:public"],
Expand Down
1 change: 1 addition & 0 deletions platform/android/src/example_custom_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <jni.h>
#include <mbgl/style/layers/custom_layer.hpp>
#include <sstream>
#include <memory>

// DEBUGGING

Expand Down
22 changes: 3 additions & 19 deletions platform/darwin/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ load(
"MLN_DARWIN_OBJC_HEADERS",
"MLN_DARWIN_PRIVATE_HEADERS",
"MLN_DARWIN_PUBLIC_OBJCPP_CUSTOM_DRAWABLE_SOURCE",
"MLN_DARWIN_PUBLIC_OBJCPP_OPENGL_SOURCE",
"MLN_DARWIN_PUBLIC_OBJCPP_SOURCE",
"MLN_DARWIN_PUBLIC_OBJC_SOURCE",
"MLN_GENERATED_DARWIN_STYLE_HEADERS",
Expand All @@ -33,10 +32,7 @@ filegroup(

filegroup(
name = "darwin_objcpp_hdrs",
srcs = MLN_DARWIN_OBJCPP_HEADERS + select({
"//:metal_renderer": [],
"//conditions:default": ["src/MLNOpenGLStyleLayer.h"],
}),
srcs = MLN_DARWIN_OBJCPP_HEADERS,
visibility = ["//visibility:public"],
)

Expand All @@ -46,12 +42,6 @@ filegroup(
visibility = ["//visibility:public"],
)

filegroup(
name = "darwin_objcpp_opengl_srcs",
srcs = MLN_DARWIN_PUBLIC_OBJCPP_OPENGL_SOURCE,
visibility = ["//visibility:public"],
)

filegroup(
name = "darwin_objcpp_custom_drawable_srcs",
srcs = MLN_DARWIN_PUBLIC_OBJCPP_CUSTOM_DRAWABLE_SOURCE,
Expand Down Expand Up @@ -319,14 +309,13 @@ exports_files(
[
"test/amsterdam.geojson",
"test/MLNSDKTestHelpers.swift",
"app/LimeGreenStyleLayer.h",
"app/LimeGreenStyleLayer.m",
"app/CustomStyleLayerExample.h",
"app/CustomStyleLayerExample.m",
"app/ExampleCustomDrawableStyleLayer.h",
"app/ExampleCustomDrawableStyleLayer.mm",
"include/mbgl/util/image+MLNAdditions.hpp",
] + MLN_DARWIN_PUBLIC_OBJC_SOURCE +
MLN_DARWIN_PUBLIC_OBJCPP_SOURCE +
MLN_DARWIN_PUBLIC_OBJCPP_OPENGL_SOURCE +
MLN_DARWIN_PUBLIC_OBJCPP_CUSTOM_DRAWABLE_SOURCE +
MLN_DARWIN_PRIVATE_HEADERS +
MLN_DARWIN_OBJC_HEADERS +
Expand Down Expand Up @@ -359,11 +348,6 @@ js_library(
":generated_style_hdrs",
":generated_style_srcs",
] + select({
"//:metal_renderer": [],
"//conditions:default": [
":darwin_objcpp_opengl_srcs",
],
}) + select({
"//:legacy_renderer": [],
"//conditions:default": [
":darwin_objcpp_custom_drawable_srcs",
Expand Down
5 changes: 5 additions & 0 deletions platform/darwin/app/CustomStyleLayerExample.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#import "Mapbox.h"

@interface CustomStyleLayerExample : MLNCustomStyleLayer

@end