evan 2026.1.4
Evan
Loading...
Searching...
No Matches
evan::DesktopSwapchainContext Class Reference

Swapchain context for desktop platforms using GLFW. More...

#include <headers/evan/glfw/DesktopSwapchainContext.hpp>

Inheritance diagram for evan::DesktopSwapchainContext:
Collaboration diagram for evan::DesktopSwapchainContext:

Public Member Functions

 DesktopSwapchainContext (const DeviceContext &deviceContext, GLFWwindow *window)
 Constructs a DesktopSwapchainContext instance with the provided device context and GLFW window.
 
void destroy (VkDevice device) override
 Destroys the swapchain and releases associated resources.
 
void recreateSwapchain (const DeviceContext &deviceContext, VkRenderPass renderpass) override
 Recreates the swapchain and associated resources.
 
VkResult aquireImage (uint32_t index, VkDevice device, VkSemaphore imageAvailableSemaphore, VkFence inFlightFence, uint32_t &imageIndex) override
 Acquires the next available image from the swapchain for rendering.
 
void waitForImage (uint32_t index) override
 Waits for the specified image to be available for rendering.
 
ViewSet & getViewSet () override
 Retrieves the set of views to render (mutable).
 
const ViewSet & getViewSet () const override
 Retrieves the set of views to render (const).
 
VkSampleCountFlagBits getMsaaSamples () const override
 Retrieves the MSAA sample count used by this swapchain context.
 
bool usesImageAvailableSemaphore () const override
 Desktop swapchains signal the image-available semaphore through vkAcquireNextImageKHR.
 
bool needsSwapchainRecreation () const override
 Desktop swapchains must be recreated when the GLFW window is resized.
 
- Public Member Functions inherited from evan::ASwapchainContext
VkRenderPass getRenderPass () const
 Retrieves the render pass associated with the swapchain context.
 
std::size_t getSwapchainCount () const
 Retrieves the number of swapchain image sets in the context.
 
virtual bool usesMultiview () const
 Indicates whether the frame renders every view in one pass.
 
utility::graphic::ViewF getView (std::size_t index) const
 Retrieves the view matrix for the specified view index.
 
virtual void setView (std::size_t index, const utility::graphic::ViewF &view)
 Sets the view state for the specified view index.
 
const utility::graphic::PoseF & getViewOffset (void) const
 Retrieves the persistent world-space view offset.
 
std::size_t getViewCount (void) const
 Retrieves the number of views in the swapchain context.
 
glm::mat4 getProjection (std::size_t index) const
 Retrieves the projection matrix for the specified view index.
 
utility::math::Vector2F getViewportSize () const
 Retrieves the current viewport size in pixels.
 

Additional Inherited Members

- Static Public Member Functions inherited from evan::ASwapchainContext
static void updateViewForExtent (utility::graphic::ViewF &view, VkExtent2D extent)
 Updates a view's viewport size and perspective for a new swapchain extent.
 
- Public Attributes inherited from evan::ASwapchainContext
std::vector< std::shared_ptr< ASwapchainImage > > _swapchainImages
 
- Protected Member Functions inherited from evan::ASwapchainContext
void createRenderPass (const std::shared_ptr< ADeviceBackend > &deviceBackend, VkSampleCountFlagBits msaaSamples, ColorAttachmentMode mode, uint32_t viewMask=0)
 Creates the Vulkan render pass for the swapchain context.
 
VkFormat selectSwapchainFormat (VkPhysicalDevice physicalDevice, const std::vector< int64_t > &swapchainFormats)
 Selects the appropriate swapchain format from the available formats.
 
VkFormat findSupportedFormat (VkPhysicalDevice physicalDevice, const std::vector< VkFormat > &candidates, VkImageTiling tiling, VkFormatFeatureFlags features)
 Finds a supported format from a list of candidates based on the specified tiling and feature requirements.
 
- Protected Attributes inherited from evan::ASwapchainContext
VkRenderPass _renderPass
 
utility::graphic::PoseF _viewOffset {}
 Persistent world-space offset applied on top of the tracked poses.
 

Detailed Description

Swapchain context for desktop platforms using GLFW.

