Finality Engine
Loading...
Searching...
No Matches
VKSwapChain.h
Go to the documentation of this file.
1
6#pragma once
7#include "VKCore.h"
8
9#include <Core/Core.h>
10#include <Core/SwapChain.h>
11
12namespace FINALITY
13{
15 class VKSwapChain : public SwapChain
16 {
17 public:
18 VKSwapChain(VkDevice device, VkPhysicalDevice physicalDevice, VkSurfaceKHR surface);
19 ~VKSwapChain() override = default;
20
21 void Initialize(const NativeWindowHandle& handle, const WindowSpec& spec) override;
22 void Recreate(const WindowSpec& spec) override;
23 void Shutdown() override;
24
25 uint32_t AcquireNextImage() override { return UINT32_MAX; }
26 void Present() override {}
27
28 uint32_t GetWidth() const override { return m_Extent.width; }
29 uint32_t GetHeight() const override { return m_Extent.height; }
30 uint32_t GetImageCount() const override { return static_cast<uint32_t>(m_Images.size()); }
31 uint32_t GetCurrentImageIndex() const override { return m_ImageIndex; }
32
33 VkSwapchainKHR GetVKHandle() const { return m_SwapChain; }
34 VkRenderPass GetVKRenderPass() const { return m_RenderPass; }
35 VkFramebuffer GetVKFramebuffer(uint32_t index) const { return m_FrameBuffers[index]; }
36 VkFormat GetVKFormat() const { return m_SurfaceFormat.format; }
37
38 VkImage GetVKImage(uint32_t index) const { return m_Images[index]; }
39 const VkImageView& GetImageView(int idx) const;
40 const VkImageView& GetDepthView() const;
41
42 private:
43 void CreateSwapChain(const WindowSpec& spec);
44 void CreateImageViews();
45 void CreateSimpleRenderPass();
46 void CreateFrameBuffers();
47 void Cleanup();
48
49 VkSurfaceFormatKHR ChooseSwapSurfaceFormat(const std::vector<VkSurfaceFormatKHR>& availableFormats);
50 VkPresentModeKHR ChooseSwapPresentMode(const std::vector<VkPresentModeKHR>& availablePresentModes);
51 VkExtent2D ChooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities, const WindowSpec& spec);
52 void CreateDepthResources(VkPhysicalDevice physicalDevice);
53
54 private:
55 VkDevice m_LogicalDevice = nullptr;
56 VkPhysicalDevice m_PhysicalDevice = nullptr;
57 VkSurfaceKHR m_Surface = nullptr;
58
59 VkSwapchainKHR m_SwapChain = nullptr;
60 VkExtent2D m_Extent{};
61 VkSurfaceFormatKHR m_SurfaceFormat{};
62 uint32_t m_ImageIndex = 0;
63
64 std::vector<VkImage> m_Images;
65 std::vector<VkImageView> m_ImageViews;
66
67 VkImage m_DepthImage = VK_NULL_HANDLE;
68 VkDeviceMemory m_DepthImageMemory = VK_NULL_HANDLE;
69 VkImageView m_DepthImageView = VK_NULL_HANDLE;
70
71 std::vector<VkFramebuffer> m_FrameBuffers;
72 VkRenderPass m_RenderPass = nullptr;
73 };
74}
SwapChain(const SwapChain &)=delete
uint32_t GetWidth() const override
Definition VKSwapChain.h:28
VKSwapChain(VkDevice device, VkPhysicalDevice physicalDevice, VkSurfaceKHR surface)
const VkImageView & GetImageView(int idx) const
void Recreate(const WindowSpec &spec) override
void Present() override
Definition VKSwapChain.h:26
uint32_t GetCurrentImageIndex() const override
Definition VKSwapChain.h:31
VkFormat GetVKFormat() const
Definition VKSwapChain.h:36
uint32_t GetImageCount() const override
Definition VKSwapChain.h:30
void Initialize(const NativeWindowHandle &handle, const WindowSpec &spec) override
uint32_t GetHeight() const override
Definition VKSwapChain.h:29
VkRenderPass GetVKRenderPass() const
Definition VKSwapChain.h:34
VkImage GetVKImage(uint32_t index) const
Definition VKSwapChain.h:38
VkSwapchainKHR GetVKHandle() const
Definition VKSwapChain.h:33
void Shutdown() override
VkFramebuffer GetVKFramebuffer(uint32_t index) const
Definition VKSwapChain.h:35
const VkImageView & GetDepthView() const
~VKSwapChain() override=default
uint32_t AcquireNextImage() override
Definition VKSwapChain.h:25