1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtQuick module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QSGRENDERER_P_H
41#define QSGRENDERER_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include "qsgabstractrenderer.h"
55#include "qsgabstractrenderer_p.h"
56#include "qsgnode.h"
57#include "qsgmaterial.h"
58
59#include <QtQuick/private/qsgcontext_p.h>
60
61QT_BEGIN_NAMESPACE
62
63class QSGBindable;
64class QSGNodeUpdater;
65class QRhiRenderTarget;
66class QRhiCommandBuffer;
67class QRhiRenderPassDescriptor;
68class QRhiResourceUpdateBatch;
69
70Q_QUICK_PRIVATE_EXPORT bool qsg_test_and_clear_fatal_render_error();
71Q_QUICK_PRIVATE_EXPORT void qsg_set_fatal_renderer_error();
72
73class Q_QUICK_PRIVATE_EXPORT QSGRenderer : public QSGAbstractRenderer
74{
75public:
76 QSGRenderer(QSGRenderContext *context);
77 virtual ~QSGRenderer();
78
79 // Accessed by QSGMaterial[Rhi]Shader::RenderState.
80 QMatrix4x4 currentProjectionMatrix() const { return m_current_projection_matrix; }
81 QMatrix4x4 currentModelViewMatrix() const { return m_current_model_view_matrix; }
82 QMatrix4x4 currentCombinedMatrix() const { return m_current_projection_matrix * m_current_model_view_matrix; }
83 qreal currentOpacity() const { return m_current_opacity; }
84 qreal determinant() const { return m_current_determinant; }
85
86 void setDevicePixelRatio(qreal ratio) { m_device_pixel_ratio = ratio; }
87 qreal devicePixelRatio() const { return m_device_pixel_ratio; }
88 QSGRenderContext *context() const { return m_context; }
89
90 bool isMirrored() const;
91 void renderScene(const QSGBindable &bindable);
92 void renderScene(uint fboId = 0) override;
93 void nodeChanged(QSGNode *node, QSGNode::DirtyState state) override;
94
95 QSGNodeUpdater *nodeUpdater() const;
96 void setNodeUpdater(QSGNodeUpdater *updater);
97 inline QSGMaterialShader::RenderState state(QSGMaterialShader::RenderState::DirtyStates dirty) const;
98 inline QSGMaterialRhiShader::RenderState rhiState(QSGMaterialRhiShader::RenderState::DirtyStates dirty) const;
99 virtual void setCustomRenderMode(const QByteArray &) { }
100 virtual bool hasCustomRenderModeWithContinuousUpdate() const { return false; }
101 virtual void releaseCachedResources() { }
102
103 void clearChangedFlag() { m_changed_emitted = false; }
104
105 // Accessed by QSGMaterialRhiShader::RenderState.
106 QByteArray *currentUniformData() const { return m_current_uniform_data; }
107 QRhiResourceUpdateBatch *currentResourceUpdateBatch() const { return m_current_resource_update_batch; }
108 QRhi *currentRhi() const { return m_rhi; }
109
110 void setRenderTarget(QRhiRenderTarget *rt) { m_rt = rt; }
111 QRhiRenderTarget *renderTarget() const { return m_rt; }
112
113 void setCommandBuffer(QRhiCommandBuffer *cb) { m_cb = cb; }
114 QRhiCommandBuffer *commandBuffer() const { return m_cb; }
115
116 void setRenderPassDescriptor(QRhiRenderPassDescriptor *rpDesc) { m_rp_desc = rpDesc; }
117 QRhiRenderPassDescriptor *renderPassDescriptor() const { return m_rp_desc; }
118
119 void setRenderPassRecordingCallbacks(QSGRenderContext::RenderPassCallback start,
120 QSGRenderContext::RenderPassCallback end,
121 void *userData)
122 {
123 m_renderPassRecordingCallbacks.start = start;
124 m_renderPassRecordingCallbacks.end = end;
125 m_renderPassRecordingCallbacks.userData = userData;
126 }
127
128protected:
129 virtual void render() = 0;
130
131 const QSGBindable *bindable() const { return m_bindable; }
132
133 virtual void preprocess();
134
135 void addNodesToPreprocess(QSGNode *node);
136 void removeNodesToPreprocess(QSGNode *node);
137
138 QMatrix4x4 m_current_projection_matrix; // includes adjustment, where applicable, so can be treated as Y up in NDC always
139 QMatrix4x4 m_current_projection_matrix_native_ndc; // Vulkan has Y down in normalized device coordinates, others Y up...
140 QMatrix4x4 m_current_model_view_matrix;
141 qreal m_current_opacity;
142 qreal m_current_determinant;
143 qreal m_device_pixel_ratio;
144
145 QSGRenderContext *m_context;
146
147 QByteArray *m_current_uniform_data;
148 QRhiResourceUpdateBatch *m_current_resource_update_batch;
149 QRhi *m_rhi;
150 QRhiRenderTarget *m_rt;
151 QRhiCommandBuffer *m_cb;
152 QRhiRenderPassDescriptor *m_rp_desc;
153 struct {
154 QSGRenderContext::RenderPassCallback start = nullptr;
155 QSGRenderContext::RenderPassCallback end = nullptr;
156 void *userData = nullptr;
157 } m_renderPassRecordingCallbacks;
158
159private:
160 QSGNodeUpdater *m_node_updater;
161
162 QSet<QSGNode *> m_nodes_to_preprocess;
163 QSet<QSGNode *> m_nodes_dont_preprocess;
164
165 const QSGBindable *m_bindable;
166
167 uint m_changed_emitted : 1;
168 uint m_is_rendering : 1;
169 uint m_is_preprocessing : 1;
170};
171
172class Q_QUICK_PRIVATE_EXPORT QSGBindable
173{
174public:
175 virtual ~QSGBindable() { }
176 virtual void bind() const = 0;
177 virtual void clear(QSGAbstractRenderer::ClearMode mode) const;
178 virtual void reactivate() const;
179};
180#if QT_CONFIG(opengl)
181class QSGBindableFboId : public QSGBindable
182{
183public:
184 QSGBindableFboId(GLuint);
185 void bind() const override;
186private:
187 GLuint m_id;
188};
189#endif
190
191
192QSGMaterialShader::RenderState QSGRenderer::state(QSGMaterialShader::RenderState::DirtyStates dirty) const
193{
194 QSGMaterialShader::RenderState s;
195 s.m_dirty = dirty;
196 s.m_data = this;
197 return s;
198}
199
200QSGMaterialRhiShader::RenderState QSGRenderer::rhiState(QSGMaterialRhiShader::RenderState::DirtyStates dirty) const
201{
202 QSGMaterialRhiShader::RenderState s;
203 s.m_dirty = dirty;
204 s.m_data = this;
205 return s;
206}
207
208
209class Q_QUICK_PRIVATE_EXPORT QSGNodeDumper : public QSGNodeVisitor {
210
211public:
212 static void dump(QSGNode *n);
213
214 QSGNodeDumper() {}
215 void visitNode(QSGNode *n) override;
216 void visitChildren(QSGNode *n) override;
217
218private:
219 int m_indent = 0;
220};
221
222
223
224QT_END_NAMESPACE
225
226#endif
227

source code of qtdeclarative/src/quick/scenegraph/coreapi/qsgrenderer_p.h