W3cubDocs

/Qt 5.15

QVulkanWindowRenderer Class

The QVulkanWindowRenderer class is used to implement the application-specific rendering logic for a QVulkanWindow. More...

Header: #include <QVulkanWindowRenderer>
qmake: QT += gui
Since: Qt 5.10

This class was introduced in Qt 5.10.

Public Functions

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

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.

Member Function Documentation

[virtual] QVulkanWindowRenderer::~QVulkanWindowRenderer()

Virtual destructor.

[virtual] void QVulkanWindowRenderer::initResources()

This virtual function is called when it is time to create the renderer's graphics resources.

Depending on the QVulkanWindow::PersistentResources flag, device lost situations, etc. this function 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 function and afterwards, up until releaseResources() is called.

The default implementation is empty.

[virtual] void QVulkanWindowRenderer::initSwapChainResources()

This virtual function 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 function 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 function is called effectively on every resize.

The default implementation is empty.

[virtual] void QVulkanWindowRenderer::logicalDeviceLost()

This virtual function is called when the logical device (VkDevice) is lost, meaning some operation failed with VK_ERROR_DEVICE_LOST.

The default implementation is empty.

There is typically no need to perform anything special in this function. 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().

See also physicalDeviceLost().

[virtual] void QVulkanWindowRenderer::physicalDeviceLost()

This virtual function is called when the physical device is lost, meaning the creation of the logical device fails with VK_ERROR_DEVICE_LOST.

The default implementation is empty.

There is typically no need to perform anything special in this function because QVulkanWindow will automatically retry to initialize itself after a certain amount of time.

See also logicalDeviceLost().

[virtual] void QVulkanWindowRenderer::preInitResources()

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

Normally there is no need to reimplement this function. However, there are cases that involve decisions based on both the physical device and the surface. These cannot normally be performed before making the QVulkanWindow visible since the Vulkan surface is not retrievable at that stage.

Instead, applications can reimplement this function. Here both QVulkanWindow::physicalDevice() and QVulkanInstance::surfaceForWindow() are functional, but no further logical device initialization has taken place yet.

The default implementation is empty.

[virtual] void QVulkanWindowRenderer::releaseResources()

This virtual function is called when the renderer's graphics resources must be released.

The implementation must be prepared that a call to this function may be followed by an initResources() at a later point.

QVulkanWindow takes care of waiting for the device to become idle before and after invoking this function.

The default implementation is empty.

[virtual] void QVulkanWindowRenderer::releaseSwapChainResources()

This virtual function is called when swapchain, framebuffer or renderpass related resources must be released.

The implementation must be prepared that a call to this function may be followed by a new call to initSwapChainResources() at a later point.

QVulkanWindow takes care of waiting for the device to become idle before and after invoking this function.

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 function in case there is a pending frame submission.

© The Qt Company Ltd
Licensed under the GNU Free Documentation License, Version 1.3.
https://doc.qt.io/qt-5.15/qvulkanwindowrenderer.html