Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsgabstractrenderer.cpp
Go to the documentation of this file.
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// Qt-Security score:significant reason:default
4
6
8
9/*!
10 \class QSGAbstractRenderer
11 \brief QSGAbstractRenderer gives access to the scene graph nodes and rendering.
12 \inmodule QtQuick
13 \since 5.4
14 \internal
15 */
16
17/*!
18 \enum QSGAbstractRenderer::MatrixTransformFlag
19
20 Used with setProjectionMatrixToRect() to indicate the expectations towards
21 the generated projection matrix.
22
23 \value MatrixTransformFlipY The traditional assumption in Qt Quick is that
24 Y points up in the normalized device coordinate system. There is at least
25 one modern graphics API where this is not the case (Vulkan). This flag can
26 then be used to get a projection that is appropriate for such an API.
27
28 \sa setProjectionMatrixToRect()
29
30 \since 5.14
31 */
32
33/*!
34 \fn void QSGAbstractRenderer::renderScene()
35
36 Renders the scene.
37 */
38
39/*!
40 \fn void QSGAbstractRenderer::sceneGraphChanged()
41
42 This signal is emitted on the first modification of a node in
43 the tree after the last scene render.
44 */
45
46/*!
47 \internal
48 */
49QSGAbstractRendererPrivate::QSGAbstractRendererPrivate()
50 : m_root_node(nullptr)
51 , m_clear_color(Qt::transparent)
52 , m_invertFrontFace(false)
53{
54 m_projection_matrix.resize(1);
55 m_projection_matrix_native_ndc.resize(1);
56}
57
58/*!
59 \internal
60 */
61QSGAbstractRenderer::QSGAbstractRenderer(QObject *parent)
62 : QObject(*new QSGAbstractRendererPrivate, parent)
63{
64}
65
66/*!
67 \internal
68 */
69QSGAbstractRenderer::~QSGAbstractRenderer()
70{
71}
72
73/*!
74 Sets the \a node as the root of the QSGNode scene
75 that you want to render. You need to provide a \a node
76 before trying to render the scene.
77
78 \note This doesn't take ownership of \a node.
79
80 \sa rootNode()
81*/
82void QSGAbstractRenderer::setRootNode(QSGRootNode *node)
83{
84 Q_D(QSGAbstractRenderer);
85 if (d->m_root_node == node)
86 return;
87 if (d->m_root_node) {
88 d->m_root_node->m_renderers.removeOne(this);
89 nodeChanged(d->m_root_node, QSGNode::DirtyNodeRemoved);
90 }
91 d->m_root_node = node;
92 if (d->m_root_node) {
93 Q_ASSERT(!d->m_root_node->m_renderers.contains(this));
94 d->m_root_node->m_renderers << this;
95 nodeChanged(d->m_root_node, QSGNode::DirtyNodeAdded);
96 }
97}
98
99/*!
100 Returns the root of the QSGNode scene.
101
102 \sa setRootNode()
103*/
104QSGRootNode *QSGAbstractRenderer::rootNode() const
105{
106 Q_D(const QSGAbstractRenderer);
107 return d->m_root_node;
108}
109
110
111/*!
112 \fn void QSGAbstractRenderer::setDeviceRect(const QSize &size)
113 \overload
114
115 Sets the \a size of the surface being rendered to.
116
117 \sa deviceRect()
118 */
119
120/*!
121 Sets \a rect as the geometry of the surface being rendered to.
122
123 \sa deviceRect()
124 */
125void QSGAbstractRenderer::setDeviceRect(const QRect &rect)
126{
127 Q_D(QSGAbstractRenderer);
128 d->m_device_rect = rect;
129}
130
131/*!
132 Returns the device rect of the surface being rendered to.
133
134 \sa setDeviceRect()
135 */
136QRect QSGAbstractRenderer::deviceRect() const
137{
138 Q_D(const QSGAbstractRenderer);
139 return d->m_device_rect;
140}
141
142/*!
143 \fn void QSGAbstractRenderer::setViewportRect(const QSize &size)
144 \overload
145
146 Sets the \a size of the viewport to render
147 on the surface.
148
149 \sa viewportRect()
150 */
151
152/*!
153 Sets \a rect as the geometry of the viewport to render
154 on the surface.
155
156 \sa viewportRect()
157 */
158void QSGAbstractRenderer::setViewportRect(const QRect &rect)
159{
160 Q_D(QSGAbstractRenderer);
161 d->m_viewport_rect = rect;
162}
163
164/*!
165 Returns the rect of the viewport to render.
166
167 \sa setViewportRect()
168 */
169QRect QSGAbstractRenderer::viewportRect() const
170{
171 Q_D(const QSGAbstractRenderer);
172 return d->m_viewport_rect;
173}
174
175/*!
176 Convenience method that calls setProjectionMatrix() with an
177 orthographic matrix generated from \a rect.
178
179 \note This function assumes that the graphics API uses Y up in its
180 normalized device coordinate system.
181
182 \sa setProjectionMatrix(), projectionMatrix()
183 */
184void QSGAbstractRenderer::setProjectionMatrixToRect(const QRectF &rect)
185{
186 setProjectionMatrixToRect(rect, {}, false);
187}
188
189/*!
190 Convenience method that calls setProjectionMatrix() with an
191 orthographic matrix generated from \a rect.
192
193 Set MatrixTransformFlipY in \a flags when the graphics API uses Y down in
194 its normalized device coordinate system (for example, Vulkan).
195
196 \sa setProjectionMatrix(), projectionMatrix()
197
198 \since 5.14
199 */
200void QSGAbstractRenderer::setProjectionMatrixToRect(const QRectF &rect, MatrixTransformFlags flags)
201{
202 setProjectionMatrixToRect(rect, flags, flags.testFlag(MatrixTransformFlipY));
203}
204
205/*!
206 Convenience method that calls setProjectionMatrix() with an
207 orthographic matrix generated from \a rect.
208
209 Set MatrixTransformFlipY in \a flags when the graphics API uses Y down in
210 its normalized device coordinate system (for example, Vulkan).
211
212 Convenience method that calls setProjectionMatrixWithNativeNDC() with an
213 orthographic matrix generated from \a rect.
214
215 Set true to \a nativeNDCFlipY to flip the Y axis relative to
216 projection matrix in its normalized device coordinate system.
217
218 \sa setProjectionMatrix(), projectionMatrix()
219 \sa setProjectionMatrixWithNativeNDC(), projectionMatrixWithNativeNDC()
220
221 \since 6.7
222 */
223void QSGAbstractRenderer::setProjectionMatrixToRect(const QRectF &rect, MatrixTransformFlags flags,
224 bool nativeNDCFlipY)
225{
226 const bool flipY = flags.testFlag(MatrixTransformFlipY);
227
228 const float left = rect.x();
229 const float right = rect.x() + rect.width();
230 float bottom = rect.y() + rect.height();
231 float top = rect.y();
232
233 if (flipY)
234 std::swap(top, bottom);
235
236 QMatrix4x4 matrix;
237 matrix.ortho(left, right, bottom, top, 1, -1);
238 setProjectionMatrix(matrix, 0);
239
240 if (nativeNDCFlipY) {
241 std::swap(top, bottom);
242
243 matrix.setToIdentity();
244 matrix.ortho(left, right, bottom, top, 1, -1);
245 }
246 setProjectionMatrixWithNativeNDC(matrix, 0);
247}
248
249/*!
250 Use \a matrix to project the QSGNode coordinates onto surface pixels.
251
252 \a index specifies the view index when multiview rendering is in use.
253
254 \sa projectionMatrix(), setProjectionMatrixToRect()
255 */
256void QSGAbstractRenderer::setProjectionMatrix(const QMatrix4x4 &matrix, int index)
257{
258 Q_D(QSGAbstractRenderer);
259 if (d->m_projection_matrix.count() <= index)
260 d->m_projection_matrix.resize(index + 1);
261 d->m_projection_matrix[index] = matrix;
262}
263
264/*!
265 \internal
266 */
267void QSGAbstractRenderer::setProjectionMatrixWithNativeNDC(const QMatrix4x4 &matrix, int index)
268{
269 Q_D(QSGAbstractRenderer);
270 if (d->m_projection_matrix_native_ndc.count() <= index)
271 d->m_projection_matrix_native_ndc.resize(index + 1);
272 d->m_projection_matrix_native_ndc[index] = matrix;
273}
274
275/*!
276 Returns the projection matrix
277
278 \sa setProjectionMatrix(), setProjectionMatrixToRect()
279 */
280QMatrix4x4 QSGAbstractRenderer::projectionMatrix(int index) const
281{
282 Q_D(const QSGAbstractRenderer);
283 return d->m_projection_matrix[index];
284}
285
286int QSGAbstractRenderer::projectionMatrixCount() const
287{
288 Q_D(const QSGAbstractRenderer);
289 return d->m_projection_matrix.count();
290}
291
292int QSGAbstractRenderer::projectionMatrixWithNativeNDCCount() const
293{
294 Q_D(const QSGAbstractRenderer);
295 return d->m_projection_matrix_native_ndc.count();
296}
297
298/*!
299 \internal
300 */
301QMatrix4x4 QSGAbstractRenderer::projectionMatrixWithNativeNDC(int index) const
302{
303 Q_D(const QSGAbstractRenderer);
304 return d->m_projection_matrix_native_ndc[index];
305}
306
307/*!
308 \internal
309 */
310void QSGAbstractRenderer::setInvertFrontFace(bool invert)
311{
312 Q_D(QSGAbstractRenderer);
313 d->m_invertFrontFace = invert;
314}
315
316/*!
317 \internal
318 */
319bool QSGAbstractRenderer::invertFrontFace() const
320{
321 Q_D(const QSGAbstractRenderer);
322 return d->m_invertFrontFace;
323}
324
325/*!
326 Sets the \a color to clear the framebuffer.
327
328 \sa clearColor()
329 */
330void QSGAbstractRenderer::setClearColor(const QColor &color)
331{
332 Q_D(QSGAbstractRenderer);
333 d->m_clear_color = color;
334}
335
336/*!
337 Returns the color that clears the framebuffer at the beginning
338 of the rendering.
339
340 \sa setClearColor()
341 */
342QColor QSGAbstractRenderer::clearColor() const
343{
344 Q_D(const QSGAbstractRenderer);
345 return d->m_clear_color;
346}
347
348/*!
349 \fn void QSGAbstractRenderer::nodeChanged(QSGNode *node, QSGNode::DirtyState state)
350 \internal
351 */
352
353void QSGAbstractRenderer::prepareSceneInline()
354{
355}
356
357void QSGAbstractRenderer::renderSceneInline()
358{
359}
360
361QT_END_NAMESPACE
362
363#include "moc_qsgabstractrenderer_p.cpp"
Combined button and popup list for selecting options.