QVulkanWindowRenderer 类

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

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

公共函数

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

详细描述

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

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 .

成员函数文档编制

[虚拟] QVulkanWindowRenderer:: ~QVulkanWindowRenderer ()

虚拟析构函数。

[虚拟] 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 () 被调用。

默认实现为空。

[虚拟] 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 () 和 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 () 被调用。

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.

默认实现为空。

[虚拟] void QVulkanWindowRenderer:: logicalDeviceLost ()

This virtual function 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 function. QVulkanWindow will automatically release all resources (invoking releaseSwapChainResources () 和 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 ().

另请参阅 physicalDeviceLost ().

[虚拟] 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 .

默认实现为空。

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.

另请参阅 logicalDeviceLost ().

[虚拟] 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 () 和 QVulkanInstance::surfaceForWindow () are functional, but no further logical device initialization has taken place yet.

默认实现为空。

[虚拟] 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.

默认实现为空。

[虚拟] 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.

默认实现为空。

注意: 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.

[pure virtual] void QVulkanWindowRenderer:: startNextFrame ()

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

Each call to this function 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 function. 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 function is invoked. The current framebuffer and main command buffer can be retrieved via QVulkanWindow::currentFramebuffer () 和 QVulkanWindow::currentCommandBuffer (). The logical device and the active graphics queue are available via QVulkanWindow::device () 和 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 () 和 QVulkanWindow::deviceLocalMemoryIndex (). All these accessors are safe to be called from any thread.

另请参阅 QVulkanWindow::frameReady () 和 QVulkanWindow .