Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-15 08:34:13

0001 // Copyright (C) 2023 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 // Qt-Security score:significant reason:default
0004 
0005 #ifndef QRHIWIDGET_H
0006 #define QRHIWIDGET_H
0007 
0008 #include <QtWidgets/qwidget.h>
0009 
0010 QT_BEGIN_NAMESPACE
0011 
0012 class QRhiWidgetPrivate;
0013 class QRhi;
0014 class QRhiTexture;
0015 class QRhiRenderBuffer;
0016 class QRhiRenderTarget;
0017 class QRhiCommandBuffer;
0018 
0019 class Q_WIDGETS_EXPORT QRhiWidget : public QWidget
0020 {
0021     Q_OBJECT
0022     Q_DECLARE_PRIVATE(QRhiWidget)
0023     Q_PROPERTY(int sampleCount READ sampleCount WRITE setSampleCount NOTIFY sampleCountChanged)
0024     Q_PROPERTY(TextureFormat colorBufferFormat READ colorBufferFormat WRITE setColorBufferFormat NOTIFY colorBufferFormatChanged)
0025     Q_PROPERTY(QSize fixedColorBufferSize READ fixedColorBufferSize WRITE setFixedColorBufferSize NOTIFY fixedColorBufferSizeChanged)
0026     Q_PROPERTY(bool mirrorVertically READ isMirrorVerticallyEnabled WRITE setMirrorVertically NOTIFY mirrorVerticallyChanged)
0027     QDOC_PROPERTY(bool autoRenderTarget READ isAutoRenderTargetEnabled WRITE setAutoRenderTarget)
0028 
0029 public:
0030     explicit QRhiWidget(QWidget *parent = nullptr, Qt::WindowFlags f = {});
0031     ~QRhiWidget() override;
0032 
0033     enum class Api {
0034         Null,
0035         OpenGL,
0036         Metal,
0037         Vulkan,
0038         Direct3D11,
0039         Direct3D12,
0040     };
0041     Q_ENUM(Api)
0042 
0043     enum class TextureFormat {
0044         RGBA8,
0045         RGBA16F,
0046         RGBA32F,
0047         RGB10A2,
0048     };
0049     Q_ENUM(TextureFormat)
0050 
0051     Api api() const;
0052     void setApi(Api api);
0053 
0054     bool isDebugLayerEnabled() const;
0055     void setDebugLayerEnabled(bool enable);
0056 
0057     int sampleCount() const;
0058     void setSampleCount(int samples);
0059 
0060     TextureFormat colorBufferFormat() const;
0061     void setColorBufferFormat(TextureFormat format);
0062 
0063     QSize fixedColorBufferSize() const;
0064     void setFixedColorBufferSize(QSize pixelSize);
0065     void setFixedColorBufferSize(int w, int h) { setFixedColorBufferSize(QSize(w, h)); }
0066 
0067     bool isMirrorVerticallyEnabled() const;
0068     void setMirrorVertically(bool enabled);
0069 
0070     QImage grabFramebuffer() const;
0071 
0072 protected:
0073     explicit QRhiWidget(QRhiWidgetPrivate &dd, QWidget *parent = nullptr, Qt::WindowFlags f = {});
0074 
0075     bool isAutoRenderTargetEnabled() const;
0076     void setAutoRenderTarget(bool enabled);
0077 
0078     virtual void initialize(QRhiCommandBuffer *cb);
0079     virtual void render(QRhiCommandBuffer *cb);
0080     virtual void releaseResources();
0081 
0082     QRhi *rhi() const;
0083     QRhiTexture *colorTexture() const;
0084     QRhiRenderBuffer *msaaColorBuffer() const;
0085     QRhiTexture *resolveTexture() const;
0086     QRhiRenderBuffer *depthStencilBuffer() const;
0087     QRhiRenderTarget *renderTarget() const;
0088 
0089     void resizeEvent(QResizeEvent *e) override;
0090     void paintEvent(QPaintEvent *e) override;
0091     bool event(QEvent *e) override;
0092 
0093 Q_SIGNALS:
0094     void frameSubmitted();
0095     void renderFailed();
0096     void sampleCountChanged(int samples);
0097     void colorBufferFormatChanged(TextureFormat format);
0098     void fixedColorBufferSizeChanged(const QSize &pixelSize);
0099     void mirrorVerticallyChanged(bool enabled);
0100 };
0101 
0102 QT_END_NAMESPACE
0103 
0104 #endif