KarmaEngine
Game Engine for practical learning and research purposes
Loading...
Searching...
No Matches
VulkanSwapChain.h
Go to the documentation of this file.
1
10
11#pragma once
12
14#include <vector>
15
16struct GLFWwindow;
17
18namespace Karma
19{
27 {
31 VkSwapchainKHR SwapChain;
32
36 VkSurfaceKHR Surface;
37 };
38
48 class FVulkanSwapChain
49 {
50 public:
59 static FVulkanSwapChain* Create(FVulkanDevice* InDevice);
60
69 void Destroy(FVulkanSwapChainRecreateInfo* RecreateInfo);
70
72 inline VkSwapchainKHR GetSwapChainHandle() const { return m_SwapChain; }
73
74 inline VkExtent2D GetSwapChainExtent() const { return m_SwapChainExtent; }
75 inline uint32_t GetMaxFramesInFlight() const { return MAX_FRAMES_IN_FLIGHT; }
76 inline const std::vector<VkImage>& GetSwapChainImages() const { return m_SwapChainImages; }
77 inline const std::vector<VkImageView>& GetSwapChainImageViews() const { return m_SwapChainImageViews; }
78 inline VkFormat GetSwapChainImageFormat() const { return m_SwapChainImageFormat; }
79
80 private:
81
88 FVulkanSwapChain(FVulkanDevice* InDevice);
89
106 static VkSurfaceFormatKHR ChooseSwapSurfaceFormat(const std::vector<VkSurfaceFormatKHR>& availableFormats);
107
117 VkPresentModeKHR ChooseSwapPresentMode(const std::vector<VkPresentModeKHR>& availablePresentModes);
118
126 VkExtent2D ChooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities);
127
128 protected:
129
130 const VkInstance m_Instance;
131 FVulkanDevice* m_Device;
132
133 VkSurfaceKHR m_Surface = VK_NULL_HANDLE;
134 VkSwapchainKHR m_SwapChain = VK_NULL_HANDLE;
135
136 std::vector<VkImage> m_SwapChainImages;
137 std::vector<VkImageView> m_SwapChainImageViews;
138
139 VkFormat m_SwapChainImageFormat;
140 VkExtent2D m_SwapChainExtent;
141
142 VkSurfaceFormatKHR m_SurfaceFormat;
143 VkPresentModeKHR m_PresentMode;
144
145 GLFWwindow* m_WindowHandle;
146
147 uint32_t m_InternalWidth = 0;
148 uint32_t m_InternalHeight = 0;
149
150 bool bInternalFullScreen = false;
151
152 uint32_t m_CurrentImageIndex;
153 uint32_t m_SemaphoreIndex;
154
155 // Number of images (to work upon (CPU side) whilst an image is being rendered (GPU side processing)) + 1
156 // Clearly, m_SwapChainImages.size() shouldn't exceed MAX_FRAMES_IN_FLIGHT
157 const uint32_t MAX_FRAMES_IN_FLIGHT = 4;
158 };
159}
Declaration of the FVulkanDevice class for managing Vulkan device resources.
Manages Vulkan device resources and operations.
Definition VulkanDevice.h:33
static FVulkanSwapChain * Create(FVulkanDevice *InDevice)
Creates a Vulkan swapchain based on the provided device.
Definition VulkanSwapChain.cpp:8
void Destroy(FVulkanSwapChainRecreateInfo *RecreateInfo)
Destroys the swapchain appropriately.
Definition VulkanSwapChain.cpp:100
Information required to recreate a Vulkan swapchain.
Definition VulkanSwapChain.h:27