1 | // Copyright (C) 2016 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 QSGRENDERER_P_H |
5 | #define QSGRENDERER_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 "qsgabstractrenderer_p_p.h" |
19 | #include "qsgnode.h" |
20 | #include "qsgmaterial.h" |
21 | |
22 | #include <QtQuick/private/qsgcontext_p.h> |
23 | |
24 | QT_BEGIN_NAMESPACE |
25 | |
26 | class QSGNodeUpdater; |
27 | class QRhiRenderTarget; |
28 | class QRhiCommandBuffer; |
29 | class QRhiRenderPassDescriptor; |
30 | class QRhiResourceUpdateBatch; |
31 | |
32 | Q_QUICK_EXPORT bool qsg_test_and_clear_fatal_render_error(); |
33 | Q_QUICK_EXPORT void qsg_set_fatal_renderer_error(); |
34 | |
35 | class Q_QUICK_EXPORT QSGRenderTarget |
36 | { |
37 | public: |
38 | QSGRenderTarget() { } |
39 | |
40 | QSGRenderTarget(QRhiRenderTarget *rt, |
41 | QRhiRenderPassDescriptor *rpDesc, |
42 | QRhiCommandBuffer *cb) |
43 | : rt(rt), rpDesc(rpDesc), cb(cb) { } |
44 | |
45 | explicit QSGRenderTarget(QPaintDevice *paintDevice) |
46 | : paintDevice(paintDevice) { } |
47 | |
48 | QRhiRenderTarget *rt = nullptr; |
49 | // Store the rp descriptor obj separately, it can (even if often it won't) |
50 | // be different from rt->renderPassDescriptor(); e.g. one user is the 2D |
51 | // integration in Quick 3D which will use a different, but compatible rp. |
52 | QRhiRenderPassDescriptor *rpDesc = nullptr; |
53 | QRhiCommandBuffer *cb = nullptr; |
54 | |
55 | QPaintDevice *paintDevice = nullptr; |
56 | |
57 | int multiViewCount = 0; |
58 | }; |
59 | |
60 | class Q_QUICK_EXPORT QSGRenderer : public QSGAbstractRenderer |
61 | { |
62 | public: |
63 | QSGRenderer(QSGRenderContext *context); |
64 | virtual ~QSGRenderer(); |
65 | |
66 | // Accessed by QSGMaterial[Rhi]Shader::RenderState. |
67 | QMatrix4x4 currentProjectionMatrix(int index) const { return m_current_projection_matrix[index]; } |
68 | QMatrix4x4 currentModelViewMatrix() const { return m_current_model_view_matrix; } |
69 | QMatrix4x4 currentCombinedMatrix(int index) const { return m_current_projection_matrix[index] * m_current_model_view_matrix; } |
70 | qreal currentOpacity() const { return m_current_opacity; } |
71 | qreal determinant() const { return m_current_determinant; } |
72 | |
73 | void setDevicePixelRatio(qreal ratio) { m_device_pixel_ratio = ratio; } |
74 | qreal devicePixelRatio() const { return m_device_pixel_ratio; } |
75 | QSGRenderContext *context() const { return m_context; } |
76 | |
77 | bool isMirrored() const; |
78 | void renderScene() override; |
79 | void prepareSceneInline() override; |
80 | void renderSceneInline() override; |
81 | void nodeChanged(QSGNode *node, QSGNode::DirtyState state) override; |
82 | |
83 | QSGNodeUpdater *nodeUpdater() const; |
84 | void setNodeUpdater(QSGNodeUpdater *updater); |
85 | inline QSGMaterialShader::RenderState state(QSGMaterialShader::RenderState::DirtyStates dirty) const; |
86 | virtual void setVisualizationMode(const QByteArray &) { } |
87 | virtual bool hasVisualizationModeWithContinuousUpdate() const { return false; } |
88 | virtual void releaseCachedResources() { } |
89 | |
90 | void clearChangedFlag() { m_changed_emitted = false; } |
91 | |
92 | // Accessed by QSGMaterialShader::RenderState. |
93 | QByteArray *currentUniformData() const { return m_current_uniform_data; } |
94 | QRhiResourceUpdateBatch *currentResourceUpdateBatch() const { return m_current_resource_update_batch; } |
95 | QRhi *currentRhi() const { return m_rhi; } |
96 | |
97 | void setRenderTarget(const QSGRenderTarget &rt) { m_rt = rt; } |
98 | const QSGRenderTarget &renderTarget() const { return m_rt; } |
99 | |
100 | void setRenderPassRecordingCallbacks(QSGRenderContext::RenderPassCallback start, |
101 | QSGRenderContext::RenderPassCallback end, |
102 | void *userData) |
103 | { |
104 | m_renderPassRecordingCallbacks.start = start; |
105 | m_renderPassRecordingCallbacks.end = end; |
106 | m_renderPassRecordingCallbacks.userData = userData; |
107 | } |
108 | |
109 | protected: |
110 | virtual void render() = 0; |
111 | |
112 | virtual void prepareInline(); |
113 | virtual void renderInline(); |
114 | |
115 | virtual void preprocess(); |
116 | |
117 | void addNodesToPreprocess(QSGNode *node); |
118 | void removeNodesToPreprocess(QSGNode *node); |
119 | |
120 | QVarLengthArray<QMatrix4x4, 1> m_current_projection_matrix; // includes adjustment, where applicable, so can be treated as Y up in NDC always |
121 | QVarLengthArray<QMatrix4x4, 1> m_current_projection_matrix_native_ndc; // Vulkan has Y down in normalized device coordinates, others Y up... |
122 | QMatrix4x4 m_current_model_view_matrix; |
123 | qreal m_current_opacity; |
124 | qreal m_current_determinant; |
125 | qreal m_device_pixel_ratio; |
126 | |
127 | QSGRenderContext *m_context; |
128 | |
129 | QByteArray *m_current_uniform_data; |
130 | QRhiResourceUpdateBatch *m_current_resource_update_batch; |
131 | QRhi *m_rhi; |
132 | QSGRenderTarget m_rt; |
133 | struct { |
134 | QSGRenderContext::RenderPassCallback start = nullptr; |
135 | QSGRenderContext::RenderPassCallback end = nullptr; |
136 | void *userData = nullptr; |
137 | } m_renderPassRecordingCallbacks; |
138 | |
139 | private: |
140 | QSGNodeUpdater *m_node_updater; |
141 | |
142 | QSet<QSGNode *> m_nodes_to_preprocess; |
143 | QSet<QSGNode *> m_nodes_dont_preprocess; |
144 | |
145 | uint m_changed_emitted : 1; |
146 | uint m_is_rendering : 1; |
147 | uint m_is_preprocessing : 1; |
148 | }; |
149 | |
150 | QSGMaterialShader::RenderState QSGRenderer::state(QSGMaterialShader::RenderState::DirtyStates dirty) const |
151 | { |
152 | QSGMaterialShader::RenderState s; |
153 | s.m_dirty = dirty; |
154 | s.m_data = this; |
155 | return s; |
156 | } |
157 | |
158 | |
159 | class Q_QUICK_EXPORT QSGNodeDumper : public QSGNodeVisitor { |
160 | |
161 | public: |
162 | static void dump(QSGNode *n); |
163 | |
164 | QSGNodeDumper() {} |
165 | void visitNode(QSGNode *n) override; |
166 | void visitChildren(QSGNode *n) override; |
167 | |
168 | private: |
169 | int m_indent = 0; |
170 | }; |
171 | |
172 | QT_END_NAMESPACE |
173 | |
174 | #endif |
175 |
Definitions
- QSGRenderTarget
- QSGRenderTarget
- QSGRenderTarget
- QSGRenderTarget
- QSGRenderer
- currentProjectionMatrix
- currentModelViewMatrix
- currentCombinedMatrix
- currentOpacity
- determinant
- setDevicePixelRatio
- devicePixelRatio
- context
- setVisualizationMode
- hasVisualizationModeWithContinuousUpdate
- releaseCachedResources
- clearChangedFlag
- currentUniformData
- currentResourceUpdateBatch
- currentRhi
- setRenderTarget
- renderTarget
- setRenderPassRecordingCallbacks
- state
- QSGNodeDumper
Start learning QML with our Intro Training
Find out more