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