1#ifndef LIBSBX_GRAPHICS_RENDER_STAGE_HPP_
2#define LIBSBX_GRAPHICS_RENDER_STAGE_HPP_
9#include <vulkan/vulkan.hpp>
11#include <libsbx/devices/devices_module.hpp>
13#include <libsbx/math/color.hpp>
14#include <libsbx/math/vector2.hpp>
16#include <libsbx/graphics/images/depth_image.hpp>
17#include <libsbx/graphics/images/image2d.hpp>
19#include <libsbx/graphics/render_pass/swapchain.hpp>
21namespace sbx::graphics {
23enum class format : std::uint32_t {
24 undefined = VK_FORMAT_UNDEFINED,
25 r32_sfloat = VK_FORMAT_R32_SFLOAT,
26 r32_uint = VK_FORMAT_R32_UINT,
27 r64_uint = VK_FORMAT_R64_UINT,
28 r32g32_sfloat = VK_FORMAT_R32G32_SFLOAT,
29 r32g32_uint = VK_FORMAT_R32G32_UINT,
30 r8g8b8a8_unorm = VK_FORMAT_R8G8B8A8_UNORM,
31 b8g8r8a8_srgb = VK_FORMAT_B8G8R8A8_SRGB,
32 r32g32b32a32_sfloat = VK_FORMAT_R32G32B32A32_SFLOAT
35enum class address_mode : std::uint32_t {
36 repeat = VK_SAMPLER_ADDRESS_MODE_REPEAT,
37 clamp_to_edge = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
50 attachment(
const std::uint32_t binding,
const std::string& name, type type,
const math::color& clear_color = math::color::black(),
const format format = format::r8g8b8a8_unorm,
const address_mode address_mode = address_mode::repeat) noexcept
52 _name{std::move(name)},
54 _clear_color{clear_color},
56 _address_mode{address_mode} { }
58 auto binding()
const noexcept -> std::uint32_t {
62 auto name()
const noexcept ->
const std::string& {
66 auto image_type()
const noexcept -> type {
70 auto format()
const noexcept -> graphics::format {
74 auto address_mode()
const noexcept -> graphics::address_mode {
78 auto clear_color()
const noexcept ->
const math::color& {
84 std::uint32_t _binding;
87 bool _is_multi_sampled;
89 graphics::format _format;
90 graphics::address_mode _address_mode;
98 subpass_binding(std::uint32_t binding, std::vector<std::uint32_t> color_attachments, std::vector<std::uint32_t> input_attachments = {})
noexcept
100 _color_attachments{std::move(color_attachments)},
101 _input_attachments{std::move(input_attachments)} { }
103 auto binding()
const noexcept -> std::uint32_t {
107 auto color_attachments()
const noexcept ->
const std::vector<std::uint32_t>& {
108 return _color_attachments;
111 auto input_attachments()
const noexcept ->
const std::vector<std::uint32_t>& {
112 return _input_attachments;
117 std::uint32_t _binding;
118 std::vector<std::uint32_t> _color_attachments;
119 std::vector<std::uint32_t> _input_attachments;
142 throw std::runtime_error{
"Dynamic viewport not implemented"};
161 auto size()
const noexcept ->
const std::optional<math::vector2u>& {
169 auto is_fixed()
const noexcept ->
bool {
170 return _type == type::fixed;
173 auto is_window()
const noexcept ->
bool {
174 return _type == type::window;
177 auto is_dynamic()
const noexcept ->
bool {
178 return _type == type::dynamic;
202 std::optional<math::vector2u> _size;
213 _aspect_ratio{
static_cast<std::float_t
>(extent.x()) /
static_cast<std::float_t
>(extent.y())} { }
215 auto operator==(
const render_area& other)
const noexcept ->
bool {
216 return _extent == other._extent && _offset == other._offset;
235 auto aspect_ratio()
const noexcept -> std::float_t {
236 return _aspect_ratio;
239 auto set_aspect_ratio(std::float_t aspect_ratio)
noexcept ->
void {
240 _aspect_ratio = aspect_ratio;
247 std::float_t _aspect_ratio;
259 auto attachments()
const noexcept ->
const std::vector<graphics::attachment>&;
261 auto find_attachment(
const std::string& name)
const noexcept -> std::optional<graphics::attachment>;
263 auto find_attachment(std::uint32_t binding)
const noexcept -> std::optional<graphics::attachment>;
265 auto subpasses()
const noexcept ->
const std::vector<subpass_binding>&;
267 auto attachment_count(std::uint32_t subpass)
const -> std::uint32_t;
269 auto subpass_attachments(std::uint32_t subpass)
const ->
const std::vector<std::uint32_t>&;
271 auto clear_values()
const noexcept ->
const std::vector<VkClearValue>&;
273 auto has_depth_attachment()
const noexcept -> bool;
275 auto has_swapchain_attachment()
const noexcept -> bool;
281 auto render_pass()
const noexcept ->
const VkRenderPass&;
285 auto framebuffer(std::uint32_t index)
noexcept ->
const VkFramebuffer&;
289 auto descriptors()
const noexcept ->
const std::map<std::string, memory::observer_ptr<const graphics::descriptor>>&;
293 auto _create_render_pass(VkFormat depth_format, VkFormat surface_format) -> void;
299 auto _create_attachment_descriptions(VkFormat depth_format, VkFormat surface_format) -> std::vector<VkAttachmentDescription>;
301 auto _create_subpass_dependencies() -> std::vector<VkSubpassDependency>;
303 std::vector<graphics::attachment> _attachments;
304 std::vector<subpass_binding> _subpass_bindings;
308 VkRenderPass _render_pass;
310 std::map<std::string, memory::observer_ptr<const graphics::descriptor>> _descriptors;
312 std::unique_ptr<graphics::depth_image> _depth_image;
313 std::unordered_map<std::uint32_t, std::unique_ptr<graphics::image2d>> _color_images;
315 std::vector<VkFramebuffer> _framebuffers;
317 std::vector<VkClearValue> _clear_values;
318 std::vector<std::uint32_t> _subpass_attachment_counts;
319 std::vector<std::vector<std::uint32_t>> _subpass_attachments;
320 std::optional<graphics::attachment> _depth_attachment;
321 std::optional<graphics::attachment> _swapchain_attachment;
Definition: render_stage.hpp:40
Definition: descriptor.hpp:37
Definition: render_stage.hpp:206
Definition: render_stage.hpp:251
Definition: render_stage.hpp:94
Definition: swapchain.hpp:12
Definition: render_stage.hpp:123
A vector in two-dimensional space.
Definition: vector2.hpp:27
A non-owning pointer that can be used to observe the value of a pointer.
Definition: observer_ptr.hpp:27