Overte C++ Documentation
VKWindow.h
1 //
2 // Created by Bradley Austin Davis on 2016/03/19
3 // Copyright 2016-2018 High Fidelity, Inc.
4 // Copyright 2022-2025 Overte e.V.
5 //
6 // Distributed under the Apache License, Version 2.0.
7 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
8 //
9 
10 #pragma once
11 
12 #include <QtCore/QCoreApplication>
13 #include <QtGui/QWindow>
14 #include <QtGui/qevent.h>
15 #include <QtCore/QTimer>
16 #include <QtCore/QDebug>
17 
18 #include "Allocation.h"
19 #include "Config.h"
20 #include "Context.h"
21 #include "VulkanSwapChain.h"
22 
23 class VKWindow : public QWindow {
24  Q_OBJECT
25 public:
26  VKWindow(QScreen* screen = nullptr);
27  virtual ~VKWindow();
28 
29  void createSwapchain();
30  void createSurface();
31 
32  bool event(QEvent *event) override;
33 
34 signals:
35  void aboutToClose();
36 
37 protected:
38  friend struct vks::Context;
39  void emitClosing();
40 
41 public slots:
42  virtual void resizeFramebuffer();
43 
44 protected:
45  void resizeEvent(QResizeEvent* event) override;
46 
47  void setupRenderPass();
48  void setupDepthStencil();
49  void setupFramebuffers();
50  void createCommandBuffers();
51  void vulkanCleanup(); // Called by the context before backend is destroyed.
52 
53 public:
54  VKWidget *_primaryWidget{ nullptr };
55  vks::Context& _context{ vks::Context::get() };
56  VkRenderPass _renderPass{};
57  VkExtent2D _extent;
58  VulkanSwapChain _swapchain;
59  VkSemaphore _acquireCompleteSemaphore{};
60  VkSemaphore _renderCompleteSemaphore{};
61  std::vector<VkCommandBuffer> _drawCommandBuffers;
62  struct : vks::Allocation {
63  bool isAllocated {false};
64  VkImage image;
65  VkImageView view;
66  } _depthStencil{};
67  std::vector<VkFramebuffer> _frameBuffers;
68  std::atomic<bool> _isVulkanCleanupComplete{ false };
69  std::atomic<bool> _needsResizing{ true };
70  VkFence _previousFrameFence{ VK_NULL_HANDLE };
71  VkCommandBuffer _previousCommandBuffer{ VK_NULL_HANDLE };
72  VkSemaphore _previousAcquireCompleteSemaphore{ VK_NULL_HANDLE };
73  VkSemaphore _previousRenderCompleteSemaphore{ VK_NULL_HANDLE };
74 };
customized canvas that simply forwards requests/events to the singleton application
Definition: VKWidget.h:31