VisuTwin Canvas
C++ 3D Engine — Metal Backend
Loading...
Searching...
No Matches
renderPass.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 11.09.2025.
5//
6#pragma once
7
8#include <memory>
9#include <vector>
10
11#include "renderTarget.h"
12#include "core/math/color.h"
13
14namespace visutwin::canvas
15{
17 {
18 float scaleX = 1.0f;
19
20 float scaleY = 1.0f;
21
22 std::shared_ptr<Texture> resizeSource;
23 };
24
29 public:
30 Color clearValue{0.0f, 0.0f, 0.0f, 1.0f}; // Color to clear to (sRGB space)
31 Color clearValueLinear{0.0f, 0.0f, 0.0f, 1.0f}; // Color to clear to (linear space)
32 bool clear = false; // Clear before rendering
33 bool store = false; // Store after render pass
34 bool resolve = true; // Resolve multi-sampled surface
35 bool genMipmaps = false; // Generate mipmaps after rendering
36
37 ColorAttachmentOps() = default;
38 };
39
45 public:
46 float clearDepthValue = 1.0f; // Depth value to clear to
47 int clearStencilValue = 0; // Stencil value to clear to
48 bool clearDepth = false; // Clear depth before rendering
49 bool clearStencil = false; // Clear stencil before rendering
50 bool storeDepth = false; // Store depth after render pass
51 bool resolveDepth = false; // Resolve multi-sampled depth
52 bool storeStencil = false; // Store stencil after render pass
53
55 };
56
57 class GraphicsDevice;
58
59 /*
60 * A render pass represents a node in the frame graph and encapsulates a system which
61 * renders to a render target using an execution callback
62 */
64 {
65 public:
66 RenderPass(const std::shared_ptr<GraphicsDevice>& device) : _device(device) {};
67
68 virtual void init(const std::shared_ptr<RenderTarget>& renderTarget = nullptr,
69 const std::shared_ptr<RenderPassOptions>& options = nullptr);
70
71 virtual void frameUpdate() const;
72
73 virtual void before() {}
74 virtual void after() {}
75 virtual void execute() {}
76
77 void render();
78
79 float scaleX() const { return _options ? _options->scaleX : 1.0f; }
80
81 float scaleY() const { return _options ? _options->scaleY : 1.0f; }
82
83 const std::vector<std::shared_ptr<RenderPass>>& beforePasses() const { return _beforePasses; }
84
85 const std::vector<std::shared_ptr<RenderPass>>& afterPasses() const { return _afterPasses; }
86 void addBeforePass(const std::shared_ptr<RenderPass>& renderPass);
87 void addAfterPass(const std::shared_ptr<RenderPass>& renderPass);
88 void clearBeforePasses();
89 void clearAfterPasses();
90
91 void setClearColor(const Color* color = nullptr);
92 void setClearDepth(const float* depthValue = nullptr);
93 void setClearStencil(const int* stencilValue = nullptr);
94
95 bool enabled() const { return _enabled; }
96 void setEnabled(bool value);
97
98 std::shared_ptr<RenderTarget> renderTarget() const { return _renderTarget; };
99
100 const std::vector<std::shared_ptr<ColorAttachmentOps>>& colorArrayOps() const { return _colorArrayOps; }
101
102 std::shared_ptr<DepthStencilAttachmentOps> depthStencilOps() const { return _depthStencilOps; }
103
104 void setSkipStart(const bool value) { _skipStart = value; }
105 void setSkipEnd(const bool value) { _skipEnd = value; }
106
107 bool requiresCubemaps() const { return _requiresCubemaps; }
108 void setRequiresCubemaps(bool value) { _requiresCubemaps = value; }
109
110 virtual void onEnable() {}
111 virtual void onDisable() {}
112
113 void setOptions(const std::shared_ptr<RenderPassOptions>& value);
114
115 void allocateAttachments();
116
117 virtual void postInit() {}
118
119 void log(std::shared_ptr<GraphicsDevice> device, int index = 0) const;
120
121 std::shared_ptr<ColorAttachmentOps> colorOps() const;
122
123 protected:
124 std::shared_ptr<GraphicsDevice> device() const { return _device; }
125
126 bool _requiresCubemaps = true;
127
128 std::string _name;
129
130 private:
131 std::shared_ptr<GraphicsDevice> _device;
132
133 std::shared_ptr<RenderPassOptions> _options;
134
135 std::shared_ptr<RenderTarget> _renderTarget;
136 bool _renderTargetInitialized = false;
137
138 // Render passes which need to be executed before this pass
139 std::vector<std::shared_ptr<RenderPass>> _beforePasses;
140 std::vector<std::shared_ptr<RenderPass>> _afterPasses;
141
142 bool _enabled = true;
143
144 bool _executeEnabled = true;
145
146 bool _skipStart = false;
147 bool _skipEnd = false;
148
149 std::vector<std::shared_ptr<ColorAttachmentOps>> _colorArrayOps;
150 std::shared_ptr<DepthStencilAttachmentOps> _depthStencilOps;
151
152 int _samples = 0;
153 };
154}
Abstract GPU interface for resource creation, state management, and draw submission.
virtual void init(const std::shared_ptr< RenderTarget > &renderTarget=nullptr, const std::shared_ptr< RenderPassOptions > &options=nullptr)
void setClearColor(const Color *color=nullptr)
void setClearDepth(const float *depthValue=nullptr)
const std::vector< std::shared_ptr< ColorAttachmentOps > > & colorArrayOps() const
Definition renderPass.h:100
void setSkipEnd(const bool value)
Definition renderPass.h:105
void setSkipStart(const bool value)
Definition renderPass.h:104
void setRequiresCubemaps(bool value)
Definition renderPass.h:108
std::shared_ptr< DepthStencilAttachmentOps > depthStencilOps() const
Definition renderPass.h:102
void setClearStencil(const int *stencilValue=nullptr)
std::shared_ptr< RenderTarget > renderTarget() const
Definition renderPass.h:98
virtual void frameUpdate() const
std::shared_ptr< GraphicsDevice > device() const
Definition renderPass.h:124
const std::vector< std::shared_ptr< RenderPass > > & beforePasses() const
Definition renderPass.h:83
RenderPass(const std::shared_ptr< GraphicsDevice > &device)
Definition renderPass.h:66
void addBeforePass(const std::shared_ptr< RenderPass > &renderPass)
std::shared_ptr< ColorAttachmentOps > colorOps() const
void addAfterPass(const std::shared_ptr< RenderPass > &renderPass)
const std::vector< std::shared_ptr< RenderPass > > & afterPasses() const
Definition renderPass.h:85
void setEnabled(bool value)
void setOptions(const std::shared_ptr< RenderPassOptions > &value)
RGBA color with floating-point components in [0, 1].
Definition color.h:18
std::shared_ptr< Texture > resizeSource
Definition renderPass.h:22