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_qvulkaninstance.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
4#include <QGuiApplication>
5#include <QVulkanFunctions>
6#include <QVulkanInstance>
7#include <QWindow>
8
10
11struct Window {
12 void setVulkanInstance(QVulkanInstance *instance) { Q_UNUSED(instance); }
13 void show();
14};
15Window *window = nullptr;
16
17
19 int main(int argc, char **argv)
20 {
21 QGuiApplication app(argc, argv);
22
23 QVulkanInstance inst;
24 if (!inst.create())
25 return 1;
26
27 // ...
29 window->show();
30
31 return app.exec();
32 }
34
35
36void wrapper0() {
38 QVulkanInstance inst;
39
40 // Enable validation layer, if supported. Messages go to qDebug by default.
41 inst.setLayers({ "VK_LAYER_KHRONOS_validation" });
42
43 bool ok = inst.create();
44 if (!ok) {
45 // ... Vulkan not available
46 }
47
48 if (!inst.layers().contains("VK_LAYER_KHRONOS_validation")) {
49 // ... validation layer not available
50 }
52}
53
54
55void wrapper1() {
57 QVulkanInstance inst;
58
59 if (inst.supportedLayers().contains("VK_LAYER_KHRONOS_validation")) {
60 // ...
61 }
62 bool ok = inst.create();
63 // ...
65
67} // wrapper1
68} // src_gui_vulkan_qvulkaninstance
69
70
72
74class VulkanWindow : public QWindow
75{
76public:
78 setSurfaceType(VulkanSurface);
79 }
80
82 if (isExposed()) {
83 if (!m_initialized) {
84 m_initialized = true;
85 // initialize device, swapchain, etc.
86 QVulkanInstance *inst = vulkanInstance();
87 QVulkanFunctions *f = inst->functions();
88 uint32_t devCount = 0;
89 f->vkEnumeratePhysicalDevices(inst->vkInstance(), &devCount, nullptr);
90 // ...
91 // build the first frame
92 render();
93 }
94 }
95 }
96
97 bool event(QEvent *e) {
98 if (e->type() == QEvent::UpdateRequest)
99 render();
100 return QWindow::event(e);
101 }
102
103 void render() {
104 // ...
105 requestUpdate(); // render continuously
106 }
107
108private:
109 bool m_initialized = false;
110};
111
112int main(int argc, char **argv)
113{
114 QGuiApplication app(argc, argv);
115
116 QVulkanInstance inst;
117 if (!inst.create()) {
118 qWarning("Vulkan not available");
119 return 1;
120 }
121
123 window.showMaximized();
124
125 return app.exec();
126
127}
129
130
131} // src_gui_vulkan_qvulkaninstance2
static int exec()
Enters the main event loop and waits until exit() is called, then returns the value that was set to e...
\inmodule QtCore
Definition qcoreevent.h:45
@ UpdateRequest
Definition qcoreevent.h:113
Type type() const
Returns the event type.
Definition qcoreevent.h:304
The QExposeEvent class contains event parameters for expose events. \inmodule QtGui.
Definition qevent.h:515
\macro qGuiApp
@ VulkanSurface
Definition qsurface.h:35
The QVulkanFunctions class provides cross-platform access to the instance level core Vulkan 1....
The QVulkanInstance class represents a native Vulkan instance, enabling Vulkan rendering onto a QSurf...
\inmodule QtGui
Definition qwindow.h:63
virtual bool event(QEvent *) override
Override this to handle any event (ev) sent to the window.
Definition qwindow.cpp:2511
bool event(QEvent *e)
Override this to handle any event (ev) sent to the window.
void exposeEvent(QExposeEvent *)
The expose event (ev) is sent by the window system when a window moves between the un-exposed and exp...
int main()
[0]
#define qWarning
Definition qlogging.h:166
GLfloat GLfloat f
#define Q_UNUSED(x)
QApplication app(argc, argv)
[0]
aWidget window() -> setWindowTitle("New Window Title")
[2]