Crimson Engine 1.0.0
A high-performance C++20 game engine prototype showcasing a custom ECS, Vulkan renderer, and ImGui editor.
Loading...
Searching...
No Matches
VulkanSwapchain Class Reference

Handles creation, extent negotiation, rendering passes, and framebuffer generation for Vulkan Swapchains. More...

#include <VulkanSwapChain.hpp>

Public Member Functions

 VulkanSwapchain ()=default
 Construct a new Vulkan Swapchain object.
 ~VulkanSwapchain ()
 Destroy the Vulkan Swapchain object and release swapchain structures.
void initialize (VkDevice device, VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, uint32_t graphicsQueueFamily)
 Sets up parameters, selects formats, builds KHR swapchain, views, render pass and framebuffers.
void cleanup ()
 Safely destroys framebuffers, render pass, image views, and swapchain handles.
VkFormat getImageFormat () const
 Gets selected swapchain format.
VkExtent2D getExtent () const
 Gets resolution extent details.
const std::vector< VkFramebuffer > & getFramebuffers () const
 Gets active framebuffers list.
VkRenderPass getRenderPass () const
 Gets default render pass for swapchain buffers.
VkSwapchainKHR getSwapchain () const
 Gets raw KHR swapchain.

Private Member Functions

void createSwapchain (uint32_t graphicsQueueFamily)
 Establishes the KHR swapchain handle.
void createImageViews ()
 Creates image views for each swapchain image.
void createRenderPass ()
 Configures render pass layouts.
void createFramebuffers ()
 Creates framebuffers linking image views to the render pass.
void createDepthResources ()
 Creates depth buffers and views.
VkFormat findDepthFormat ()
 Helper to query and select best depth format.
VkFormat findSupportedFormat (const std::vector< VkFormat > &candidates, VkImageTiling tiling, VkFormatFeatureFlags features)
 Helper to find supported depth formats.
uint32_t findMemoryType (uint32_t typeFilter, VkMemoryPropertyFlags properties)
 Helper to query suitable GPU memory index.
VkSurfaceFormatKHR chooseSurfaceFormat (const std::vector< VkSurfaceFormatKHR > &formats)
 Selects optimal color format and color space.
VkPresentModeKHR choosePresentMode (const std::vector< VkPresentModeKHR > &modes)
 Selects optimal presentation mode (e.g. Mailbox or FIFO).
VkExtent2D chooseExtent (const VkSurfaceCapabilitiesKHR &capabilities)
 Resolves swapchain resolution boundaries against hardware limits.

Private Attributes

VkDevice device = VK_NULL_HANDLE
 Reference to logical device.
VkPhysicalDevice physicalDevice = VK_NULL_HANDLE
 Reference to physical device.
VkSurfaceKHR surface = VK_NULL_HANDLE
 Reference to presentation surface.
VkSwapchainKHR swapchain = VK_NULL_HANDLE
 Raw swapchain handle.
std::vector< VkImage > images
 Retrieved swapchain images.
std::vector< VkImageView > imageViews
 image views wrapping swapchain images.
std::vector< VkFramebuffer > framebuffers
 framebuffers wrapping image views.
VkFormat imageFormat {}
 image format of swapchain buffers.
VkExtent2D extent {}
 image extent (resolution) of swapchain buffers.
VkRenderPass renderPass = VK_NULL_HANDLE
 Render pass used for frame clearing and drawing.
VkImage depthImage = VK_NULL_HANDLE
 GPU depth image allocation handle.
VkDeviceMemory depthImageMemory = VK_NULL_HANDLE
 GPU depth memory handle.
VkImageView depthImageView = VK_NULL_HANDLE
 Depth image view wrapper.
VkFormat depthFormat = VK_FORMAT_D32_SFLOAT
 Selected depth format.

Detailed Description

Handles creation, extent negotiation, rendering passes, and framebuffer generation for Vulkan Swapchains.

Constructor & Destructor Documentation

◆ VulkanSwapchain()

VulkanSwapchain::VulkanSwapchain ( )
default

Construct a new Vulkan Swapchain object.

◆ ~VulkanSwapchain()

VulkanSwapchain::~VulkanSwapchain ( )

Destroy the Vulkan Swapchain object and release swapchain structures.

Destroy the Vulkan Swapchain:: Vulkan Swapchain object.

Member Function Documentation

◆ chooseExtent()

VkExtent2D VulkanSwapchain::chooseExtent ( const VkSurfaceCapabilitiesKHR & capabilities)
private

Resolves swapchain resolution boundaries against hardware limits.

Adjusts resolution bounds matching capabilities.

Parameters
capabilitiesSurface capabilities.
Returns
Optimal swapchain extent.
Parameters
capabilitiesSurface capabilities.
Returns
Frame buffer extent.

◆ choosePresentMode()

VkPresentModeKHR VulkanSwapchain::choosePresentMode ( const std::vector< VkPresentModeKHR > & modes)
private

Selects optimal presentation mode (e.g. Mailbox or FIFO).

Chooses presentation mode (prioritizes Mailbox, defaults to FIFO).

Parameters
modesList of supported modes.
Returns
Ideal present mode.
Parameters
modesAvailable present modes.
Returns
Present mode.

◆ chooseSurfaceFormat()

VkSurfaceFormatKHR VulkanSwapchain::chooseSurfaceFormat ( const std::vector< VkSurfaceFormatKHR > & formats)
private

