VisuTwin Canvas
C++ 3D Engine — Metal Backend
Loading...
Searching...
No Matches
renderTarget.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 12.09.2025.
5//
6#pragma once
7
8#include <unordered_set>
9
10#include "texture.h"
11
12namespace visutwin::canvas
13{
15 {
17
18 Texture* colorBuffer = nullptr;
19
20 std::vector<Texture*> colorBuffers;
21
22 Texture* depthBuffer = nullptr;
23
24 bool depth = false;
25
26 int face = 0;
27
28 int samples = 1;
29
30 bool stencil = false;
31
32 bool autoResolve = false;
33
34 std::string name;
35
36 int mipLevel = 0;
37
38 bool flipY;
39 };
40
41 /*
42 * A render target is a rectangular rendering surface
43 */
45 {
46 public:
47 explicit RenderTarget(const RenderTargetOptions& options = {});
48
49 virtual ~RenderTarget();
50
51 // Width of the render target in pixels
52 int width() const;
53
54 int height() const;
55
56 void resize(int width, int height);
57
58 Texture* colorBuffer() const { return _colorBuffer; }
59
60 int samples() const { return _samples; }
61
62 bool hasDepthBuffer() const { return _depthBuffer != nullptr; }
63 bool hasDepth() const { return _depth; }
64
65 int colorBufferCount() const { return _colorBuffers.size(); }
66
67 bool hasMipmaps() const { return _mipmaps; }
68
69 Texture* getColorBuffer(size_t index) const;
70
71 bool hasStencil() const { return _stencil; }
72
73 int mipLevel() const { return _mipLevel; }
74
75 const std::string& name() const { return _name; }
76
77 Texture* depthBuffer() const { return _depthBuffer; }
78 bool autoResolve() const { return _autoResolve; }
79
80 // Cubemap face index (0-5). Used when rendering to a specific face of a cubemap texture.
81 int face() const { return _face; }
82
83 int key() const { return _id; }
84
85 protected:
86 GraphicsDevice* device() const { return _device; }
87
88 // Validates that all MRT color buffers have the same dimensions and settings
89 void validateMrt();
90
91 virtual void destroyFrameBuffers() = 0;
92 virtual void createFrameBuffers() = 0;
93
94 private:
95 GraphicsDevice* _device;
96
97 int _mipLevel;
98
99 Texture* _colorBuffer = nullptr;
100
101 std::vector<Texture*> _colorBuffers;
102
103 Texture* _depthBuffer = nullptr;
104
105 int _samples = 1;
106
107 bool _mipmaps = true;
108
109 bool _stencil;
110
111 std::string _name;
112
113 int _id;
114
115 bool _depth;
116
117 int _face;
118
119 bool _autoResolve;
120
121 bool _flipY;
122 };
123}
Abstract GPU interface for resource creation, state management, and draw submission.
Texture * getColorBuffer(size_t index) const
GraphicsDevice * device() const
virtual void destroyFrameBuffers()=0
void resize(int width, int height)
RenderTarget(const RenderTargetOptions &options={})
Texture * depthBuffer() const
virtual void createFrameBuffers()=0
const std::string & name() const
Texture * colorBuffer() const
GPU texture resource supporting 2D, cubemap, volume, and array formats with mipmap management.
Definition texture.h:57
std::vector< Texture * > colorBuffers