This is a basic demo for integrating the framework VulkanSceneGraph to QtQuick.
Features:
- Provide a standard QQuickItem-based control, called
Canvas
, rendered by VSG and can be integrated seamlessly into QtQuick app; - Support mouse interaction, key events and resizing;
- Support dynamically load VSG models.
The core idea is sharing a VkImage between VSG and QSG(short for Qt SceneGraph) via Vulkan's external memory extension.
The idea is possible because:
- VSG can create a framebuffer for offline rendering. Specifically, the color image attachment in the framebuffer is created with
VkExportMemoryAllocateInfo
enabled, which makes the image sharable between different Vulkan devices via external memory extension; - Qt has adopted a new rendering layer called Rhi, which fully supports Vulkan-based QtQuick rendering. So when QtQuick is running on Vulkan, it is possible to render a customized VkImage on top of the QSG using
QSGSimpleTextureNode
; - By creating the
QSGSimpleTextureNode
using the VkImage imported from VSG viaVkImportMemoryWin32HandleInfoKHR
(on Win32) orVkImportMemoryFdInfoKHR
(on Unix), the texture rendered by VSG can shown on the QtQuick window.
This demo is built & tested with:
- Qt 6.1.1;
- VSG 0.1.3;
- Vulkan SDK 1.2.176.1;
- on a Windows netbook with a integrated GPU (Intel HD Graphics 615) which supports Vulkan 1.0.0.
Although the codes in the demo try to adapt itself to Unix environment, it is not tested under that platform yet.
The following repos/examples are referenced in the demo:
- vsgheadless;
- vsgrendertotexture;
- Qt vulkantextureimport;
- vsgQtViewer. The class
KeyboardMap
is taken from this repo. Thanks.