This class manages the swapchain for desktop applications, providing functionality to acquire images, get projection and view matrices, and handle synchronization. It inherits from ASwapchainContext and implements the necessary virtual functions for desktop-specific behavior.

The constructor initializes the swapchain context with the given device context and GLFW window. The destructor ensures proper cleanup of resources. The aquireImage function allows acquiring an image from the swapchain, while getProjection and getView provide the necessary matrices for rendering.

Note
This class is designed to work with Vulkan and GLFW, and it assumes that the necessary Vulkan setup has been performed before its instantiation. It also relies on the DeviceContext for managing Vulkan resources and synchronization.

Definition at line 40 of file DesktopSwapchainContext.hpp.

Constructor & Destructor Documentation

◆ DesktopSwapchainContext()

evan::DesktopSwapchainContext::DesktopSwapchainContext ( const DeviceContext &  deviceContext,
GLFWwindow *  window 
)

Constructs a DesktopSwapchainContext instance with the provided device context and GLFW window.

This constructor initializes the swapchain context for desktop platforms using GLFW. It takes a reference to a DeviceContext instance, which provides access to Vulkan resources and synchronization mechanisms, and a pointer to a GLFWwindow, which is used to create the swapchain and manage the rendering surface.

Parameters
deviceContextA reference to the DeviceContext instance that provides access to Vulkan resources and synchronization mechanisms.
windowA pointer to the GLFWwindow that is used to create the swapchain and manage the rendering surface for desktop applications.
Note
The constructor performs necessary initialization steps to set up the swapchain context, including creating the swapchain, configuring synchronization primitives, and preparing for rendering operations. It is essential to ensure that the Vulkan instance and logical device have been properly initialized before creating an instance of DesktopSwapchainContext.

Definition at line 16 of file DesktopSwapchainContext.cpp.

Here is the call graph for this function:

◆ ~DesktopSwapchainContext()

evan::DesktopSwapchainContext::~DesktopSwapchainContext ( )

Definition at line 41 of file DesktopSwapchainContext.cpp.

Member Function Documentation

◆ aquireImage()

VkResult evan::DesktopSwapchainContext::aquireImage ( uint32_t  index,
VkDevice  device,
VkSemaphore  imageAvailableSemaphore,
VkFence  inFlightFence,
uint32_t &  imageIndex 
)
overridevirtual

Acquires the next available image from the swapchain for rendering.

This function overrides the pure virtual function from ASwapchainContext to handle the acquisition of the next available image from the swapchain for rendering. It takes several parameters, including the index of the image to acquire, the Vulkan device, a semaphore to signal when the image is available, a fence to signal when the image is in flight, and a reference to store the index of the acquired image. Implement this function to ensure that the rendering system can acquire images from the swapchain for rendering operations.

Parameters
indexThe index of the image to acquire from the swapchain.
deviceThe Vulkan device used to perform the image acquisition.
imageAvailableSemaphoreA Vulkan semaphore that will be signaled when the image is available for rendering.
inFlightFenceA Vulkan fence that will be signaled when the image is in flight and ready for rendering operations.
imageIndexA reference to a uint32_t variable where the index of the acquired image will be stored.
Returns
VkResult The result of the image acquisition operation, indicating success or failure. Implement this function to return appropriate Vulkan result codes based on the outcome of the image acquisition process.
Note
This function is crucial for managing the rendering workflow, as it allows the application to acquire images from the swapchain for rendering operations. Proper implementation of this function ensures that synchronization is handled correctly and that the rendering system can efficiently acquire and use images from the swapchain.

Implements evan::ASwapchainContext.

Definition at line 119 of file DesktopSwapchainContext.cpp.

◆ destroy()

void evan::DesktopSwapchainContext::destroy ( VkDevice  device)
overridevirtual

Destroys the swapchain and releases associated resources.

This function overrides the pure virtual function from ASwapchainContext to handle the destruction of the swapchain and the release of any resources associated with it. It takes a Vulkan device as a parameter, which is used to perform the necessary cleanup operations. Implement this function to ensure that all resources related to the swapchain are properly released when the swapchain is no longer needed.

