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
9QT_BEGIN_NAMESPACE
10
11class QRhiWidgetPrivate;
12class QRhi;
13class QRhiTexture;
14class QRhiRenderBuffer;
15class QRhiRenderTarget;
16class QRhiCommandBuffer;
17
18class 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
28public:
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
71protected:
72 explicit QRhiWidget(QRhiWidgetPrivate &dd, QWidget *parent = nullptr, Qt::WindowFlags f = {});
73
74 bool isAutoRenderTargetEnabled() const;
75 void setAutoRenderTarget(bool enabled);
76
77 virtual void initialize(QRhiCommandBuffer *cb);
78 virtual void render(QRhiCommandBuffer *cb);
79 virtual void releaseResources();
80
81 QRhi *rhi() const;
82 QRhiTexture *colorTexture() const;
83 QRhiRenderBuffer *msaaColorBuffer() const;
84 QRhiTexture *resolveTexture() const;
85 QRhiRenderBuffer *depthStencilBuffer() const;
86 QRhiRenderTarget *renderTarget() const;
87
88 void resizeEvent(QResizeEvent *e) override;
89 void paintEvent(QPaintEvent *e) override;
90 bool event(QEvent *e) override;
91
92Q_SIGNALS:
93 void frameSubmitted();
94 void renderFailed();
95 void sampleCountChanged(int samples);
96 void colorBufferFormatChanged(TextureFormat format);
97 void fixedColorBufferSizeChanged(const QSize &pixelSize);
98 void mirrorVerticallyChanged(bool enabled);
99};
100
101QT_END_NAMESPACE
102
103#endif
104

source code of qtbase/src/widgets/kernel/qrhiwidget.h