PixelBullet  0.0.1
A C++ game engine
Loading...
Searching...
No Matches
render_stage.h
1#pragma once
2
3#include "pixelbullet/core/color.h"
4
5#include <glm/glm.hpp>
6
7#include <cstdint>
8#include <optional>
9#include <string>
10#include <utility>
11#include <vector>
12
13namespace pixelbullet
14{
15class Attachment
16{
17public:
18 enum class Type
19 {
20 RenderTarget,
21 Depth,
22 Swapchain
23 };
24
25 Attachment(uint32_t binding, std::string name, Type type, bool multisampled = false, const Color& clear_colour = Color::black,
26 bool shader_readable = false, bool shadow_sampler = false)
27 : binding_(binding)
28 , name_(std::move(name))
29 , type_(type)
30 , multisampled_(multisampled)
31 , clear_color_(clear_colour)
32 , shader_readable_(shader_readable)
33 , shadow_sampler_(shadow_sampler)
34 {
35 }
36
37 uint32_t GetBinding() const
38 {
39 return binding_;
40 }
41 const std::string& GetName() const
42 {
43 return name_;
44 }
45 Type GetType() const
46 {
47 return type_;
48 }
49 bool IsMultisampled() const
50 {
51 return multisampled_;
52 }
53 const Color& GetClearColour() const
54 {
55 return clear_color_;
56 }
57 bool IsShaderReadable() const
58 {
59 return shader_readable_;
60 }
61 bool UsesShadowSampler() const
62 {
63 return shadow_sampler_;
64 }
65
66private:
67 uint32_t binding_;
68 std::string name_;
69 Type type_;
70 bool multisampled_;
71 Color clear_color_;
72 bool shader_readable_;
73 bool shadow_sampler_;
74};
75
76class SubpassType
77{
78public:
79 SubpassType(uint32_t binding, std::vector<uint32_t> attachment_bindings)
80 : binding_(binding)
81 , attachment_bindings_(std::move(attachment_bindings))
82 {
83 }
84
85 uint32_t GetBinding() const
86 {
87 return binding_;
88 }
89 const std::vector<uint32_t>& GetAttachmentBindings() const
90 {
91 return attachment_bindings_;
92 }
93
94private:
95 uint32_t binding_;
96 std::vector<uint32_t> attachment_bindings_;
97};
98
99class Viewport
100{
101public:
102 Viewport() = default;
103
104 explicit Viewport(const glm::uvec2& size)
105 : size_(size)
106 {
107 }
108
109 const glm::vec2& GetScale() const
110 {
111 return scale_;
112 }
113 void SetScale(const glm::vec2& scale)
114 {
115 scale_ = scale;
116 }
117
118 const std::optional<glm::uvec2>& GetSize() const
119 {
120 return size_;
121 }
122 void SetSize(const std::optional<glm::uvec2>& size)
123 {
124 size_ = size;
125 }
126
127 const glm::ivec2& GetOffset() const
128 {
129 return offset_;
130 }
131 void SetOffset(const glm::ivec2& offset)
132 {
133 offset_ = offset;
134 }
135
136private:
137 glm::vec2 scale_{ 1.0f, 1.0f };
138 std::optional<glm::uvec2> size_;
139 glm::ivec2 offset_{ 0, 0 };
140};
141
142class RenderStage
143{
144public:
145 explicit RenderStage(std::vector<Attachment> images = {}, std::vector<SubpassType> subpasses = {},
146 const Viewport& viewport = Viewport());
147 ~RenderStage();
148
149 std::optional<Attachment> GetAttachment(const std::string& name) const;
150 std::optional<Attachment> GetAttachment(uint32_t binding) const;
151
152 const std::vector<Attachment>& GetAttachments() const
153 {
154 return attachments_;
155 }
156 const std::vector<SubpassType>& GetSubpasses() const
157 {
158 return subpasses_;
159 }
160
161 Viewport& GetViewport()
162 {
163 return viewport_;
164 }
165 const Viewport& GetViewport() const
166 {
167 return viewport_;
168 }
169 void SetViewport(const Viewport& viewport)
170 {
171 viewport_ = viewport;
172 }
173
174private:
175 std::vector<Attachment> attachments_;
176 std::vector<SubpassType> subpasses_;
177 Viewport viewport_;
178};
179} // namespace pixelbullet
A polished Color class storing RGBA values in a glm::vec4.
Definition color.h:24
Definition render_stage.h:100