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