1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QVULKANWINDOW_H
5#define QVULKANWINDOW_H
6
7#include <QtGui/qtguiglobal.h>
8
9#if 0
10#pragma qt_no_master_include
11#pragma qt_sync_skip_header_check
12#endif
13
14#if QT_CONFIG(vulkan) || defined(Q_QDOC)
15
16#include <QtGui/qvulkaninstance.h>
17#include <QtGui/qwindow.h>
18#include <QtGui/qimage.h>
19#include <QtGui/qmatrix4x4.h>
20#include <QtCore/qset.h>
21
22#ifdef Q_QDOC
23typedef void* VkQueue;
24typedef void* VkCommandPool;
25typedef void* VkRenderPass;
26typedef void* VkCommandBuffer;
27typedef void* VkFramebuffer;
28typedef int VkPhysicalDeviceProperties;
29typedef int VkFormat;
30typedef int VkQueueFamilyProperties;
31typedef int VkDeviceQueueCreateInfo;
32typedef int VkFormat;
33typedef int VkSampleCountFlagBits;
34#endif
35
36QT_BEGIN_NAMESPACE
37
38class QVulkanWindowPrivate;
39
40class Q_GUI_EXPORT QVulkanWindowRenderer
41{
42public:
43 virtual ~QVulkanWindowRenderer();
44
45 virtual void preInitResources();
46 virtual void initResources();
47 virtual void initSwapChainResources();
48 virtual void releaseSwapChainResources();
49 virtual void releaseResources();
50
51 virtual void startNextFrame() = 0;
52
53 virtual void physicalDeviceLost();
54 virtual void logicalDeviceLost();
55};
56
57#ifndef VK_VERSION_1_1
58typedef struct VkPhysicalDeviceFeatures2 {
59 VkStructureType sType;
60 void* pNext;
61 VkPhysicalDeviceFeatures features;
62} VkPhysicalDeviceFeatures2;
63#endif
64
65class Q_GUI_EXPORT QVulkanWindow : public QWindow
66{
67 Q_OBJECT
68 Q_DECLARE_PRIVATE(QVulkanWindow)
69
70public:
71 enum Flag {
72 PersistentResources = 0x01
73 };
74 Q_DECLARE_FLAGS(Flags, Flag)
75
76 explicit QVulkanWindow(QWindow *parent = nullptr);
77 ~QVulkanWindow();
78
79 void setFlags(Flags flags);
80 Flags flags() const;
81
82 QList<VkPhysicalDeviceProperties> availablePhysicalDevices();
83 void setPhysicalDeviceIndex(int idx);
84
85 QVulkanInfoVector<QVulkanExtension> supportedDeviceExtensions();
86 void setDeviceExtensions(const QByteArrayList &extensions);
87
88 typedef std::function<void(VkPhysicalDeviceFeatures &)> EnabledFeaturesModifier;
89 void setEnabledFeaturesModifier(const EnabledFeaturesModifier &modifier);
90 typedef std::function<void(VkPhysicalDeviceFeatures2 &)> EnabledFeatures2Modifier;
91 void setEnabledFeaturesModifier(EnabledFeatures2Modifier modifier);
92
93 void setPreferredColorFormats(const QList<VkFormat> &formats);
94
95 QList<int> supportedSampleCounts();
96 void setSampleCount(int sampleCount);
97
98 typedef std::function<void(const VkQueueFamilyProperties *, uint32_t,
99 QList<VkDeviceQueueCreateInfo> &)>
100 QueueCreateInfoModifier;
101 void setQueueCreateInfoModifier(const QueueCreateInfoModifier &modifier);
102
103 bool isValid() const;
104
105 virtual QVulkanWindowRenderer *createRenderer();
106 void frameReady();
107
108 VkPhysicalDevice physicalDevice() const;
109 const VkPhysicalDeviceProperties *physicalDeviceProperties() const;
110 VkDevice device() const;
111 VkQueue graphicsQueue() const;
112 uint32_t graphicsQueueFamilyIndex() const;
113 VkCommandPool graphicsCommandPool() const;
114 uint32_t hostVisibleMemoryIndex() const;
115 uint32_t deviceLocalMemoryIndex() const;
116 VkRenderPass defaultRenderPass() const;
117
118 VkFormat colorFormat() const;
119 VkFormat depthStencilFormat() const;
120 QSize swapChainImageSize() const;
121
122 VkCommandBuffer currentCommandBuffer() const;
123 VkFramebuffer currentFramebuffer() const;
124 int currentFrame() const;
125
126 static const int MAX_CONCURRENT_FRAME_COUNT = 3;
127 int concurrentFrameCount() const;
128
129 int swapChainImageCount() const;
130 int currentSwapChainImageIndex() const;
131 VkImage swapChainImage(int idx) const;
132 VkImageView swapChainImageView(int idx) const;
133 VkImage depthStencilImage() const;
134 VkImageView depthStencilImageView() const;
135
136 VkSampleCountFlagBits sampleCountFlagBits() const;
137 VkImage msaaColorImage(int idx) const;
138 VkImageView msaaColorImageView(int idx) const;
139
140 bool supportsGrab() const;
141 QImage grab();
142
143 QMatrix4x4 clipCorrectionMatrix();
144
145Q_SIGNALS:
146 void frameGrabbed(const QImage &image);
147
148protected:
149 void exposeEvent(QExposeEvent *) override;
150 void resizeEvent(QResizeEvent *) override;
151 bool event(QEvent *) override;
152
153private:
154 Q_DISABLE_COPY(QVulkanWindow)
155};
156
157Q_DECLARE_OPERATORS_FOR_FLAGS(QVulkanWindow::Flags)
158
159QT_END_NAMESPACE
160
161#endif // QT_CONFIG(vulkan)
162
163#endif
164

Provided by KDAB

Privacy Policy
Learn Advanced QML with KDAB
Find out more

source code of qtbase/src/gui/vulkan/qvulkanwindow.h