Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
Swapchain.h
Go to the documentation of this file.
1/**
2 * @file Swapchain.h
3 * @brief VkSwapchain + per-image views, render pass, framebuffers.
4 *
5 * Held separately from Context so a window resize can rebuild the swapchain
6 * without tearing down the whole device. Renderer calls Recreate() when it
7 * sees VK_ERROR_OUT_OF_DATE_KHR or VK_SUBOPTIMAL_KHR from the present path.
8 */
9
10#pragma once
11
12#include <vector>
13
14#include <vulkan/vulkan.h>
15
16struct GLFWwindow;
17
18namespace mnd::vk
19{
20class Context;
21
23{
24public:
25 Swapchain(Context &ctx, GLFWwindow *window);
26 ~Swapchain();
27
28 Swapchain(const Swapchain &) = delete;
29 Swapchain &operator=(const Swapchain &) = delete;
30
31 /// Tear down + rebuild against the window's current size. Blocks on
32 /// vkDeviceWaitIdle so call only between frames.
33 void Recreate();
34
35 [[nodiscard]] VkSwapchainKHR Get() const { return m_swapchain; }
36 [[nodiscard]] VkRenderPass GetRenderPass() const { return m_renderPass; }
37 [[nodiscard]] VkExtent2D GetExtent() const { return m_extent; }
38 [[nodiscard]] VkFormat GetFormat() const { return m_format; }
39 [[nodiscard]] const std::vector<VkFramebuffer> &GetFramebuffers() const { return m_framebuffers; }
40 [[nodiscard]] uint32_t ImageCount() const { return static_cast<uint32_t>(m_images.size()); }
41
42private:
43 void Build();
44 void Cleanup();
45
46 Context &m_ctx;
47 GLFWwindow *m_window = nullptr;
48 VkSwapchainKHR m_swapchain = VK_NULL_HANDLE;
49 VkRenderPass m_renderPass = VK_NULL_HANDLE;
50 VkFormat m_format = VK_FORMAT_UNDEFINED;
51 VkExtent2D m_extent = {0, 0};
52 std::vector<VkImage> m_images;
53 std::vector<VkImageView> m_imageViews;
54 std::vector<VkFramebuffer> m_framebuffers;
55};
56
57} // namespace mnd::vk
Owns the Vulkan instance, surface (tied to a GLFW window), physical + logical device,...
Definition Context.h:41
VkRenderPass GetRenderPass() const
Definition Swapchain.h:36
uint32_t ImageCount() const
Definition Swapchain.h:40
VkSwapchainKHR Get() const
Definition Swapchain.h:35
Swapchain(const Swapchain &)=delete
Swapchain & operator=(const Swapchain &)=delete
VkFormat GetFormat() const
Definition Swapchain.h:38
VkExtent2D GetExtent() const
Definition Swapchain.h:37
const std::vector< VkFramebuffer > & GetFramebuffers() const
Definition Swapchain.h:39