Parameters
deviceThe Vulkan device used to perform cleanup operations for the swapchain.
Note
This function is essential for managing the lifecycle of the swapchain and ensuring that resources are properly released to prevent memory leaks and other issues in the rendering system. It should be implemented to handle the specific cleanup logic for the swapchain in the context of desktop applications using GLFW.

Implements evan::ASwapchainContext.

Definition at line 54 of file DesktopSwapchainContext.cpp.

◆ getMsaaSamples()

VkSampleCountFlagBits evan::DesktopSwapchainContext::getMsaaSamples ( ) const
overridevirtual

Retrieves the MSAA sample count used by this swapchain context.

Returns
The device-level MSAA sample count.

Implements evan::ASwapchainContext.

Definition at line 146 of file DesktopSwapchainContext.cpp.

◆ getViewSet() [1/2]

const evan::ViewSet & evan::DesktopSwapchainContext::getViewSet ( ) const
overridevirtual

Retrieves the set of views to render (const).

Returns
A const reference to the ViewSet.

Implements evan::ASwapchainContext.

Definition at line 141 of file DesktopSwapchainContext.cpp.

◆ getViewSet() [2/2]

evan::ViewSet & evan::DesktopSwapchainContext::getViewSet ( )
overridevirtual

Retrieves the set of views to render (mutable).

Returns
A mutable reference to the ViewSet.

Implements evan::ASwapchainContext.

Definition at line 136 of file DesktopSwapchainContext.cpp.

◆ needsSwapchainRecreation()

bool evan::DesktopSwapchainContext::needsSwapchainRecreation ( ) const
overridevirtual

Desktop swapchains must be recreated when the GLFW window is resized.

Returns
True when a framebuffer resize has been detected since the last recreation.

Reimplemented from evan::ASwapchainContext.

Definition at line 156 of file DesktopSwapchainContext.cpp.

◆ recreateSwapchain()

void evan::DesktopSwapchainContext::recreateSwapchain ( const DeviceContext &  deviceContext,
VkRenderPass  renderpass 
)
overridevirtual

Recreates the swapchain and associated resources.

This function is responsible for recreating the swapchain and any associated resources when the swapchain becomes out of date or needs to be recreated due to changes in the window size or other factors. It takes a reference to the DeviceContext instance, which provides access to Vulkan resources and synchronization mechanisms. Implement this function to ensure that the swapchain is properly recreated and that all necessary resources are reinitialized for rendering operations.

Parameters
deviceContextA reference to the DeviceContext instance that provides access to Vulkan resources and synchronization mechanisms.
renderpassThe Vulkan render pass that will be used with the swapchain images during rendering operations.

Implements evan::ASwapchainContext.

Definition at line 72 of file DesktopSwapchainContext.cpp.

Here is the call graph for this function:

◆ usesImageAvailableSemaphore()

bool evan::DesktopSwapchainContext::usesImageAvailableSemaphore ( ) const
overridevirtual

Desktop swapchains signal the image-available semaphore through vkAcquireNextImageKHR.

Returns
True.

Reimplemented from evan::ASwapchainContext.

Definition at line 151 of file DesktopSwapchainContext.cpp.

◆ waitForImage()

void evan::DesktopSwapchainContext::waitForImage ( uint32_t  index)
inlineoverridevirtual

Waits for the specified image to be available for rendering.

This function overrides the pure virtual function from ASwapchainContext to handle waiting for a specific image to be available for rendering. In the context of desktop applications using GLFW, this function may not require any specific implementation, as synchronization is typically handled through Vulkan semaphores and fences. However, it is essential to provide an implementation to satisfy the interface requirements of ASwapchainContext.

Parameters
indexThe index of the image to wait for.
Note
This function does not perform any specific operations in the context of desktop applications using GLFW, as synchronization is managed through Vulkan primitives. However, it is implemented to fulfill the interface requirements of ASwapchainContext and to provide a placeholder for any potential future synchronization logic that may be needed for specific use cases or platform-specific behavior.

Implements evan::ASwapchainContext.

Definition at line 173 of file DesktopSwapchainContext.hpp.


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