CopperSpice API  1.9.1
QVulkanWindowRenderer Class Referenceabstract

Implements the application specific rendering logic for a QVulkanWindow. More...

Public Methods

virtual ~QVulkanWindowRenderer ()
 
virtual void initResources ()
 
virtual void initSwapChainResources ()
 
virtual void logicalDeviceLost ()
 
virtual void physicalDeviceLost ()
 
virtual void preInitResources ()
 
virtual void releaseResources ()
 
virtual void releaseSwapChainResources ()
 
virtual void startNextFrame () = 0
 

Detailed Description

Applications typically subclass both QVulkanWindow and QVulkanWindowRenderer. The former allows handling events, for example, input, while the latter allows implementing the Vulkan resource management and command buffer building that make up the application's rendering.

In addition to event handling, the QVulkanWindow subclass is responsible for providing an implementation for QVulkanWindow::createRenderer() as well. This is where the window and renderer get connected. A typical implementation will simply create a new instance of a subclass of QVulkanWindowRenderer.

Constructor & Destructor Documentation

QVulkanWindowRenderer::~QVulkanWindowRenderer ( )
virtual

Destructor.

Method Documentation

void QVulkanWindowRenderer::initResources ( )
virtual

This method is called to create the renderer's graphics resources. Depending on the QVulkanWindow::PersistentResources flag, device lost situations, etc. this method may be called more than once during the lifetime of a QVulkanWindow. However, subsequent invocations are always preceded by a call to releaseResources().

Accessors like device(), graphicsQueue(), and graphicsCommandPool() are only guaranteed to return valid values inside this method and afterwards, up until releaseResources() is called.

The default implementation is empty.

void QVulkanWindowRenderer::initSwapChainResources ( )
virtual

This method is called when swapchain, framebuffer or renderpass related initialization can be performed. Swapchain and related resources are reset and then recreated in response to window resize events, and therefore a pair of calls to initResources() and releaseResources() can have multiple calls to initSwapChainResources() and releaseSwapChainResources() calls in between.

Accessors like QVulkanWindow::swapChainImageSize() are only guaranteed to return valid values inside this method and afterwards, up until releaseSwapChainResources() is called.

This is also the place where size-dependent calculations (for example, the projection matrix) should be made since this method is called effectively on every resize.

The default implementation is empty.

void QVulkanWindowRenderer::logicalDeviceLost ( )
virtual

This method is called when the logical device (VkDevice) is lost, meaning some operation failed with VK_ERROR_DEVICE_LOST. There is typically no need to perform anything special in this method. QVulkanWindow will automatically release all resources (invoking releaseSwapChainResources() and releaseResources() as necessary) and will attempt to reinitialize, acquiring a new device. When the physical device was also lost, this reinitialization attempt may then result in physicalDeviceLost().

The default implementation is empty.

See also
physicalDeviceLost()
void QVulkanWindowRenderer::physicalDeviceLost ( )
virtual

This method is called when the physical device is lost, meaning the creation of the logical device fails with VK_ERROR_DEVICE_LOST. There is typically no need to perform anything special in this method because QVulkanWindow will automatically retry to initialize itself after a certain amount of time.

The default implementation is empty.

See also
logicalDeviceLost()
void QVulkanWindowRenderer::preInitResources ( )
virtual

This method is called right before graphics initialization, that ends up in calling initResources(), is about to begin.

Normally there is no need to reimplement this method. However, there are cases that involve decisions based on both the physical device and the surface. These can not normally be performed before making the QVulkanWindow visible since the Vulkan surface is not retrievable at that stage.Instead, applications can reimplement this method. Both QVulkanWindow::physicalDevice() and QVulkanInstance::surfaceForWindow() are functional, but no further logical device initialization has taken place yet.

The default implementation is empty.

void QVulkanWindowRenderer::releaseResources ( )
virtual

This method is called when the renderer's graphics resources must be released. QVulkanWindow takes care of waiting for the device to become idle before and after invoking this method. The implementation must be prepared that a call to this method may be followed by an initResources() at a later point.

The default implementation is empty.

void QVulkanWindowRenderer::releaseSwapChainResources ( )
virtual

This method is called when swapchain, framebuffer or renderpass related resources must be released. QVulkanWindow takes care of waiting for the device to become idle before and after invoking this method. The implementation must be prepared that a call to this method may be followed by a new call to initSwapChainResources() at a later point.

The default implementation is empty.

Note
This is the last place to act with all graphics resources intact before QVulkanWindow starts releasing them. It is therefore essential that implementations with an asynchronous, potentially multi-threaded startNextFrame() perform a blocking wait and call QVulkanWindow::frameReady() before returning from this method in case there is a pending frame submission.
void QVulkanWindowRenderer::startNextFrame ( )
pure virtual

This method is called when the draw calls for the next frame are to be added to the command buffer.

Each call to this method must be followed by a call to QVulkanWindow::frameReady(). Failing to do so will stall the rendering loop. The call can also be made at a later time, after returning from this method. This means that it is possible to kick off asynchronous work, and only update the command buffer and notify QVulkanWindow when that work has finished.

All Vulkan resources are initialized and ready when this method is invoked. The current framebuffer and main command buffer can be retrieved via QVulkanWindow::currentFramebuffer() and QVulkanWindow::currentCommandBuffer(). The logical device and the active graphics queue are available via QVulkanWindow::device() and QVulkanWindow::graphicsQueue(). Implementations can create additional command buffers from the pool returned by QVulkanWindow::graphicsCommandPool(). For convenience, the index of a host visible and device local memory type index are exposed via QVulkanWindow::hostVisibleMemoryIndex() and QVulkanWindow::deviceLocalMemoryIndex(). All these accessors are safe to be called from any thread.

See also
QVulkanWindow::frameReady(), QVulkanWindow