Mandrill 2025.6.0
Loading...
Searching...
No Matches
Mandrill::Swapchain Class Reference

Swapchain class for managing the swapchain and its images. More...

#include <Swapchain.h>

Public Member Functions

MANDRILL_API Swapchain (ptr< Device > pDevice, uint32_t framesInFlight=2)
 Create a new swapchain.
 
MANDRILL_API ~Swapchain ()
 Destructor for swapchain.
 
MANDRILL_API void recreate ()
 Recreate the swapchain, for instance if window size changed.
 
MANDRILL_API VkCommandBuffer acquireNextImage ()
 Acquire the next image in the swapchain to render to.
 
MANDRILL_API void present (VkCommandBuffer cmd, ptr< Image > pImage)
 Present a rendered image to the swapchain image.
 
MANDRILL_API void requestScreenshot ()
 Request a screenshot from the next rendered frame. This call must be paired with a call to waitForScreenshot(). See App::takeScreenshot() for proper usage.
 
MANDRILL_API std::vector< uint8_t > waitForScreenshot ()
 Wait for screenshot to be available and acquire it. Only call this after a call to requestScreenshot(). See App::takeScreenshot() for proper usage.
 
MANDRILL_API VkSwapchainKHR getSwapchain () const
 Get the swapchain handle.
 
MANDRILL_API VkImage getImage () const
 Get the current swapchain image.
 
MANDRILL_API const std::vector< VkImage > & getImages () const
 Get all the swapchain images.
 
MANDRILL_API VkImageView getImageView () const
 Get the current swapchain image view.
 
MANDRILL_API const std::vector< VkImageView > & getImageViews () const
 Get all the swapchain image views.
 
MANDRILL_API VkDescriptorSet getImageDescriptorSet () const
 Get the descriptor set of the current swapchain image. Useful if using the swapchain image as a storage image in a shader.
 
MANDRILL_API VkFormat getImageFormat () const
 Get the image format of the swapchain.
 
MANDRILL_API VkExtent2D getExtent () const
 Get the extent (resolution) of the swapchain.
 
MANDRILL_API uint32_t getImageIndex () const
 Get the current image index.
 
MANDRILL_API uint32_t getInFlightIndex () const
 Get the current frame in flight index.
 
MANDRILL_API uint32_t getPreviousInFlightIndex () const
 Get the index of the previous frame that was in flight. This is useful when indexing after calling present(), like when querying for timestamps.
 
MANDRILL_API uint32_t getFramesInFlightCount () const
 Get the count of the total number of frames in flight.
 
MANDRILL_API bool recreated () const
 Check if the swapchain was recreated during the last frame. This is reset in present().
 

Detailed Description

Swapchain class for managing the swapchain and its images.

Constructor & Destructor Documentation

◆ Swapchain()

Swapchain::Swapchain ( ptr< Device pDevice,
uint32_t  framesInFlight = 2 
)

Create a new swapchain.

Parameters
pDeviceDevice to use
framesInFlightHow many frames in flight that should be used

Member Function Documentation

◆ acquireNextImage()

VkCommandBuffer Swapchain::acquireNextImage ( )

Acquire the next image in the swapchain to render to.

Returns
Command buffer to use to render to the new swapchain image

◆ getExtent()

MANDRILL_API VkExtent2D Mandrill::Swapchain::getExtent ( ) const
inline

Get the extent (resolution) of the swapchain.

Returns
Image extent

◆ getFramesInFlightCount()

MANDRILL_API uint32_t Mandrill::Swapchain::getFramesInFlightCount ( ) const
inline

Get the count of the total number of frames in flight.

Returns
Number of frames in flight

◆ getImage()

MANDRILL_API VkImage Mandrill::Swapchain::getImage ( ) const
inline

Get the current swapchain image.

Returns
Current swapchain image handle

◆ getImageDescriptorSet()

MANDRILL_API VkDescriptorSet Mandrill::Swapchain::getImageDescriptorSet ( ) const
inline

Get the descriptor set of the current swapchain image. Useful if using the swapchain image as a storage image in a shader.

Returns
Descriptor set handle

◆ getImageFormat()

MANDRILL_API VkFormat Mandrill::Swapchain::getImageFormat ( ) const
inline

Get the image format of the swapchain.

Returns
Image format

◆ getImageIndex()

MANDRILL_API uint32_t Mandrill::Swapchain::getImageIndex ( ) const
inline

Get the current image index.

Returns
Index to current swapchain image

◆ getImages()

MANDRILL_API const std::vector< VkImage > & Mandrill::Swapchain::getImages ( ) const
inline

Get all the swapchain images.

Returns
Vector of swapchain image handles

◆ getImageView()

MANDRILL_API VkImageView Mandrill::Swapchain::getImageView ( ) const
inline

Get the current swapchain image view.

Returns
Current swapchain image view

◆ getImageViews()

MANDRILL_API const std::vector< VkImageView > & Mandrill::Swapchain::getImageViews ( ) const
inline

Get all the swapchain image views.

Returns
Vector of swapchain image view handles

◆ getInFlightIndex()

MANDRILL_API uint32_t Mandrill::Swapchain::getInFlightIndex ( ) const
inline

Get the current frame in flight index.

Returns
Index to the current frame in flight

◆ getPreviousInFlightIndex()

MANDRILL_API uint32_t Mandrill::Swapchain::getPreviousInFlightIndex ( ) const
inline

Get the index of the previous frame that was in flight. This is useful when indexing after calling present(), like when querying for timestamps.

Returns
Index of previous frame in flight

◆ getSwapchain()

MANDRILL_API VkSwapchainKHR Mandrill::Swapchain::getSwapchain ( ) const
inline

Get the swapchain handle.

Returns
Swapchain handle

◆ present()

void Swapchain::present ( VkCommandBuffer  cmd,
ptr< Image pImage 
)

Present a rendered image to the swapchain image.

Parameters
cmdCommand buffer which was acquired with acquireNextImage()
pImageImage to blit to the swapchain image

◆ recreated()

MANDRILL_API bool Mandrill::Swapchain::recreated ( ) const
inline

Check if the swapchain was recreated during the last frame. This is reset in present().

Returns
True if recreated, otherwise false

◆ waitForScreenshot()

std::vector< uint8_t > Swapchain::waitForScreenshot ( )

Wait for screenshot to be available and acquire it. Only call this after a call to requestScreenshot(). See App::takeScreenshot() for proper usage.

Returns
Vector with pixel data

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