| 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 QQUICKRHIITEM_H |
| 5 | #define QQUICKRHIITEM_H |
| 6 | |
| 7 | #include <QtQuick/QQuickItem> |
| 8 | |
| 9 | QT_BEGIN_NAMESPACE |
| 10 | |
| 11 | class QQuickRhiItem; |
| 12 | class QQuickRhiItemPrivate; |
| 13 | class QQuickRhiItemNode; |
| 14 | class QRhi; |
| 15 | class QRhiCommandBuffer; |
| 16 | class QRhiTexture; |
| 17 | class QRhiRenderBuffer; |
| 18 | class QRhiRenderTarget; |
| 19 | |
| 20 | class Q_QUICK_EXPORT QQuickRhiItemRenderer |
| 21 | { |
| 22 | public: |
| 23 | QQuickRhiItemRenderer(); |
| 24 | virtual ~QQuickRhiItemRenderer(); |
| 25 | |
| 26 | protected: |
| 27 | virtual void initialize(QRhiCommandBuffer *cb) = 0; |
| 28 | virtual void synchronize(QQuickRhiItem *item) = 0; |
| 29 | virtual void render(QRhiCommandBuffer *cb) = 0; |
| 30 | |
| 31 | void update(); |
| 32 | |
| 33 | QRhi *rhi() const; |
| 34 | QRhiTexture *colorTexture() const; |
| 35 | QRhiRenderBuffer *msaaColorBuffer() const; |
| 36 | QRhiTexture *resolveTexture() const; |
| 37 | QRhiRenderBuffer *depthStencilBuffer() const; |
| 38 | QRhiRenderTarget *renderTarget() const; |
| 39 | |
| 40 | private: |
| 41 | QQuickRhiItemNode *node; |
| 42 | friend class QQuickRhiItem; |
| 43 | friend class QQuickRhiItemNode; |
| 44 | |
| 45 | Q_DISABLE_COPY_MOVE(QQuickRhiItemRenderer) |
| 46 | }; |
| 47 | |
| 48 | class Q_QUICK_EXPORT QQuickRhiItem : public QQuickItem |
| 49 | { |
| 50 | Q_OBJECT |
| 51 | Q_DECLARE_PRIVATE(QQuickRhiItem) |
| 52 | |
| 53 | Q_PROPERTY(int sampleCount READ sampleCount WRITE setSampleCount NOTIFY sampleCountChanged FINAL) |
| 54 | Q_PROPERTY(TextureFormat colorBufferFormat READ colorBufferFormat WRITE setColorBufferFormat NOTIFY colorBufferFormatChanged FINAL) |
| 55 | Q_PROPERTY(bool mirrorVertically READ isMirrorVerticallyEnabled WRITE setMirrorVertically NOTIFY mirrorVerticallyChanged FINAL) |
| 56 | Q_PROPERTY(bool alphaBlending READ alphaBlending WRITE setAlphaBlending NOTIFY alphaBlendingChanged FINAL) |
| 57 | Q_PROPERTY(int fixedColorBufferWidth READ fixedColorBufferWidth WRITE setFixedColorBufferWidth NOTIFY fixedColorBufferWidthChanged FINAL) |
| 58 | Q_PROPERTY(int fixedColorBufferHeight READ fixedColorBufferHeight WRITE setFixedColorBufferHeight NOTIFY fixedColorBufferHeightChanged FINAL) |
| 59 | Q_PROPERTY(QSize effectiveColorBufferSize READ effectiveColorBufferSize NOTIFY effectiveColorBufferSizeChanged FINAL) |
| 60 | |
| 61 | public: |
| 62 | enum class TextureFormat { |
| 63 | RGBA8, |
| 64 | RGBA16F, |
| 65 | RGBA32F, |
| 66 | RGB10A2 |
| 67 | }; |
| 68 | Q_ENUM(TextureFormat) |
| 69 | |
| 70 | explicit QQuickRhiItem(QQuickItem *parent = nullptr); |
| 71 | ~QQuickRhiItem() override; |
| 72 | |
| 73 | int sampleCount() const; |
| 74 | void setSampleCount(int samples); |
| 75 | |
| 76 | TextureFormat colorBufferFormat() const; |
| 77 | void setColorBufferFormat(TextureFormat format); |
| 78 | |
| 79 | bool isMirrorVerticallyEnabled() const; |
| 80 | void setMirrorVertically(bool enable); |
| 81 | |
| 82 | bool alphaBlending() const; |
| 83 | void setAlphaBlending(bool enable); |
| 84 | |
| 85 | int fixedColorBufferWidth() const; |
| 86 | void setFixedColorBufferWidth(int width); |
| 87 | int fixedColorBufferHeight() const; |
| 88 | void setFixedColorBufferHeight(int height); |
| 89 | |
| 90 | QSize effectiveColorBufferSize() const; |
| 91 | |
| 92 | bool isTextureProvider() const override; |
| 93 | QSGTextureProvider *textureProvider() const override; |
| 94 | |
| 95 | Q_SIGNALS: |
| 96 | void sampleCountChanged(); |
| 97 | void colorBufferFormatChanged(); |
| 98 | void autoRenderTargetChanged(); |
| 99 | void mirrorVerticallyChanged(); |
| 100 | void alphaBlendingChanged(); |
| 101 | void fixedColorBufferWidthChanged(); |
| 102 | void fixedColorBufferHeightChanged(); |
| 103 | void effectiveColorBufferSizeChanged(); |
| 104 | |
| 105 | protected: |
| 106 | virtual QQuickRhiItemRenderer *createRenderer() = 0; |
| 107 | |
| 108 | bool isAutoRenderTargetEnabled() const; |
| 109 | void setAutoRenderTarget(bool enabled); |
| 110 | |
| 111 | QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override; |
| 112 | bool event(QEvent *) override; |
| 113 | void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; |
| 114 | void releaseResources() override; |
| 115 | |
| 116 | private Q_SLOTS: |
| 117 | void invalidateSceneGraph(); |
| 118 | |
| 119 | friend class QQuickRhiItemNode; |
| 120 | }; |
| 121 | |
| 122 | QT_END_NAMESPACE |
| 123 | |
| 124 | #endif // QQUICKRHIITEM_H |
| 125 |
