-
-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathrender_pass.hpp
More file actions
260 lines (219 loc) · 6.19 KB
/
Copy pathrender_pass.hpp
File metadata and controls
260 lines (219 loc) · 6.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/**
* @file liblava/block/render_pass.hpp
* @brief Render pass
* @authors Lava Block OÜ and contributors
* @copyright Copyright (c) 2018-present, MIT License
*/
#pragma once
#include "liblava/base/device.hpp"
#include "liblava/block/attachment.hpp"
#include "liblava/block/subpass.hpp"
namespace lava {
/**
* @brief Render pass
*/
struct render_pass : entity {
/// Shared pointer to render pass
using s_ptr = std::shared_ptr<render_pass>;
/// List of render passes
using s_list = std::vector<s_ptr>;
/**
* @brief Make a new render pass
* @param device Vulkan device
* @return s_ptr Shared pointer to render pass
*/
static s_ptr make(device::ptr device) {
return std::make_shared<render_pass>(device);
}
/**
* @brief Construct a new render pass
* @param device Vulkan device
*/
explicit render_pass(device::ptr device);
/**
* @brief Create a new render pass
* @param target_attachments List of target attachments
* @param area Rectangle area
* @return Create was successful or failed
*/
bool create(VkAttachmentsRef target_attachments,
rect::ref area);
/**
* @brief Destroy the render pass
*/
void destroy();
/**
* @brief Process the render pass
* @param cmd_buf Command buffer
* @param frame Frame index
*/
void process(VkCommandBuffer cmd_buf,
index frame);
/**
* @brief Get the device
* @return device::ptr Vulkan device
*/
device::ptr get_device() {
return m_device;
}
/**
* @brief Get the render pass
* @return VkRenderPass Vulkan render pass
*/
VkRenderPass get() const {
return m_vk_render_pass;
}
/**
* @brief Get the subpass count
* @return ui32 Number of subpasses
*/
ui32 get_subpass_count() const {
return to_ui32(m_subpasses.size());
}
/**
* @brief Check if subpass exists
* @param index Index to check
* @return Subpass exists or not
*/
bool exists_subpass(index index = 0) const {
return index < m_subpasses.size();
}
/**
* @brief Get the subpass
* @param index Index of subpass
* @return subpass* Subpass
*/
subpass* get_subpass(index index = 0) {
return m_subpasses.at(index).get();
}
/**
* @brief Get the subpasses
* @return subpass::s_list const& List of subpasses
*/
subpass::s_list const& get_subpasses() const {
return m_subpasses;
}
/**
* @brief Add an attachment
* @param attachment Attachment
*/
void add(attachment::s_ptr const& attachment) {
m_attachments.push_back(attachment);
}
/**
* @brief Add a subpass dependency
* @param dependency Subpass dependency
*/
void add(subpass_dependency::s_ptr const& dependency) {
m_dependencies.push_back(dependency);
}
/**
* @brief Add a subpass
* @param subpass Subpass
*/
void add(subpass::s_ptr const& subpass) {
m_subpasses.push_back(subpass);
}
/**
* @brief Set the clear values
* @param values List of clear values
*/
void set_clear_values(VkClearValues const& values) {
m_clear_values = values;
}
/**
* @brief Get the clear values
* @return VkClearValues const& List of clear values
*/
VkClearValues const& get_clear_values() const {
return m_clear_values;
}
/**
* @brief Set the clear color
* @param value Clear color
*/
void set_clear_color(v3 value = {});
/**
* @brief Get the clear color
* @return v3 Clear color
*/
v3 get_clear_color() const;
/**
* @brief Add a render pipeline to the back of subpass
* @param pipeline Render pipeline
* @param subpass Subpass
*/
void add(render_pipeline::s_ptr pipeline,
index subpass = 0) {
m_subpasses.at(subpass)->add(pipeline);
}
/**
* @brief Add a render pipeline to the front of subpass
* @param pipeline Render pipeline
* @param subpass Subpass
*/
void add_front(render_pipeline::s_ptr pipeline,
index subpass = 0) {
m_subpasses.at(subpass)->add_front(pipeline);
}
/**
* @brief Remove a render pipeline from the subpass
* @param pipeline Render pipeline
* @param subpass Subpass
*/
void remove(render_pipeline::s_ptr pipeline,
index subpass = 0) {
m_subpasses.at(subpass)->remove(pipeline);
}
/**
* @brief Get the target callback
* @return target_callback const& Target callback
*/
target_callback const& get_target_callback() const {
return m_callback;
}
private:
/// Vulkan device
device::ptr m_device = nullptr;
/// Vulkan render pass
VkRenderPass m_vk_render_pass = VK_NULL_HANDLE;
/// List of frame buffers
VkFramebuffers m_framebuffers = {};
/// List of attachments
attachment::s_list m_attachments;
/// List of subpass dependencies
subpass_dependency::s_list m_dependencies;
/// List of subpasses
subpass::s_list m_subpasses;
/// List of clear values
VkClearValues m_clear_values = {};
/// Rectangle area
rect m_area;
/// Target callback
target_callback m_callback;
/**
* @brief Begin the render pass
* @param cmd_buf Command buffer
* @param frame Frame index
*/
void begin(VkCommandBuffer cmd_buf,
index frame);
/**
* @brief End the render pass
* @param cmd_buf Command buffer
*/
void end(VkCommandBuffer cmd_buf);
/**
* @brief Called on target created
* @param target_attachments List of target attachments
* @param area Rectangle area
* @return Create was successful or failed
*/
bool on_target_created(VkAttachmentsRef target_attachments,
rect::ref area);
/**
* @brief Called on target destroyed
*/
void on_target_destroyed();
};
} // namespace lava