PixelBullet  0.0.1
A C++ game engine
Loading...
Searching...
No Matches
RenderStage.hpp
1#pragma once
2
3#include "PixelBullet/Graphics/Images/ImageDepth.hpp"
4#include "PixelBullet/Graphics/Renderpass/Framebuffers.hpp"
5#include "PixelBullet/Graphics/Renderpass/Renderpass.hpp"
6#include "PixelBullet/Graphics/Renderpass/Swapchain.hpp"
7#include "PixelBullet/Math/Color.hpp"
8
9#include <glm/glm.hpp>
10
11#include <map>
12
13namespace PixelBullet
14{
19 {
20 public:
21 enum class Type
22 {
23 Image,
24 Depth,
26 };
27
37 Attachment(uint32_t binding, std::string name, Type type, bool multisampled = false,
38 VkFormat format = VK_FORMAT_R8G8B8A8_UNORM, const Color& clearColour = Color::Black)
39 : m_Binding(binding)
40 , m_Name(std::move(name))
41 , m_Type(type)
42 , m_Multisampled(multisampled)
43 , m_Format(format)
44 , m_ClearColor(clearColour)
45 {
46 }
47
48 uint32_t GetBinding() const
49 {
50 return m_Binding;
51 }
52 const std::string& GetName() const
53 {
54 return m_Name;
55 }
56 Type GetType() const
57 {
58 return m_Type;
59 }
60 bool IsMultisampled() const
61 {
62 return m_Multisampled;
63 }
64 VkFormat GetFormat() const
65 {
66 return m_Format;
67 }
68 const Color& GetClearColour() const
69 {
70 return m_ClearColor;
71 }
72
73 private:
74 uint32_t m_Binding;
75 std::string m_Name;
76 Type m_Type;
77 bool m_Multisampled;
78 VkFormat m_Format;
79 Color m_ClearColor;
80 };
81
83 {
84 public:
85 SubpassType(uint32_t binding, std::vector<uint32_t> attachmentBindings)
86 : m_Binding(binding)
87 , m_AttachmentBindings(std::move(attachmentBindings))
88 {
89 }
90
91 uint32_t GetBinding() const
92 {
93 return m_Binding;
94 }
95 const std::vector<uint32_t>& GetAttachmentBindings() const
96 {
97 return m_AttachmentBindings;
98 }
99
100 private:
101 uint32_t m_Binding;
102 std::vector<uint32_t> m_AttachmentBindings;
103 };
104
106 {
107 public:
108 explicit RenderArea(const glm::uvec2& extent = {}, const glm::ivec2& offset = {})
109 : m_Extent(extent)
110 , m_Offset(offset)
111 {
112 }
113
114 bool operator==(const RenderArea& rhs) const
115 {
116 return m_Extent == rhs.m_Extent && m_Offset == rhs.m_Offset;
117 }
118
119 bool operator!=(const RenderArea& rhs) const
120 {
121 return !(*this == rhs);
122 }
123
124 const glm::uvec2& GetExtent() const
125 {
126 return m_Extent;
127 }
128 void SetExtent(const glm::uvec2& extent)
129 {
130 this->m_Extent = extent;
131 }
132
133 const glm::ivec2& GetOffset() const
134 {
135 return m_Offset;
136 }
137 void SetOffset(const glm::ivec2& offset)
138 {
139 this->m_Offset = offset;
140 }
141
146 float GetAspectRatio() const
147 {
148 return m_AspectRatio;
149 }
150 void SetAspectRatio(float aspectRatio)
151 {
152 this->m_AspectRatio = aspectRatio;
153 }
154
155 private:
156 glm::uvec2 m_Extent;
157 glm::ivec2 m_Offset;
158 float m_AspectRatio = 1.0f;
159 };
160
162 {
163 public:
164 Viewport() = default;
165
166 explicit Viewport(const glm::uvec2& size)
167 : m_Size(size)
168 {
169 }
170
171 const glm::vec2& GetScale() const
172 {
173 return m_Scale;
174 }
175 void SetScale(const glm::vec2& scale)
176 {
177 this->m_Scale = scale;
178 }
179
180 const std::optional<glm::uvec2>& GetSize() const
181 {
182 return m_Size;
183 }
184 void SetSize(const std::optional<glm::uvec2>& size)
185 {
186 this->m_Size = size;
187 }
188
189 const glm::ivec2& GetOffset() const
190 {
191 return m_Offset;
192 }
193 void SetOffset(const glm::ivec2& offset)
194 {
195 this->m_Offset = offset;
196 }
197
198 private:
199 glm::vec2 m_Scale{ 1.0f, 1.0f };
200 std::optional<glm::uvec2> m_Size;
201 glm::ivec2 m_Offset;
202 };
203
205 {
206 friend class Graphics;
207
208 public:
209 explicit RenderStage(std::vector<Attachment> images = {}, std::vector<SubpassType> subpasses = {},
210 const Viewport& viewport = Viewport());
211
212 void Update();
213 void Rebuild(const Swapchain& swapchain);
214
215 std::optional<Attachment> GetAttachment(const std::string& name) const;
216 std::optional<Attachment> GetAttachment(uint32_t binding) const;
217
218 const Descriptor* GetDescriptor(const std::string& name) const;
219 const VkFramebuffer& GetActiveFramebuffer(uint32_t activeSwapchainImage) const;
220
221 const std::vector<Attachment>& GetAttachments() const
222 {
223 return m_Attachments;
224 }
225 const std::vector<SubpassType>& GetSubpasses() const
226 {
227 return m_Subpasses;
228 }
229
230 Viewport& GetViewport()
231 {
232 return m_Viewport;
233 }
234 void SetViewport(const Viewport& viewport)
235 {
236 this->m_Viewport = viewport;
237 }
238
244 {
245 return m_RenderArea;
246 }
247
252 bool IsOutOfDate() const
253 {
254 return m_OutOfDate;
255 }
256
257 const Renderpass* GetRenderpass() const
258 {
259 return m_Renderpass.get();
260 }
261 const ImageDepth* GetDepthStencil() const
262 {
263 return m_DepthStencil.get();
264 }
265 const Framebuffers* GetFramebuffers() const
266 {
267 return m_Framebuffers.get();
268 }
269 const std::vector<VkClearValue>& GetClearValues() const
270 {
271 return m_ClearValues;
272 }
273 uint32_t GetAttachmentCount(uint32_t subpass) const
274 {
275 return m_SubpassAttachmentCount[subpass];
276 }
277 bool HasDepth() const
278 {
279 return m_DepthAttachment.has_value();
280 }
281 bool HasSwapchain() const
282 {
283 return m_SwapchainAttachment.has_value();
284 }
285 bool IsMultisampled(uint32_t subpass) const
286 {
287 return m_SubpassMultisampled[subpass];
288 }
289
290 private:
291 std::vector<Attachment> m_Attachments;
292 std::vector<SubpassType> m_Subpasses;
293
294 Viewport m_Viewport;
295
296 std::unique_ptr<Renderpass> m_Renderpass;
297 std::unique_ptr<ImageDepth> m_DepthStencil;
298 std::unique_ptr<Framebuffers> m_Framebuffers;
299
300 std::map<std::string, const Descriptor*> m_Descriptors;
301
302 std::vector<VkClearValue> m_ClearValues;
303 std::vector<uint32_t> m_SubpassAttachmentCount;
304 std::optional<Attachment> m_DepthAttachment;
305 std::optional<Attachment> m_SwapchainAttachment;
306 std::vector<bool> m_SubpassMultisampled;
307
308 RenderArea m_RenderArea;
309 bool m_OutOfDate = false;
310 };
311} // namespace PixelBullet
Class that represents an attachment in a renderpass.
Definition RenderStage.hpp:19
Attachment(uint32_t binding, std::string name, Type type, bool multisampled=false, VkFormat format=VK_FORMAT_R8G8B8A8_UNORM, const Color &clearColour=Color::Black)
Definition RenderStage.hpp:37
A polished Color class storing RGBA values in a glm::vec4.
Definition Color.hpp:23
Definition Descriptor.hpp:75
Module that manages the Vulkan m_Instance, Surface, Window and the renderpass structure.
Definition Graphics.hpp:32
A representation of a Vulkan image, sampler, and view.
Definition Image.hpp:18
Definition RenderStage.hpp:106
float GetAspectRatio() const
Definition RenderStage.hpp:146
Definition RenderStage.hpp:205
const RenderArea & GetRenderArea() const
Definition RenderStage.hpp:243
bool IsOutOfDate() const
Definition RenderStage.hpp:252
Definition Renderpass.hpp:14
Definition RenderStage.hpp:83
Definition Swapchain.hpp:14
Definition RenderStage.hpp:162