SPARK  0.1.0
A general purpose game engine written in C++.
Loading...
Searching...
No Matches
spark::render::vk::VulkanSwapChain Class Referencefinal

Vulkan implementation of ISwapChain. More...

#include <VulkanSwapChain.h>

Inheritance diagram for spark::render::vk::VulkanSwapChain:
spark::render::SwapChain< IVulkanImage, VulkanFrameBuffer > spark::render::ISwapChain

Classes

struct  Impl
 

Public Member Functions

 VulkanSwapChain (const VulkanDevice &device, Format surface_format=Format::B8G8R8A8_SRGB, const math::Vector2< unsigned > &render_area={1280, 720}, unsigned buffers=3)
 Initializes a VulkanSwapChain.
 
 VulkanSwapChain (const VulkanSwapChain &other)=delete
 
 VulkanSwapChain (VulkanSwapChain &&other) noexcept=delete
 
VulkanSwapChainoperator= (const VulkanSwapChain &other)=delete
 
VulkanSwapChainoperator= (VulkanSwapChain &&other) noexcept=delete
 
const VkSemaphore & semaphore () const noexcept
 Gets the current swap semaphore, a command queue can wait on for presenting.
 
unsigned buffers () const noexcept override
 Gets the number of images in the swap chain.
 
math::Vector2< unsigned > renderArea () const noexcept override
 Gets the swap chain's render area.
 
Format surfaceFormat () const noexcept override
 Gets the swap chain's surface format.
 
std::vector< Format > surfaceFormats () const noexcept override
 Gets all the swap chain's supported surface formats.
 
void reset (Format surface_format, math::Vector2< unsigned > render_area, unsigned buffers) noexcept override
 Recreates the swap chain with the given parameters. All frame buffers that use this swap chain will be invalidated and recreated.
 
unsigned swapBackBuffer () const noexcept override
 Swaps the front buffer with the next back buffer in order.
 
std::vector< const IVulkanImage * > images () const noexcept override
 Gets all the swap chain's images.
 
const IVulkanImageimage (unsigned back_buffer) const override
 Gets the swap chain's current image for the given back buffer.
 
void present (const VulkanFrameBuffer &frame_buffer) const noexcept override
 Queues a present that gets executed after frame_buffer signals that it's done rendering.
 
- Public Member Functions inherited from spark::render::SwapChain< IVulkanImage, VulkanFrameBuffer >
virtual void present (const frame_buffer_type &frame_buffer) const noexcept=0
 Queues a present that gets executed after frame_buffer signals that it's done rendering.
 
- Public Member Functions inherited from spark::render::ISwapChain
virtual const IImageimage (unsigned int back_buffer) const =0
 Gets the swap chain's current image for the given back buffer.
 
std::vector< const IImage * > images () const noexcept
 Gets all the swap chain's images.
 
void present (const IFrameBuffer &frame_buffer) const noexcept
 Queues a present that gets executed after frame_buffer signals that it's done rendering.
 
virtual void reset (Format surface_format, math::Vector2< unsigned int > render_area, unsigned int buffers) noexcept=0
 Recreates the swap chain with the given parameters. All frame buffers that use this swap chain will be invalidated and recreated.
 

Additional Inherited Members

- Public Types inherited from spark::render::SwapChain< IVulkanImage, VulkanFrameBuffer >
using image_type
 
using frame_buffer_type
 

Detailed Description

Vulkan implementation of ISwapChain.

Constructor & Destructor Documentation

◆ VulkanSwapChain()

spark::render::vk::VulkanSwapChain::VulkanSwapChain ( const VulkanDevice & device,
Format surface_format = Format::B8G8R8A8_SRGB,
const math::Vector2< unsigned > & render_area = {1280, 720},
unsigned buffers = 3 )
explicit

Initializes a VulkanSwapChain.

Parameters
deviceThe device owning the swap chain.
surface_formatThe initial surface format. (default: B8G8R8A8_SRGB)
render_areaThe initial render area. (default: 1280x720)
buffersThe initial number of buffers. (default: 3)

Member Function Documentation

◆ buffers()

unsigned spark::render::vk::VulkanSwapChain::buffers ( ) const
nodiscardoverridevirtualnoexcept

Gets the number of images in the swap chain.

Returns
The number of images in the swap chain.

Implements spark::render::ISwapChain.

◆ image()

const IVulkanImage * spark::render::vk::VulkanSwapChain::image ( unsigned back_buffer) const
nodiscardoverride

Gets the swap chain's current image for the given back buffer.

Parameters
back_bufferIndex of the back buffer to get the image for.
Returns
A IImage pointer to the swap chain's current image for the given back buffer.
Exceptions
base::ArgumentOutOfRangeExceptionIf back_buffer is out of range.

◆ images()

std::vector< const IVulkanImage * > spark::render::vk::VulkanSwapChain::images ( ) const
nodiscardoverridevirtualnoexcept

Gets all the swap chain's images.

Returns
A std::vector containing pointers to all the swap chain's images.

Implements spark::render::SwapChain< IVulkanImage, VulkanFrameBuffer >.

◆ present()

void spark::render::vk::VulkanSwapChain::present ( const VulkanFrameBuffer & frame_buffer) const
overridenoexcept

Queues a present that gets executed after frame_buffer signals that it's done rendering.

Parameters
frame_bufferThe frame buffer for which the present should wait.

◆ renderArea()

math::Vector2< unsigned > spark::render::vk::VulkanSwapChain::renderArea ( ) const
nodiscardoverridevirtualnoexcept

Gets the swap chain's render area.

Returns
A math::Vector2<unsigned int> describing the swap chain's render area.

Implements spark::render::ISwapChain.

◆ reset()

void spark::render::vk::VulkanSwapChain::reset ( Format surface_format,
math::Vector2< unsigned > render_area,
unsigned buffers )
overridenoexcept

Recreates the swap chain with the given parameters. All frame buffers that use this swap chain will be invalidated and recreated.

There is no guarantee that:

  • the swap chain images will end up in the exact format, as specified by surface_format. If the format itself is not supported, a compatible format may be looked up. If the lookup fails, the method may raise an exception.
  • that the number of images returned by ISwapChain::images() matches the number specified in buffers. A swap chain may require a minimum number of images or may constraint a maximum number of images. In both cases, buffers will be clamped.
Parameters
surface_formatA Format describing the swap chain's surface format.
render_areaA math::Vector2<unsigned int> describing the swap chain's frame buffers size.
buffersThe number of buffers in the swap chain.

◆ semaphore()

const VkSemaphore & spark::render::vk::VulkanSwapChain::semaphore ( ) const
nodiscardnoexcept

Gets the current swap semaphore, a command queue can wait on for presenting.

Returns
The current swap semaphore, a command queue can wait on for presenting.

◆ surfaceFormat()

Format spark::render::vk::VulkanSwapChain::surfaceFormat ( ) const
nodiscardoverridevirtualnoexcept

Gets the swap chain's surface format.

Returns
A Format describing the swap chain's surface format.

Implements spark::render::ISwapChain.

◆ surfaceFormats()

std::vector< Format > spark::render::vk::VulkanSwapChain::surfaceFormats ( ) const
nodiscardoverridevirtualnoexcept

Gets all the swap chain's supported surface formats.

Returns
A std::vector containing all the swap chain's supported surface formats.

Implements spark::render::ISwapChain.

◆ swapBackBuffer()

unsigned spark::render::vk::VulkanSwapChain::swapBackBuffer ( ) const
nodiscardoverridevirtualnoexcept

Swaps the front buffer with the next back buffer in order.

Returns
The new front buffer after the swap.

Implements spark::render::ISwapChain.