1 | // Copyright (C) 2023 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 QRHIWIDGET_H |
5 | #define QRHIWIDGET_H |
6 | |
7 | #include <QtWidgets/qwidget.h> |
8 | |
9 | QT_BEGIN_NAMESPACE |
10 | |
11 | class QRhiWidgetPrivate; |
12 | class QRhi; |
13 | class QRhiTexture; |
14 | class QRhiRenderBuffer; |
15 | class QRhiRenderTarget; |
16 | class QRhiCommandBuffer; |
17 | |
18 | class Q_WIDGETS_EXPORT QRhiWidget : public QWidget |
19 | { |
20 | Q_OBJECT |
21 | Q_DECLARE_PRIVATE(QRhiWidget) |
22 | Q_PROPERTY(int sampleCount READ sampleCount WRITE setSampleCount NOTIFY sampleCountChanged) |
23 | Q_PROPERTY(TextureFormat colorBufferFormat READ colorBufferFormat WRITE setColorBufferFormat NOTIFY colorBufferFormatChanged) |
24 | Q_PROPERTY(QSize fixedColorBufferSize READ fixedColorBufferSize WRITE setFixedColorBufferSize NOTIFY fixedColorBufferSizeChanged) |
25 | Q_PROPERTY(bool mirrorVertically READ isMirrorVerticallyEnabled WRITE setMirrorVertically NOTIFY mirrorVerticallyChanged) |
26 | QDOC_PROPERTY(bool autoRenderTarget READ isAutoRenderTargetEnabled WRITE setAutoRenderTarget) |
27 | |
28 | public: |
29 | explicit QRhiWidget(QWidget *parent = nullptr, Qt::WindowFlags f = {}); |
30 | ~QRhiWidget() override; |
31 | |
32 | enum class Api { |
33 | Null, |
34 | OpenGL, |
35 | Metal, |
36 | Vulkan, |
37 | Direct3D11, |
38 | Direct3D12, |
39 | }; |
40 | Q_ENUM(Api) |
41 | |
42 | enum class TextureFormat { |
43 | RGBA8, |
44 | RGBA16F, |
45 | RGBA32F, |
46 | RGB10A2, |
47 | }; |
48 | Q_ENUM(TextureFormat) |
49 | |
50 | Api api() const; |
51 | void setApi(Api api); |
52 | |
53 | bool isDebugLayerEnabled() const; |
54 | void setDebugLayerEnabled(bool enable); |
55 | |
56 | int sampleCount() const; |
57 | void setSampleCount(int samples); |
58 | |
59 | TextureFormat colorBufferFormat() const; |
60 | void setColorBufferFormat(TextureFormat format); |
61 | |
62 | QSize fixedColorBufferSize() const; |
63 | void setFixedColorBufferSize(QSize pixelSize); |
64 | void setFixedColorBufferSize(int w, int h) { setFixedColorBufferSize(QSize(w, h)); } |
65 | |
66 | bool isMirrorVerticallyEnabled() const; |
67 | void setMirrorVertically(bool enabled); |
68 | |
69 | QImage grabFramebuffer() const; |
70 | |
71 | protected: |
72 | bool isAutoRenderTargetEnabled() const; |
73 | void setAutoRenderTarget(bool enabled); |
74 | |
75 | virtual void initialize(QRhiCommandBuffer *cb); |
76 | virtual void render(QRhiCommandBuffer *cb); |
77 | virtual void releaseResources(); |
78 | |
79 | QRhi *rhi() const; |
80 | QRhiTexture *colorTexture() const; |
81 | QRhiRenderBuffer *msaaColorBuffer() const; |
82 | QRhiTexture *resolveTexture() const; |
83 | QRhiRenderBuffer *depthStencilBuffer() const; |
84 | QRhiRenderTarget *renderTarget() const; |
85 | |
86 | void resizeEvent(QResizeEvent *e) override; |
87 | void paintEvent(QPaintEvent *e) override; |
88 | bool event(QEvent *e) override; |
89 | |
90 | Q_SIGNALS: |
91 | void frameSubmitted(); |
92 | void renderFailed(); |
93 | void sampleCountChanged(int samples); |
94 | void colorBufferFormatChanged(TextureFormat format); |
95 | void fixedColorBufferSizeChanged(const QSize &pixelSize); |
96 | void mirrorVerticallyChanged(bool enabled); |
97 | }; |
98 | |
99 | QT_END_NAMESPACE |
100 | |
101 | #endif |
102 | |