From 14d3c7529d29a2bfb8733d0b112a38cdb8a0175b Mon Sep 17 00:00:00 2001 From: Yaroslav Date: Thu, 9 Jul 2026 20:55:59 +0300 Subject: [PATCH] core: add nearClippedProjectionMatrix to MLNCustomStyleLayer (#4364) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Bart Louwers --- .../mbgl/style/layers/custom_layer_render_parameters.hpp | 6 ++++++ platform/darwin/src/MLNCustomStyleLayer.h | 4 +++- platform/darwin/src/MLNCustomStyleLayer.mm | 3 ++- src/mbgl/style/layers/custom_layer_render_parameters.cpp | 1 + 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/mbgl/style/layers/custom_layer_render_parameters.hpp b/include/mbgl/style/layers/custom_layer_render_parameters.hpp index 54eb7d90d..226b3b4a0 100644 --- a/include/mbgl/style/layers/custom_layer_render_parameters.hpp +++ b/include/mbgl/style/layers/custom_layer_render_parameters.hpp @@ -22,8 +22,14 @@ struct CustomLayerRenderParameters { double bearing; double pitch; double fieldOfView; + + /// Standard projection matrix (nearZ = 1 tile unit). + /// Use this for 2D/flat custom geometry. std::array projectionMatrix; + /// A 4×4 matrix representing the map view’s current near clip projection state. + std::array nearClippedProjectionMatrix; + CustomLayerRenderParameters(const PaintParameters&); }; diff --git a/platform/darwin/src/MLNCustomStyleLayer.h b/platform/darwin/src/MLNCustomStyleLayer.h index d0c57a714..4958157f6 100644 --- a/platform/darwin/src/MLNCustomStyleLayer.h +++ b/platform/darwin/src/MLNCustomStyleLayer.h @@ -30,8 +30,10 @@ typedef struct MLNStyleLayerDrawingContext { CGFloat pitch; /// The vertical field of view, in degrees, for the map’s perspective. CGFloat fieldOfView; - /// A 4×4 matrix representing the map view’s current projection state. + /// Standard projection matrix (nearZ = 1 tile unit). Use for 2D/flat geometry. MLNMatrix4 projectionMatrix; + /// A 4×4 matrix representing the map view’s current near clip projection state. + MLNMatrix4 nearClippedProjectionMatrix; } MLNStyleLayerDrawingContext; /// A style layer that is rendered by Metal code that you provide. diff --git a/platform/darwin/src/MLNCustomStyleLayer.mm b/platform/darwin/src/MLNCustomStyleLayer.mm index 23d955c73..28d63e1d3 100644 --- a/platform/darwin/src/MLNCustomStyleLayer.mm +++ b/platform/darwin/src/MLNCustomStyleLayer.mm @@ -117,7 +117,8 @@ public: .direction = mbgl::util::wrap(parameters.bearing, 0., 360.), .pitch = static_cast(parameters.pitch), .fieldOfView = static_cast(parameters.fieldOfView), - .projectionMatrix = MLNMatrix4Make(parameters.projectionMatrix)}; + .projectionMatrix = MLNMatrix4Make(parameters.projectionMatrix), + .nearClippedProjectionMatrix = MLNMatrix4Make(parameters.nearClippedProjectionMatrix)}; if (layer.mapView) { [layer drawInMapView:layer.mapView withContext:drawingContext]; diff --git a/src/mbgl/style/layers/custom_layer_render_parameters.cpp b/src/mbgl/style/layers/custom_layer_render_parameters.cpp index 67fb1e939..cf29b1817 100644 --- a/src/mbgl/style/layers/custom_layer_render_parameters.cpp +++ b/src/mbgl/style/layers/custom_layer_render_parameters.cpp @@ -18,6 +18,7 @@ CustomLayerRenderParameters::CustomLayerRenderParameters(const mbgl::PaintParame mat4 projMatrix; state.getProjMatrix(projMatrix); projectionMatrix = projMatrix; + nearClippedProjectionMatrix = paintParameters.transformParams.nearClippedProjMatrix; } } // namespace style