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
50private:
51
52 auto _choose_present_mode() const -> VkPresentModeKHR;
53
54 auto _create_image_view(const VkImage& image, VkFormat format, VkImageAspectFlags aspect, VkImageView& image_view) -> void;
55
56 VkExtent2D _extent{};
57 VkPresentModeKHR _present_mode{};
58 VkFormat _format{};
59
60 std::uint32_t _active_image_index{};
61 std::uint32_t _image_count{};
62
63 VkSurfaceTransformFlagsKHR _pre_transform{};
64 VkCompositeAlphaFlagBitsKHR _composite_alpha{};
65
66 std::vector<VkImage> _images{};
67 std::vector<VkImageView> _image_views{};
68
69 VkSwapchainKHR _handle{};
70
71}; // class swapchain
72
73} // namespace sbx::graphics
74
75#endif // LIBSBX_GRAPHICS_SWAPCHAIN_SWAPCHAIN_HPP_
Definition: fence.hpp:10
Definition: image.hpp:18
Definition: swapchain.hpp:12