1#ifndef LIBSBX_GRAPHICS_RENDER_STAGE_HPP_
2#define LIBSBX_GRAPHICS_RENDER_STAGE_HPP_
9#include <vulkan/vulkan.hpp>
13#include <libsbx/devices/devices_module.hpp>
15#include <libsbx/math/color.hpp>
16#include <libsbx/math/vector2.hpp>
18#include <libsbx/graphics/images/depth_image.hpp>
19#include <libsbx/graphics/images/image2d.hpp>
21#include <libsbx/graphics/render_pass/swapchain.hpp>
23namespace sbx::graphics {
25enum class format : std::uint32_t {
26 undefined = VK_FORMAT_UNDEFINED,
27 r32_sfloat = VK_FORMAT_R32_SFLOAT,
28 r32g32_sfloat = VK_FORMAT_R32G32_SFLOAT,
29 r8g8b8a8_unorm = VK_FORMAT_R8G8B8A8_UNORM,
30 r32g32b32a32_sfloat = VK_FORMAT_R32G32B32A32_SFLOAT
33enum class address_mode : std::uint32_t {
34 repeat = VK_SAMPLER_ADDRESS_MODE_REPEAT,
35 clamp_to_edge = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
48 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
50 _name{std::move(name)},
52 _clear_color{clear_color},
54 _address_mode{address_mode} { }
56 auto binding()
const noexcept -> std::uint32_t {
60 auto name()
const noexcept ->
const std::string& {
64 auto image_type()
const noexcept -> type {
68 auto format()
const noexcept -> graphics::format {
72 auto address_mode()
const noexcept -> graphics::address_mode {
76 auto clear_color()
const noexcept ->
const math::color& {
82 std::uint32_t _binding;
85 bool _is_multi_sampled;
87 graphics::format _format;
88 graphics::address_mode _address_mode;
96 subpass_binding(std::uint32_t binding, std::vector<std::uint32_t> color_attachments, std::vector<std::uint32_t> input_attachments = {})
noexcept
98 _color_attachments{std::move(color_attachments)},
99 _input_attachments{std::move(input_attachments)} { }
101 auto binding()
const noexcept -> std::uint32_t {
105 auto color_attachments()
const noexcept ->
const std::vector<std::uint32_t>& {
106 return _color_attachments;
109 auto input_attachments()
const noexcept ->
const std::vector<std::uint32_t>& {
110 return _input_attachments;
113 auto input_attachment_bindings()
const noexcept ->
const std::vector<std::uint32_t>& {
114 return _input_attachment_bindings;
119 std::uint32_t _binding;
120 std::vector<std::uint32_t> _color_attachments;
121 std::vector<std::uint32_t> _input_attachments;
130 : _scale{1.0f, 1.0f},
132 _size{std::nullopt} { }
135 : _scale{1.0f, 1.0f},
155 auto size()
const noexcept ->
const std::optional<math::vector2u>& {
167 std::optional<math::vector2u> _size;
178 _aspect_ratio{
static_cast<std::float_t
>(extent.x()) /
static_cast<std::float_t
>(extent.y())} { }
180 auto operator==(
const render_area& other)
const noexcept ->
bool {
181 return _extent == other._extent && _offset == other._offset;
200 auto aspect_ratio()
const noexcept -> std::float_t {
201 return _aspect_ratio;
204 auto set_aspect_ratio(std::float_t aspect_ratio)
noexcept ->
void {
205 _aspect_ratio = aspect_ratio;
212 std::float_t _aspect_ratio;
224 auto attachments()
const noexcept ->
const std::vector<graphics::attachment>&;
226 auto find_attachment(
const std::string& name)
const noexcept -> std::optional<graphics::attachment>;
228 auto find_attachment(std::uint32_t binding)
const noexcept -> std::optional<graphics::attachment>;
230 auto subpasses()
const noexcept ->
const std::vector<subpass_binding>&;
232 auto attachment_count(std::uint32_t subpass)
const -> std::uint32_t;
234 auto clear_values()
const noexcept ->
const std::vector<VkClearValue>&;
236 auto has_depth_attachment()
const noexcept -> bool;
238 auto has_swapchain_attachment()
const noexcept -> bool;
244 auto render_pass()
const noexcept ->
const VkRenderPass&;
248 auto framebuffer(std::uint32_t index)
noexcept ->
const VkFramebuffer&;
252 auto descriptors()
const noexcept ->
const std::map<std::string, memory::observer_ptr<const graphics::descriptor>>&;
256 auto _create_render_pass(VkFormat depth_format, VkFormat surface_format) -> void;
262 auto _create_attachment_descriptions(VkFormat depth_format, VkFormat surface_format) -> std::vector<VkAttachmentDescription>;
264 auto _create_subpass_dependencies() -> std::vector<VkSubpassDependency>;
266 std::vector<graphics::attachment> _attachments;
267 std::vector<subpass_binding> _subpass_bindings;
271 VkRenderPass _render_pass;
273 std::map<std::string, memory::observer_ptr<const graphics::descriptor>> _descriptors;
275 std::unique_ptr<graphics::depth_image> _depth_image;
276 std::unordered_map<std::uint32_t, std::unique_ptr<graphics::image2d>> _color_images;
278 std::vector<VkFramebuffer> _framebuffers;
280 std::vector<VkClearValue> _clear_values;
281 std::vector<std::uint32_t> _subpass_attachment_counts;
282 std::optional<graphics::attachment> _depth_attachment;
283 std::optional<graphics::attachment> _swapchain_attachment;
Definition: render_stage.hpp:38
Definition: descriptor.hpp:33
Definition: render_stage.hpp:171
Definition: render_stage.hpp:216
Definition: render_stage.hpp:92
Definition: swapchain.hpp:12
Definition: render_stage.hpp:125
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