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 |
23 | typedef void* VkQueue; |
24 | typedef void* VkCommandPool; |
25 | typedef void* VkRenderPass; |
26 | typedef void* VkCommandBuffer; |
27 | typedef void* VkFramebuffer; |
28 | typedef int VkPhysicalDeviceProperties; |
29 | typedef int VkFormat; |
30 | typedef int VkQueueFamilyProperties; |
31 | typedef int VkDeviceQueueCreateInfo; |
32 | typedef int VkFormat; |
33 | typedef int VkSampleCountFlagBits; |
34 | #endif |
35 | |
36 | QT_BEGIN_NAMESPACE |
37 | |
38 | class QVulkanWindowPrivate; |
39 | |
40 | class Q_GUI_EXPORT QVulkanWindowRenderer |
41 | { |
42 | public: |
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 | class Q_GUI_EXPORT QVulkanWindow : public QWindow |
58 | { |
59 | Q_OBJECT |
60 | Q_DECLARE_PRIVATE(QVulkanWindow) |
61 | |
62 | public: |
63 | enum Flag { |
64 | PersistentResources = 0x01 |
65 | }; |
66 | Q_DECLARE_FLAGS(Flags, Flag) |
67 | |
68 | explicit QVulkanWindow(QWindow *parent = nullptr); |
69 | ~QVulkanWindow(); |
70 | |
71 | void setFlags(Flags flags); |
72 | Flags flags() const; |
73 | |
74 | QList<VkPhysicalDeviceProperties> availablePhysicalDevices(); |
75 | void setPhysicalDeviceIndex(int idx); |
76 | |
77 | QVulkanInfoVector<QVulkanExtension> supportedDeviceExtensions(); |
78 | void setDeviceExtensions(const QByteArrayList &extensions); |
79 | |
80 | typedef std::function<void(VkPhysicalDeviceFeatures &)> EnabledFeaturesModifier; |
81 | void setEnabledFeaturesModifier(const EnabledFeaturesModifier &modifier); |
82 | |
83 | void setPreferredColorFormats(const QList<VkFormat> &formats); |
84 | |
85 | QList<int> supportedSampleCounts(); |
86 | void setSampleCount(int sampleCount); |
87 | |
88 | typedef std::function<void(const VkQueueFamilyProperties *, uint32_t, |
89 | QList<VkDeviceQueueCreateInfo> &)> |
90 | QueueCreateInfoModifier; |
91 | void setQueueCreateInfoModifier(const QueueCreateInfoModifier &modifier); |
92 | |
93 | bool isValid() const; |
94 | |
95 | virtual QVulkanWindowRenderer *createRenderer(); |
96 | void frameReady(); |
97 | |
98 | VkPhysicalDevice physicalDevice() const; |
99 | const VkPhysicalDeviceProperties *physicalDeviceProperties() const; |
100 | VkDevice device() const; |
101 | VkQueue graphicsQueue() const; |
102 | uint32_t graphicsQueueFamilyIndex() const; |
103 | VkCommandPool graphicsCommandPool() const; |
104 | uint32_t hostVisibleMemoryIndex() const; |
105 | uint32_t deviceLocalMemoryIndex() const; |
106 | VkRenderPass defaultRenderPass() const; |
107 | |
108 | VkFormat colorFormat() const; |
109 | VkFormat depthStencilFormat() const; |
110 | QSize swapChainImageSize() const; |
111 | |
112 | VkCommandBuffer currentCommandBuffer() const; |
113 | VkFramebuffer currentFramebuffer() const; |
114 | int currentFrame() const; |
115 | |
116 | static const int MAX_CONCURRENT_FRAME_COUNT = 3; |
117 | int concurrentFrameCount() const; |
118 | |
119 | int swapChainImageCount() const; |
120 | int currentSwapChainImageIndex() const; |
121 | VkImage swapChainImage(int idx) const; |
122 | VkImageView swapChainImageView(int idx) const; |
123 | VkImage depthStencilImage() const; |
124 | VkImageView depthStencilImageView() const; |
125 | |
126 | VkSampleCountFlagBits sampleCountFlagBits() const; |
127 | VkImage msaaColorImage(int idx) const; |
128 | VkImageView msaaColorImageView(int idx) const; |
129 | |
130 | bool supportsGrab() const; |
131 | QImage grab(); |
132 | |
133 | QMatrix4x4 clipCorrectionMatrix(); |
134 | |
135 | Q_SIGNALS: |
136 | void frameGrabbed(const QImage &image); |
137 | |
138 | protected: |
139 | void exposeEvent(QExposeEvent *) override; |
140 | void resizeEvent(QResizeEvent *) override; |
141 | bool event(QEvent *) override; |
142 | |
143 | private: |
144 | Q_DISABLE_COPY(QVulkanWindow) |
145 | }; |
146 | |
147 | Q_DECLARE_OPERATORS_FOR_FLAGS(QVulkanWindow::Flags) |
148 | |
149 | QT_END_NAMESPACE |
150 | |
151 | #endif // QT_CONFIG(vulkan) |
152 | |
153 | #endif |
154 | |