VisuTwin Canvas
C++ 3D Engine — Metal Backend
Loading...
Searching...
No Matches
metalRenderTarget.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2025-2026 Arnis Lektauers
3//
4// Created by Arnis Lektauers on 22.10.2025.
5//
6#pragma once
7
8#include "Metal/Metal.hpp"
10
11namespace visutwin::canvas
12{
14
19 public:
20 MTL::PixelFormat pixelFormat = MTL::PixelFormatInvalid;
21
22 MTL::Texture* texture = nullptr;
23
24 // Multi-sampled buffer
25 MTL::Texture* multisampledBuffer = nullptr;
26
27 ColorAttachment() = default;
28 ~ColorAttachment() = default;
29
30 void destroy();
31 };
32
37 public:
38 MTL::PixelFormat pixelFormat = MTL::PixelFormatInvalid;
39
40 // True if the format has stencil
41 bool hasStencil = false;
42
43 // Depth texture
44 MTL::Texture* depthTexture = nullptr;
45
46 // True if the depthTexture is internally allocated / owned
48
49 // Multi-sampled depth buffer allocated over the user-provided depth buffer
50 MTL::Texture* multisampledDepthBuffer = nullptr;
51
52 explicit DepthAttachment(MTL::PixelFormat format, bool hasStencil);
53
54 ~DepthAttachment() = default;
55
56 // Destroy resources
57 void destroy(MetalGraphicsDevice* device);
58 };
59
65 {
66 public:
67 explicit MetalRenderTarget(const RenderTargetOptions& options = {});
68
69 virtual ~MetalRenderTarget();
70
71 const std::vector<std::shared_ptr<ColorAttachment>>& colorAttachments() const { return _colorAttachments; }
72 const std::shared_ptr<DepthAttachment>& depthAttachment() const { return _depthAttachment; }
73 void ensureAttachments();
74
75 private:
76 void destroyFrameBuffers() override;
77 void createFrameBuffers() override;
78
79 std::vector<std::shared_ptr<ColorAttachment>> _colorAttachments;
80 std::shared_ptr<DepthAttachment> _depthAttachment;
81 };
82}
DepthAttachment(MTL::PixelFormat format, bool hasStencil)
void destroy(MetalGraphicsDevice *device)
MetalRenderTarget(const RenderTargetOptions &options={})
const std::vector< std::shared_ptr< ColorAttachment > > & colorAttachments() const
const std::shared_ptr< DepthAttachment > & depthAttachment() const
virtual void destroyFrameBuffers()=0
RenderTarget(const RenderTargetOptions &options={})
virtual void createFrameBuffers()=0