Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
src_gui_vulkan_qvulkanwindow.cpp
Go to the documentation of this file.
1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3#include <QGuiApplication>
4#include <QVulkanDeviceFunctions>
5#include <QVulkanWindow>
6
8VkCommandBuffer commandBuffer;
9const VkRenderPassBeginInfo *renderPassBegin = nullptr;
10VkSubpassContents contents;
13{
14public:
15 VulkanRenderer(QVulkanWindow *w) : m_window(w), m_devFuncs(nullptr) { }
16
17 void initResources() override
18 {
19 m_devFuncs = m_window->vulkanInstance()->deviceFunctions(m_window->device());
20 // ..
21 }
22 void initSwapChainResources() override { /* ... */ }
23 void releaseSwapChainResources() override { /* ... */ }
24 void releaseResources() override { /* ... */ }
25
26 void startNextFrame() override
27 {
28 VkCommandBuffer cmdBuf = m_window->currentCommandBuffer();
29 // ...
30 m_devFuncs->vkCmdBeginRenderPass(commandBuffer, renderPassBegin, contents);
31 // ...
32 m_window->frameReady();
33 }
34
35private:
36 QVulkanWindow *m_window;
37 QVulkanDeviceFunctions *m_devFuncs;
38};
39
41{
42public:
44 return new VulkanRenderer(this);
45 }
46};
47
48int main(int argc, char *argv[])
49{
50 QGuiApplication app(argc, argv);
51
52 QVulkanInstance inst;
53 // enable the standard validation layers, when available
54 inst.setLayers({ "VK_LAYER_KHRONOS_validation" });
55 if (!inst.create())
56 qFatal("Failed to create Vulkan instance: %d", inst.errorCode());
57
59 w.setVulkanInstance(&inst);
60 w.showMaximized();
61
62 return app.exec();
63}
65
67 class Renderer {
68 void startNextFrame();
69 // ...
70
71 VkDescriptorBufferInfo m_uniformBufInfo[QVulkanWindow::MAX_CONCURRENT_FRAME_COUNT];
72 QVulkanWindow *m_window = nullptr;
73 };
74
75 void Renderer::startNextFrame()
76 {
77 VkDescriptorBufferInfo &uniformBufInfo(m_uniformBufInfo[m_window->currentFrame()]);
78 // ...
79 }
81
82} // src_gui_vulkan_qvulkanwindow
83
84
86
88 class Renderer {
89 void startNextFrame();
90 // ...
91
92 VkDescriptorBufferInfo m_uniformBufInfo[QVulkanWindow::MAX_CONCURRENT_FRAME_COUNT];
93 QVulkanWindow *m_window = nullptr;
94 };
95
96 void Renderer::startNextFrame()
97 {
98 const int count = m_window->concurrentFrameCount();
99 // for (int i = 0; i < count; ++i)
100 // m_uniformBufInfo[i] = ...
101 // ...
102 }
104
105} // src_gui_vulkan_qvulkanwindow2
static int exec()
Enters the main event loop and waits until exit() is called, then returns the value that was set to e...
\macro qGuiApp
The QVulkanDeviceFunctions class provides cross-platform access to the device level core Vulkan 1....
The QVulkanInstance class represents a native Vulkan instance, enabling Vulkan rendering onto a QSurf...
\inmodule QtGui
\inmodule QtGui
int main()
[0]
const VkRenderPassBeginInfo * renderPassBegin
#define qFatal
Definition qlogging.h:168
GLfloat GLfloat GLfloat w
[0]
GLenum GLenum GLsizei count
QObject::connect nullptr
QApplication app(argc, argv)
[0]