Changes to the custom Metal layer to allow more flexible rendering (#4446)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: louwers <649392+louwers@users.noreply.github.com>
Co-authored-by: Bart Louwers <bart@emeel.net>
This commit is contained in:
Steve Gifford
2026-08-11 15:23:35 -07:00
committed by GitHub
parent d9664ee187
commit 49f80e95f3
41 changed files with 281 additions and 128 deletions

View File

@@ -25,6 +25,7 @@ public:
mtl::CommandEncoder& getCommandEncoder() { return commandEncoder; }
const mtl::CommandEncoder& getCommandEncoder() const { return commandEncoder; }
const MTLCommandBufferPtr& getCommandBuffer() const { return commandBuffer; }
const MTLRenderCommandEncoderPtr& getMetalEncoder() const { return encoder; }
const gfx::RenderPassDescriptor& getDescriptor() const { return descriptor; }
@@ -71,6 +72,7 @@ private:
private:
gfx::RenderPassDescriptor descriptor;
mtl::CommandEncoder& commandEncoder;
MTLCommandBufferPtr commandBuffer;
MTLRenderCommandEncoderPtr encoder;
MTLDepthStencilStatePtr currentDepthStencilState;
MTLRenderPipelineStatePtr currentPipelineState;

View File

@@ -1,5 +1,6 @@
#pragma once
#include <mbgl/gfx/context.hpp>
#include <mbgl/style/layers/custom_layer_init_parameters.hpp>
#include <mbgl/style/layers/custom_layer_render_parameters.hpp>
@@ -24,6 +25,11 @@ public:
*/
virtual void initialize(const CustomLayerInitParameters&) = 0;
/**
* Called right before the layers start rendering.
*/
virtual void preRender(const mbgl::gfx::Context&, const mbgl::style::CustomLayerRenderParameters&) {};
/**
* Render the layer. This method is called once per frame. The
* implementation should not make any assumptions about the GL/Metal state (other

View File

@@ -1,6 +1,7 @@
#pragma once
#include <mbgl/style/layers/custom_layer_render_parameters.hpp>
#include <mbgl/gfx/render_pass.hpp>
#include <mbgl/mtl/mtl_fwd.hpp>
#include <Foundation/Foundation.hpp>
@@ -20,9 +21,12 @@ namespace mtl {
* Metal subclass of CustomLayerRenderParameters
*/
struct CustomLayerRenderParameters : mbgl::style::CustomLayerRenderParameters {
const std::unique_ptr<mbgl::gfx::RenderPass> &renderPass;
mbgl::mtl::MTLRenderCommandEncoderPtr encoder;
mbgl::mtl::MTLCommandBufferPtr commandBuffer;
mbgl::mtl::MTLRenderPassDescriptorPtr renderPassDesc;
CustomLayerRenderParameters(const PaintParameters&);
CustomLayerRenderParameters(const PaintParameters &);
};
} // namespace mtl