Selects optimal color format and color space.

Parameters
formatsList of supported formats.
Returns
Ideal surface format.
Parameters
formatsList of supported formats.
Returns
Surface format.

◆ cleanup()

void VulkanSwapchain::cleanup ( )

Safely destroys framebuffers, render pass, image views, and swapchain handles.

Destroys framebuffers, render pass, image views, and swapchain handles.

◆ createDepthResources()

void VulkanSwapchain::createDepthResources ( )
private

Creates depth buffers and views.

◆ createFramebuffers()

void VulkanSwapchain::createFramebuffers ( )
private

Creates framebuffers linking image views to the render pass.

Instantiates framebuffers binding image views to the render pass.

◆ createImageViews()

void VulkanSwapchain::createImageViews ( )
private

Creates image views for each swapchain image.

Wraps swapchain images into VkImageView descriptors.

◆ createRenderPass()

void VulkanSwapchain::createRenderPass ( )
private

Configures render pass layouts.

Configures layouts and subpass parameters, creating the default render pass.

◆ createSwapchain()

void VulkanSwapchain::createSwapchain ( uint32_t graphicsQueueFamily)
private

Establishes the KHR swapchain handle.

Checks capabilities and creates swapchain object.

Parameters
graphicsQueueFamilyQueue family index.
graphicsQueueFamilyGraphics queue family index.

◆ findDepthFormat()

VkFormat VulkanSwapchain::findDepthFormat ( )
private

Helper to query and select best depth format.

◆ findMemoryType()

uint32_t VulkanSwapchain::findMemoryType ( uint32_t typeFilter,
VkMemoryPropertyFlags properties )
private

Helper to query suitable GPU memory index.

◆ findSupportedFormat()

VkFormat VulkanSwapchain::findSupportedFormat ( const std::vector< VkFormat > & candidates,
VkImageTiling tiling,
VkFormatFeatureFlags features )
private

Helper to find supported depth formats.

◆ getExtent()

VkExtent2D VulkanSwapchain::getExtent ( ) const
inline

Gets resolution extent details.

Returns
VkExtent2D.

◆ getFramebuffers()

const std::vector< VkFramebuffer > & VulkanSwapchain::getFramebuffers ( ) const
inline

Gets active framebuffers list.

Returns
Vector of framebuffer handles.

◆ getImageFormat()

VkFormat VulkanSwapchain::getImageFormat ( ) const
inline

Gets selected swapchain format.

Returns
VkFormat.

◆ getRenderPass()

VkRenderPass VulkanSwapchain::getRenderPass ( ) const
inline

Gets default render pass for swapchain buffers.

Returns
VkRenderPass.

◆ getSwapchain()

VkSwapchainKHR VulkanSwapchain::getSwapchain ( ) const
inline

Gets raw KHR swapchain.

Returns
VkSwapchainKHR.

◆ initialize()

void VulkanSwapchain::initialize ( VkDevice dev,
VkPhysicalDevice phys,
VkSurfaceKHR surf,
uint32_t queueFamily )

Sets up parameters, selects formats, builds KHR swapchain, views, render pass and framebuffers.

Binds references and initializes swapchain creation.

Parameters
deviceVulkan logical device context.
physicalDeviceVulkan physical device.
surfacePresentation surface context.
graphicsQueueFamilyTarget graphics family index.
devLogical device context.
physPhysical device.
surfPresentation surface context.
queueFamilyGraphics queue family index.

Member Data Documentation

◆ depthFormat

VkFormat VulkanSwapchain::depthFormat = VK_FORMAT_D32_SFLOAT
private

Selected depth format.

◆ depthImage

VkImage VulkanSwapchain::depthImage = VK_NULL_HANDLE
private

GPU depth image allocation handle.

◆ depthImageMemory

VkDeviceMemory VulkanSwapchain::depthImageMemory = VK_NULL_HANDLE
private

GPU depth memory handle.

◆ depthImageView

VkImageView VulkanSwapchain::depthImageView = VK_NULL_HANDLE
private

Depth image view wrapper.

◆ device

VkDevice VulkanSwapchain::device = VK_NULL_HANDLE
private

Reference to logical device.

◆ extent

VkExtent2D VulkanSwapchain::extent {}
private

image extent (resolution) of swapchain buffers.

◆ framebuffers

std::vector<VkFramebuffer> VulkanSwapchain::framebuffers
private

framebuffers wrapping image views.

◆ imageFormat

VkFormat VulkanSwapchain::imageFormat {}
private

image format of swapchain buffers.

◆ images

std::vector<VkImage> VulkanSwapchain::images
private

Retrieved swapchain images.

◆ imageViews

std::vector<VkImageView> VulkanSwapchain::imageViews
private

image views wrapping swapchain images.

◆ physicalDevice

VkPhysicalDevice VulkanSwapchain::physicalDevice = VK_NULL_HANDLE
private

Reference to physical device.

◆ renderPass

VkRenderPass VulkanSwapchain::renderPass = VK_NULL_HANDLE
private

Render pass used for frame clearing and drawing.

◆ surface

VkSurfaceKHR VulkanSwapchain::surface = VK_NULL_HANDLE
private

Reference to presentation surface.

◆ swapchain

VkSwapchainKHR VulkanSwapchain::swapchain = VK_NULL_HANDLE
private

Raw swapchain handle.


The documentation for this class was generated from the following files: