Overte C++ Documentation
VKWidget.h
1 //
2 // Created by Bradley Austin Davis on 2015/12/03
3 // Copyright 2013-2018 High Fidelity, Inc.
4 // Copyright 2020 Maki.
5 // Copyright 2023-2025 Overte e.V.
6 //
7 // Distributed under the Apache License, Version 2.0.
8 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
9 //
10 
11 
12 #pragma once
13 
14 #include <QtWidgets/QWidget>
15 #include "Context.h"
16 #include "VulkanSwapChain.h"
17 
18 namespace gl {
19 class Context;
20 class OffscreenContext;
21 }
22 
23 namespace vks {
24 struct Context;
25 }
26 
27 class QOpenGLContext;
28 
29 // VKTODO: make this and GLWidget inherit from the same base class, for example called GraphicsWidget.
31 class VKWidget : public QWidget {
32  Q_OBJECT
33 
34  friend struct vks::Context;
35 
36 public:
37  VKWidget(QWidget *parent = nullptr);
38  ~VKWidget() override;
39 
40  [[nodiscard]] int getDeviceWidth() const;
41  [[nodiscard]] int getDeviceHeight() const;
42  [[nodiscard]] QSize getDeviceSize() const { return QSize(getDeviceWidth(), getDeviceHeight()); }
43  [[nodiscard]] QPaintEngine* paintEngine() const override;
44  void createContext(QOpenGLContext* shareContext = nullptr);
45  bool makeCurrent();
46  void doneCurrent();
47  void swapBuffers();
48  gl::OffscreenContext* context() { return _context; }
49  QOpenGLContext* qglContext();
50  [[nodiscard]] QVariant inputMethodQuery(Qt::InputMethodQuery query) const override;
51 
52 protected:
53  bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
54  bool event(QEvent* event) override;
55  gl::OffscreenContext* _context { nullptr };
56 
57 private:
58  QPaintEngine* _paintEngine { nullptr };
59 
60  bool _vsyncSupported { false };
61 
62 public:
63  VKWindow *_mainWindow; // For getting Vulkan surface, VKTODO: make a better way of setting it
64 };
customized canvas that simply forwards requests/events to the singleton application
Definition: VKWidget.h:31