Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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
11//! [0]
13{
14public:
15 VulkanRenderer(QVulkanWindow *w) : m_window(w), m_devFuncs(nullptr) { }
16
18 {
19 m_devFuncs = m_window->vulkanInstance()->deviceFunctions(m_window->device());
20 // ..
21 }
22 void initSwapChainResources() override { /* ... */ }
24 void releaseResources() override { /* ... */ }
25
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}
64//! [0]
65
66//! [1]
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 }
80//! [1]
81
82} // src_gui_vulkan_qvulkanwindow
83
84
86
87//! [2]
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 }
103//! [2]
104
105} // src_gui_vulkan_qvulkanwindow2
const VkRenderPassBeginInfo * renderPassBegin