sandbox
Loading...
Searching...
No Matches
swapchain.hpp
1#ifndef LIBSBX_GRAPHICS_SWAPCHAIN_SWAPCHAIN_HPP_
2#define LIBSBX_GRAPHICS_SWAPCHAIN_SWAPCHAIN_HPP_
3
4#include <cinttypes>
5#include <memory>
6#include <vector>
7
8#include <vulkan/vulkan.hpp>
9
10namespace sbx::graphics {
11
12class swapchain {
13
14public:
15
16 static constexpr auto max_frames_in_flight = std::uint32_t{2};
17
18 swapchain(const std::unique_ptr<swapchain>& old_swapchain = nullptr);
19
20 ~swapchain();
21
22 auto handle() const noexcept -> const VkSwapchainKHR&;
23
24 operator const VkSwapchainKHR&() const noexcept;
25
26 auto extent() const noexcept -> const VkExtent2D&;
27
28 auto is_outdated(const VkExtent2D& extent) const noexcept -> bool {
29 return _extent.width != extent.width || _extent.height != extent.height;
30 }
31
32 auto active_image_index() const noexcept -> std::uint32_t;
33
34 auto image_count() const noexcept -> std::uint32_t;
35
36 auto pre_transform() const noexcept -> VkSurfaceTransformFlagsKHR;
37
38 auto composite_alpha() const noexcept -> VkCompositeAlphaFlagBitsKHR;
39
40 auto present_mode() const noexcept -> VkPresentModeKHR;
41
42 auto image(std::uint32_t index) const noexcept -> const VkImage&;
43
44 auto image_view(std::uint32_t index) const noexcept -> const VkImageView&;
45
46 auto acquire_next_image(const VkSemaphore& image_available_semaphore = nullptr, const VkFence& fence = nullptr) -> VkResult;
47
48 auto present(const VkSemaphore& wait_semaphore = nullptr) -> VkResult;
49
50 auto formt() const noexcept -> VkFormat {
51 return _format;
52 }
53
54private:
55
56 auto _choose_present_mode() const -> VkPresentModeKHR;
57
58 auto _create_image_view(const VkImage& image, VkFormat format, VkImageAspectFlags aspect, VkImageView& image_view) -> void;
59
60 VkExtent2D _extent{};
61 VkPresentModeKHR _present_mode{};
62 VkFormat _format{};
63
64 std::uint32_t _active_image_index{};
65 std::uint32_t _image_count{};
66
67 VkSurfaceTransformFlagsKHR _pre_transform{};
68 VkCompositeAlphaFlagBitsKHR _composite_alpha{};
69
70 std::vector<VkImage> _images{};
71 std::vector<VkImageView> _image_views{};
72
73 VkSwapchainKHR _handle{};
74
75}; // class swapchain
76
77} // namespace sbx::graphics
78
79#endif // LIBSBX_GRAPHICS_SWAPCHAIN_SWAPCHAIN_HPP_
Definition: image.hpp:20
Definition: swapchain.hpp:12