vengine  0.1.0
3D graphics engine made with Vulkan
Loading...
Searching...
No Matches
SwapChain.hpp
Go to the documentation of this file.
1///
2/// @file SwapChain.hpp
3/// @brief This file contains the Shader class
4/// @namespace ven
5///
6
7#pragma once
8
9#include <vulkan/vulkan.h>
10#include <memory>
11
12#include "VEngine/Device.hpp"
13
14namespace ven {
15
16 class SwapChain {
17
18 public:
19
20 static constexpr int MAX_FRAMES_IN_FLIGHT = 2;
21
22 SwapChain(Device &deviceRef, const VkExtent2D windowExtentRef) : device{deviceRef}, windowExtent{windowExtentRef} { init(); }
23 SwapChain(Device &deviceRef, const VkExtent2D windowExtentRef, std::shared_ptr<SwapChain> previous) : device{deviceRef}, windowExtent{windowExtentRef}, oldSwapChain{std::move(previous)} { init(); oldSwapChain = nullptr; }
24 ~SwapChain();
25
26 SwapChain(const SwapChain &) = delete;
27 SwapChain& operator=(const SwapChain &) = delete;
28
29 [[nodiscard]] VkFramebuffer getFrameBuffer(const unsigned long index) const { return swapChainFramebuffers[index]; }
30 [[nodiscard]] VkRenderPass getRenderPass() const { return renderPass; }
31 [[nodiscard]] VkImageView getImageView(const int index) const { return swapChainImageViews[static_cast<unsigned long>(index)]; }
32 [[nodiscard]] size_t imageCount() const { return swapChainImages.size(); }
33 [[nodiscard]] VkFormat getSwapChainImageFormat() const { return swapChainImageFormat; }
34 [[nodiscard]] VkExtent2D getSwapChainExtent() const { return m_swapChainExtent; }
35 [[nodiscard]] uint32_t width() const { return m_swapChainExtent.width; }
36 [[nodiscard]] uint32_t height() const { return m_swapChainExtent.height; }
37
38 [[nodiscard]] float extentAspectRatio() const { return static_cast<float>(m_swapChainExtent.width) / static_cast<float>(m_swapChainExtent.height); }
39 VkFormat findDepthFormat() const;
40
41 VkResult acquireNextImage(uint32_t *imageIndex) const;
42 VkResult submitCommandBuffers(const VkCommandBuffer *buffers, const uint32_t *imageIndex);
43
44 [[nodiscard]] bool compareSwapFormats(const SwapChain &swapChainp) const {
46 }
47
48 private:
49
50 void init();
51 void createSwapChain();
52 void createImageViews();
54 void createRenderPass();
55 void createFramebuffers();
56 void createSyncObjects();
57
58 static VkSurfaceFormatKHR chooseSwapSurfaceFormat(const std::vector<VkSurfaceFormatKHR> &availableFormats);
59 static VkPresentModeKHR chooseSwapPresentMode(const std::vector<VkPresentModeKHR> &availablePresentModes);
60 VkExtent2D chooseSwapExtent(const VkSurfaceCapabilitiesKHR &capabilities) const;
61
64 VkExtent2D m_swapChainExtent{};
65
66 std::vector<VkFramebuffer> swapChainFramebuffers;
67 VkRenderPass renderPass{};
68
69 std::vector<VkImage> depthImages;
70 std::vector<VkDeviceMemory> depthImageMemorys;
71 std::vector<VkImageView> depthImageViews;
72 std::vector<VkImage> swapChainImages;
73 std::vector<VkImageView> swapChainImageViews;
74
76 VkExtent2D windowExtent;
77
78 VkSwapchainKHR swapChain{};
79 std::shared_ptr<SwapChain> oldSwapChain;
80
81 std::vector<VkSemaphore> imageAvailableSemaphores;
82 std::vector<VkSemaphore> renderFinishedSemaphores;
83 std::vector<VkFence> inFlightFences;
84 std::vector<VkFence> imagesInFlight;
85 size_t currentFrame = 0;
86
87 }; // class SwapChain
88
89} // namespace ven
This file contains the Device class.
std::vector< VkImage > swapChainImages
Definition SwapChain.hpp:72
SwapChain & operator=(const SwapChain &)=delete
SwapChain(const SwapChain &)=delete
size_t imageCount() const
Definition SwapChain.hpp:32
Device & device
Definition SwapChain.hpp:75
VkFramebuffer getFrameBuffer(const unsigned long index) const
Definition SwapChain.hpp:29
std::vector< VkImageView > depthImageViews
Definition SwapChain.hpp:71
VkExtent2D chooseSwapExtent(const VkSurfaceCapabilitiesKHR &capabilities) const
VkRenderPass getRenderPass() const
Definition SwapChain.hpp:30
uint32_t height() const
Definition SwapChain.hpp:36
static VkPresentModeKHR chooseSwapPresentMode(const std::vector< VkPresentModeKHR > &availablePresentModes)
uint32_t width() const
Definition SwapChain.hpp:35
VkExtent2D getSwapChainExtent() const
Definition SwapChain.hpp:34
size_t currentFrame
Definition SwapChain.hpp:85
std::vector< VkImageView > swapChainImageViews
Definition SwapChain.hpp:73
std::vector< VkFramebuffer > swapChainFramebuffers
Definition SwapChain.hpp:66
VkFormat getSwapChainImageFormat() const
Definition SwapChain.hpp:33
float extentAspectRatio() const
Definition SwapChain.hpp:38
SwapChain(Device &deviceRef, const VkExtent2D windowExtentRef, std::shared_ptr< SwapChain > previous)
Definition SwapChain.hpp:23
VkResult acquireNextImage(uint32_t *imageIndex) const
Definition swapChain.cpp:49
VkImageView getImageView(const int index) const
Definition SwapChain.hpp:31
std::vector< VkFence > inFlightFences
Definition SwapChain.hpp:83
void createFramebuffers()
bool compareSwapFormats(const SwapChain &swapChainp) const
Definition SwapChain.hpp:44
void createSwapChain()
VkFormat swapChainDepthFormat
Definition SwapChain.hpp:63
void createDepthResources()
std::vector< VkSemaphore > renderFinishedSemaphores
Definition SwapChain.hpp:82
void createSyncObjects()
void createImageViews()
std::vector< VkFence > imagesInFlight
Definition SwapChain.hpp:84
VkFormat findDepthFormat() const
VkFormat swapChainImageFormat
Definition SwapChain.hpp:62
VkResult submitCommandBuffers(const VkCommandBuffer *buffers, const uint32_t *imageIndex)
Definition swapChain.cpp:56
static constexpr int MAX_FRAMES_IN_FLIGHT
Definition SwapChain.hpp:20
std::vector< VkDeviceMemory > depthImageMemorys
Definition SwapChain.hpp:70
VkExtent2D m_swapChainExtent
Definition SwapChain.hpp:64
VkExtent2D windowExtent
Definition SwapChain.hpp:76
SwapChain(Device &deviceRef, const VkExtent2D windowExtentRef)
Definition SwapChain.hpp:22
VkRenderPass renderPass
Definition SwapChain.hpp:67
std::shared_ptr< SwapChain > oldSwapChain
Definition SwapChain.hpp:79
void createRenderPass()
VkSwapchainKHR swapChain
Definition SwapChain.hpp:78
std::vector< VkImage > depthImages
Definition SwapChain.hpp:69
std::vector< VkSemaphore > imageAvailableSemaphores
Definition SwapChain.hpp:81
static VkSurfaceFormatKHR chooseSwapSurfaceFormat(const std::vector< VkSurfaceFormatKHR > &availableFormats)
STL namespace.