Chronos 0.0
A advanced 2D rendering and animation system
Loading...
Searching...
No Matches
swapchain.hpp
Go to the documentation of this file.
1/*
2Copyright (c) 2024 Rahul Satish Vadhyar
3
4Permission is hereby granted, free of charge, to any person obtaining a copy
5of this software and associated documentation files (the "Software"), to deal
6in the Software without restriction, including without limitation the rights
7to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8copies of the Software, and to permit persons to whom the Software is
9furnished to do so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall be included in all
12copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20SOFTWARE.
21*/
22
28#pragma once
29#include "device.hpp"
30namespace Chronos {
31namespace Engine {
32
37 VkSurfaceCapabilitiesKHR capabilities;
38 std::vector<VkSurfaceFormatKHR> formats;
39 std::vector<VkPresentModeKHR> presentModes;
40 };
41
59 VkExtent2D chooseSwapExtent(
60 const VkSurfaceCapabilitiesKHR& capabilities, GLFWwindow* window);
61
72 VkSurfaceFormatKHR chooseSwapSurfaceFormat(
73 const std::vector<VkSurfaceFormatKHR>& availableFormats);
74
89 VkPhysicalDevice device, VkSurfaceKHR surface);
90
99 class SwapChain {
100 public:
114 void init(Chronos::Engine::Device* device, VkSurfaceKHR surface,
115 GLFWwindow* window);
116
124 void recreate();
125
130 void cleanup();
131
138 void changeMsaa();
139
143 VkExtent2D swapChainExtent;
144
148 VkSwapchainKHR swapChain;
149
153 VkSurfaceKHR surface;
154
158 std::vector<VkImageView> swapChainImageViews;
159
163 VkImageView colorImageView;
164
169
173 VkPresentModeKHR preferredPresentMode = VK_PRESENT_MODE_MAILBOX_KHR;
174
175 bool changePresentMode = false;
176
177 private:
182
186 GLFWwindow* window;
187
191 VkImage colorImage;
192
196 VkDeviceMemory colorImageMemory;
197
201 std::vector<VkImage> swapChainImages;
202
207 void create();
208
212 void createImageViews();
213
218
254 VkPresentModeKHR chooseSwapPresentMode(
255 const std::vector<VkPresentModeKHR>& availablePresentModes);
256 };
257};
258};
This initializes, manages and destroys the logical and physical devices(GPU).
Definition device.hpp:47
void createImageViews()
Creates the image views of the swapchain images.
std::vector< VkImageView > swapChainImageViews
Image views of the swapchain textures(images, aka window)
VkExtent2D swapChainExtent
Dimenisons of the current swapchain.
Chronos::Engine::Device * device
Device to which swapchain needs to be created.
VkSurfaceKHR surface
Surface to which we need to present the swapchain images.
VkPresentModeKHR preferredPresentMode
Preferred present mode for the swapchain.
void create()
Creates the swapchain image resources and chooses the optimal settings for given hardware.
VkImageView colorImageView
image view of the color attachement
VkFormat swapChainImageFormat
Chosen swapchain image format.
VkDeviceMemory colorImageMemory
Memory to store the color image.
VkImage colorImage
The color image.
void cleanup()
Cleans up the assets that are rendered invalid during MSAA changes or swapchain.
std::vector< VkImage > swapChainImages
Swapchaim images to render and present to.
GLFWwindow * window
The window to present the surface to.
VkSwapchainKHR swapChain
Vulkan swapchain object.
void recreate()
When the swapchain is rendered invalid, recreate it.
void init(Chronos::Engine::Device *device, VkSurfaceKHR surface, GLFWwindow *window)
Initilize the swapchain.
Definition swapchain.cpp:94
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.
void changeMsaa()
Changes the MSAA count of the swapchain images.
Contains the Device class.
VkExtent2D chooseSwapExtent(const VkSurfaceCapabilitiesKHR &capabilities, GLFWwindow *window)
Gets the maximum extent of the swapchain images(framebuffer size).
Definition swapchain.cpp:41
VkSurfaceFormatKHR chooseSwapSurfaceFormat(const std::vector< VkSurfaceFormatKHR > &availableFormats)
Chooses the best present mode among the supported modes.
Definition swapchain.cpp:26
SwapChainSupportDetails querySwapChainSupport(VkPhysicalDevice device, VkSurfaceKHR surface)
For a given swapchain mode, it gets the capabilites, formats and present modes.
Definition swapchain.cpp:65
Contains the fields to the support details of a physical device.
Definition swapchain.hpp:36
VkSurfaceCapabilitiesKHR capabilities
Definition swapchain.hpp:37
std::vector< VkSurfaceFormatKHR > formats
Definition swapchain.hpp:38
std::vector< VkPresentModeKHR > presentModes
Definition swapchain.hpp:39