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_P_H |
5 | #define QQUICKRHIITEM_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include "qquickrhiitem.h" |
19 | #include <QtQuick/QSGTextureProvider> |
20 | #include <QtQuick/QSGSimpleTextureNode> |
21 | #include <QtQuick/private/qquickitem_p.h> |
22 | #include <rhi/qrhi.h> |
23 | |
24 | QT_BEGIN_NAMESPACE |
25 | |
26 | class QQuickRhiItemNode : public QSGTextureProvider, public QSGSimpleTextureNode |
27 | { |
28 | Q_OBJECT |
29 | |
30 | public: |
31 | QQuickRhiItemNode(QQuickRhiItem *item); |
32 | |
33 | QSGTexture *texture() const override; |
34 | |
35 | void sync(); |
36 | QRhiCommandBuffer *queryCommandBuffer(); |
37 | void resetColorBufferObjects(); |
38 | void resetRenderTargetObjects(); |
39 | |
40 | bool isValid() const |
41 | { |
42 | return m_rhi && m_sgTexture; |
43 | } |
44 | |
45 | void scheduleUpdate() |
46 | { |
47 | m_renderPending = true; |
48 | m_window->update(); // ensure getting to beforeRendering() at some point |
49 | } |
50 | |
51 | bool hasRenderer() const |
52 | { |
53 | return m_renderer != nullptr; |
54 | } |
55 | |
56 | void setRenderer(QQuickRhiItemRenderer *r) |
57 | { |
58 | m_renderer.reset(p: r); |
59 | } |
60 | |
61 | QQuickRhiItem *m_item; |
62 | QQuickWindow *m_window; |
63 | QSize m_pixelSize; |
64 | qreal m_dpr = 0.0f; |
65 | QRhi *m_rhi = nullptr; |
66 | bool m_renderPending = true; |
67 | std::unique_ptr<QSGTexture> m_sgTexture; |
68 | std::unique_ptr<QQuickRhiItemRenderer> m_renderer; |
69 | QRhiTexture *m_colorTexture = nullptr; |
70 | QRhiTexture *m_resolveTexture = nullptr; |
71 | std::unique_ptr<QRhiRenderBuffer> m_msaaColorBuffer; |
72 | std::unique_ptr<QRhiRenderBuffer> m_depthStencilBuffer; |
73 | std::unique_ptr<QRhiTextureRenderTarget> m_renderTarget; |
74 | std::unique_ptr<QRhiRenderPassDescriptor> m_renderPassDescriptor; |
75 | |
76 | public slots: |
77 | void render(); |
78 | }; |
79 | |
80 | class QQuickRhiItemPrivate : public QQuickItemPrivate |
81 | { |
82 | Q_DECLARE_PUBLIC(QQuickRhiItem) |
83 | |
84 | public: |
85 | static QQuickRhiItemPrivate *get(QQuickRhiItem *item) { return item->d_func(); } |
86 | |
87 | mutable QQuickRhiItemNode *node = nullptr; |
88 | QQuickRhiItem::TextureFormat itemTextureFormat = QQuickRhiItem::TextureFormat::RGBA8; |
89 | QRhiTexture::Format rhiTextureFormat = QRhiTexture::RGBA8; |
90 | int samples = 1; |
91 | bool autoRenderTarget = true; |
92 | bool mirrorVertically = false; |
93 | bool blend = false; |
94 | int fixedTextureWidth = 0; |
95 | int fixedTextureHeight = 0; |
96 | QSize effectiveTextureSize; |
97 | }; |
98 | |
99 | QT_END_NAMESPACE |
100 | |
101 | #endif |
102 | |