Chronos 0.0
A advanced 2D rendering and animation system
|
#include <swapchain.hpp>
Public Member Functions | |
void | init (Chronos::Engine::Device *device, VkSurfaceKHR surface, GLFWwindow *window) |
Initilize the swapchain. | |
void | recreate () |
When the swapchain is rendered invalid, recreate it. | |
void | cleanup () |
Cleans up the assets that are rendered invalid during MSAA changes or swapchain. | |
void | changeMsaa () |
Changes the MSAA count of the swapchain images. | |
Public Attributes | |
VkExtent2D | swapChainExtent |
Dimenisons of the current swapchain. | |
VkSwapchainKHR | swapChain |
Vulkan swapchain object. | |
VkSurfaceKHR | surface |
Surface to which we need to present the swapchain images. | |
std::vector< VkImageView > | swapChainImageViews |
Image views of the swapchain textures(images, aka window) | |
VkImageView | colorImageView |
image view of the color attachement | |
VkFormat | swapChainImageFormat |
Chosen swapchain image format. | |
VkPresentModeKHR | preferredPresentMode = VK_PRESENT_MODE_MAILBOX_KHR |
Preferred present mode for the swapchain. | |
bool | changePresentMode = false |
Private Member Functions | |
void | create () |
Creates the swapchain image resources and chooses the optimal settings for given hardware. | |
void | createImageViews () |
Creates the image views of the swapchain images. | |
void | createColorResources () |
Creates the color images along with the associated objects. | |
VkPresentModeKHR | chooseSwapPresentMode (const std::vector< VkPresentModeKHR > &availablePresentModes) |
From the available present mode, this chooses the the best present mode. | |
Private Attributes | |
Chronos::Engine::Device * | device |
Device to which swapchain needs to be created. | |
GLFWwindow * | window |
The window to present the surface to. | |
VkImage | colorImage |
The color image. | |
VkDeviceMemory | colorImageMemory |
Memory to store the color image. | |
std::vector< VkImage > | swapChainImages |
Swapchaim images to render and present to. | |
/brief Responsible for initializing, managing, recreating and presenting the swapchain images.
In Vulkan, we render to images(texture). These images are then present to the GLFW window. Since there will be multiple images in flight, along with multiple other assets for this, we need to manage these assets.
Definition at line 99 of file swapchain.hpp.
void Chronos::Engine::SwapChain::changeMsaa | ( | ) |
Changes the MSAA count of the swapchain images.
When the user decides to change the MSAA, we need to recreate the swapchain. This does it.
Definition at line 223 of file swapchain.cpp.
|
private |
From the available present mode, this chooses the the best present mode.
If available VK_PRESENT_MODE_MAILBOX_KHR
will be chosen.
Some of the presentation modes available are:
VK_PRESENT_MODE_IMMEDIATE_KHR
: Images submitted by your application are transferred to the screen right away, which may result in tearing.VK_PRESENT_MODE_FIFO_KHR
: The swap chain is a queue where the display takes an image from the front of the queue when the display is refreshed and the program inserts rendered images at the back of the queue.If the queue is full then the program has to wait. This is most similar to vertical sync as found in modern games.The moment that the display is refreshed is known as "vertical blank".VK_PRESENT_MODE_FIFO_RELAXED_KHR
: This mode only differs from the previous one if the application is late and the queue was empty at the last vertical blank. Instead of waiting for the next vertical blank, the image is transferred right away when it finally arrives.This may result in visible tearing.VK_PRESENT_MODE_MAILBOX_KHR
: This is another variation of the second mode.Instead of blocking the application when the queue is full, the images that are already queued are simply replaced with the newer ones.This mode can be used to render frames as fast as possible while still avoiding tearing, resulting in fewer latency issues than standard vertical sync.This is commonly known as "triple buffering", although the existence of three buffers alone does not necessarily mean that the framerateavailablePresentModes | The available present modes to choose from. |
Definition at line 233 of file swapchain.cpp.
void Chronos::Engine::SwapChain::cleanup | ( | ) |
Cleans up the assets that are rendered invalid during MSAA changes or swapchain.
Definition at line 193 of file swapchain.cpp.
|
private |
Creates the swapchain image resources and chooses the optimal settings for given hardware.
Definition at line 105 of file swapchain.cpp.
References Chronos::Engine::SwapChainSupportDetails::capabilities, Chronos::Engine::chooseSwapExtent(), Chronos::Engine::chooseSwapSurfaceFormat(), Chronos::Engine::findQueueFamilies(), Chronos::Engine::SwapChainSupportDetails::formats, Chronos::Engine::QueueFamilyIndices::graphicsFamily, Chronos::Engine::QueueFamilyIndices::presentFamily, Chronos::Engine::SwapChainSupportDetails::presentModes, and Chronos::Engine::querySwapChainSupport().
|
private |
Creates the color images along with the associated objects.
Definition at line 179 of file swapchain.cpp.
References Chronos::Engine::createImage(), and Chronos::Engine::createImageView().
|
private |
Creates the image views of the swapchain images.
Definition at line 170 of file swapchain.cpp.
References Chronos::Engine::createImageView().
void Chronos::Engine::SwapChain::init | ( | Chronos::Engine::Device * | device, |
VkSurfaceKHR | surface, | ||
GLFWwindow * | window | ||
) |
Initilize the swapchain.
The swapchain is an insanely complicated process to setup. We need to create multiple textures, along with their memory and views. We also need to select the format to render to. Along with that we need the color rendering texture attachment, which has its own texture, memory and view.
device | The device to create the swapchain on |
surface | The surface(VK version of window texture) to render to |
window | Thw window to display the image on. |
Definition at line 94 of file swapchain.cpp.
References create(), createColorResources(), createImageViews(), device, surface, and window.
void Chronos::Engine::SwapChain::recreate | ( | ) |
When the swapchain is rendered invalid, recreate it.
Due to various user activities such as window resizing and minimization, the swapchain can become invalid. At that point, we need to recreate the assets based on the new dimensions.
Definition at line 206 of file swapchain.cpp.
bool Chronos::Engine::SwapChain::changePresentMode = false |
Definition at line 175 of file swapchain.hpp.
|
private |
The color image.
Definition at line 191 of file swapchain.hpp.
|
private |
Memory to store the color image.
Definition at line 196 of file swapchain.hpp.
VkImageView Chronos::Engine::SwapChain::colorImageView |
image view of the color attachement
Definition at line 163 of file swapchain.hpp.
|
private |
Device to which swapchain needs to be created.
Definition at line 181 of file swapchain.hpp.
VkPresentModeKHR Chronos::Engine::SwapChain::preferredPresentMode = VK_PRESENT_MODE_MAILBOX_KHR |
Preferred present mode for the swapchain.
Definition at line 173 of file swapchain.hpp.
VkSurfaceKHR Chronos::Engine::SwapChain::surface |
Surface to which we need to present the swapchain images.
Definition at line 153 of file swapchain.hpp.
VkSwapchainKHR Chronos::Engine::SwapChain::swapChain |
Vulkan swapchain object.
Definition at line 148 of file swapchain.hpp.
VkExtent2D Chronos::Engine::SwapChain::swapChainExtent |
Dimenisons of the current swapchain.
Definition at line 143 of file swapchain.hpp.
VkFormat Chronos::Engine::SwapChain::swapChainImageFormat |
Chosen swapchain image format.
Definition at line 168 of file swapchain.hpp.
|
private |
Swapchaim images to render and present to.
Definition at line 201 of file swapchain.hpp.
std::vector<VkImageView> Chronos::Engine::SwapChain::swapChainImageViews |
Image views of the swapchain textures(images, aka window)
Definition at line 158 of file swapchain.hpp.
|
private |
The window to present the surface to.
Definition at line 186 of file swapchain.hpp.