Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qsgnode.h
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
4#ifndef QSGNODE_H
5#define QSGNODE_H
6
7#include <QtCore/qlist.h>
8#include <QtQuick/qsggeometry.h>
9#include <QtGui/QMatrix4x4>
10
11#include <float.h>
12
14
15#ifndef QT_NO_DEBUG
16#define QSG_RUNTIME_DESCRIPTION
17#endif
18
20class QSGRenderer;
21
22class QSGNode;
23class QSGRootNode;
24class QSGGeometryNode;
26class QSGClipNode;
27class QSGNodePrivate;
30
31namespace QSGBatchRenderer {
32 class Renderer;
33 class Updater;
34}
35
36class Q_QUICK_EXPORT QSGNode
37{
38public:
39 enum NodeType {
46 RenderNodeType
47 };
48
49 enum Flag {
50 // Lower 16 bites reserved for general node
51 OwnedByParent = 0x0001,
52 UsePreprocess = 0x0002,
53
54 // 0x00ff0000 bits reserved for node subclasses
55
56 // QSGBasicGeometryNode
57 OwnsGeometry = 0x00010000,
58 OwnsMaterial = 0x00020000,
59 OwnsOpaqueMaterial = 0x00040000,
60
61 // Uppermost 8 bits are reserved for internal use.
62 IsVisitableNode = 0x01000000
63#ifdef Q_QDOC
64 , InternalReserved = 0x01000000
65#endif
66 };
68
70 DirtySubtreeBlocked = 0x0080,
71 DirtyMatrix = 0x0100,
72 DirtyNodeAdded = 0x0400,
73 DirtyNodeRemoved = 0x0800,
74 DirtyGeometry = 0x1000,
75 DirtyMaterial = 0x2000,
76 DirtyOpacity = 0x4000,
77
78 DirtyForceUpdate = 0x8000,
79
80 DirtyUsePreprocess = UsePreprocess,
81
82 DirtyPropagationMask = DirtyMatrix
83 | DirtyNodeAdded
84 | DirtyOpacity
85 | DirtyForceUpdate
86
87 };
88 Q_DECLARE_FLAGS(DirtyState, DirtyStateBit)
89
90 QSGNode();
91 virtual ~QSGNode();
92
93 QSGNode *parent() const { return m_parent; }
94
95 void removeChildNode(QSGNode *node);
96 void removeAllChildNodes();
97 void prependChildNode(QSGNode *node);
98 void appendChildNode(QSGNode *node);
99 void insertChildNodeBefore(QSGNode *node, QSGNode *before);
100 void insertChildNodeAfter(QSGNode *node, QSGNode *after);
101 void reparentChildNodesTo(QSGNode *newParent);
102
103 int childCount() const;
104 QSGNode *childAtIndex(int i) const;
105 QSGNode *firstChild() const { return m_firstChild; }
106 QSGNode *lastChild() const { return m_lastChild; }
107 QSGNode *nextSibling() const { return m_nextSibling; }
108 QSGNode* previousSibling() const { return m_previousSibling; }
109
110 inline NodeType type() const { return m_type; }
111
113 void markDirty(DirtyState bits);
114 QT_DEPRECATED DirtyState dirtyState() const { return { }; }
115
116 virtual bool isSubtreeBlocked() const;
117
118 Flags flags() const { return m_nodeFlags; }
119 void setFlag(Flag, bool = true);
120 void setFlags(Flags, bool = true);
121
122 virtual void preprocess() { }
123
124protected:
125 QSGNode(NodeType type);
126 QSGNode(QSGNodePrivate &dd, NodeType type);
127
128private:
129 friend class QSGRootNode;
131 friend class QSGRenderer;
132
133 void init();
134 void destroy();
135
136 QSGNode *m_parent = nullptr;
137 NodeType m_type = BasicNodeType;
138 QSGNode *m_firstChild = nullptr;
139 QSGNode *m_lastChild = nullptr;
140 QSGNode *m_nextSibling = nullptr;
141 QSGNode *m_previousSibling = nullptr;
142 int m_subtreeRenderableCount = 0;
143
144 Flags m_nodeFlags;
145
146protected:
147 friend class QSGNodePrivate;
148
150};
151
152void Q_QUICK_EXPORT qsgnode_set_description(QSGNode *node, const QString &description);
153
154class Q_QUICK_EXPORT QSGBasicGeometryNode : public QSGNode
155{
156public:
157 ~QSGBasicGeometryNode() override;
158
159 void setGeometry(QSGGeometry *geometry);
160 const QSGGeometry *geometry() const { return m_geometry; }
161 QSGGeometry *geometry() { return m_geometry; }
162
163 const QMatrix4x4 *matrix() const { return m_matrix; }
164 const QSGClipNode *clipList() const { return m_clip_list; }
165
166 void setRendererMatrix(const QMatrix4x4 *m) { m_matrix = m; }
167 void setRendererClipList(const QSGClipNode *c) { m_clip_list = c; }
168
169protected:
170 QSGBasicGeometryNode(NodeType type);
172
173private:
174 friend class QSGNodeUpdater;
175
176 QSGGeometry *m_geometry;
177
179 QT_WARNING_DISABLE_GCC("-Wattributes")
180 [[maybe_unused]] int m_reserved_start_index;
181 [[maybe_unused]] int m_reserved_end_index;
183
184 const QMatrix4x4 *m_matrix;
185 const QSGClipNode *m_clip_list;
186};
187
188class QSGMaterial;
189
190class Q_QUICK_EXPORT QSGGeometryNode : public QSGBasicGeometryNode
191{
192public:
194 ~QSGGeometryNode() override;
195
196 void setMaterial(QSGMaterial *material);
197 QSGMaterial *material() const { return m_material; }
198
199 void setOpaqueMaterial(QSGMaterial *material);
200 QSGMaterial *opaqueMaterial() const { return m_opaque_material; }
201
202 QSGMaterial *activeMaterial() const;
203
204 void setRenderOrder(int order);
205 int renderOrder() const { return m_render_order; }
206
207 void setInheritedOpacity(qreal opacity);
208 qreal inheritedOpacity() const { return m_opacity; }
209
210protected:
212
213private:
214 friend class QSGNodeUpdater;
215
216 int m_render_order = 0;
217 QSGMaterial *m_material = nullptr;
218 QSGMaterial *m_opaque_material = nullptr;
219
220 qreal m_opacity = 1;
221};
222
223class Q_QUICK_EXPORT QSGClipNode : public QSGBasicGeometryNode
224{
225public:
226 QSGClipNode();
227 ~QSGClipNode() override;
228
229 void setIsRectangular(bool rectHint);
230 bool isRectangular() const { return m_is_rectangular; }
231
232 void setClipRect(const QRectF &);
233 QRectF clipRect() const { return m_clip_rect; }
234
235private:
236 uint m_is_rectangular : 1;
237 uint m_reserved : 31;
238
239 QRectF m_clip_rect;
240};
241
242
243class Q_QUICK_EXPORT QSGTransformNode : public QSGNode
244{
245public:
247 ~QSGTransformNode() override;
248
249 void setMatrix(const QMatrix4x4 &matrix);
250 const QMatrix4x4 &matrix() const { return m_matrix; }
251
252 void setCombinedMatrix(const QMatrix4x4 &matrix);
253 const QMatrix4x4 &combinedMatrix() const { return m_combined_matrix; }
254
255private:
256 QMatrix4x4 m_matrix;
257 QMatrix4x4 m_combined_matrix;
258};
259
260
261class Q_QUICK_EXPORT QSGRootNode : public QSGNode
262{
263public:
264 QSGRootNode();
265 ~QSGRootNode() override;
266
267private:
268 void notifyNodeChange(QSGNode *node, DirtyState state);
269
271 friend class QSGNode;
272 friend class QSGGeometryNode;
273
275};
276
277
278class Q_QUICK_EXPORT QSGOpacityNode : public QSGNode
279{
280public:
282 ~QSGOpacityNode() override;
283
284 void setOpacity(qreal opacity);
285 qreal opacity() const { return m_opacity; }
286
287 void setCombinedOpacity(qreal opacity);
288 qreal combinedOpacity() const { return m_combined_opacity; }
289
290 bool isSubtreeBlocked() const override;
291
292private:
293 qreal m_opacity = 1;
294 qreal m_combined_opacity = 1;
295};
296
297class Q_QUICK_EXPORT QSGNodeVisitor {
298public:
299 virtual ~QSGNodeVisitor();
300
301protected:
304 virtual void enterClipNode(QSGClipNode *) {}
305 virtual void leaveClipNode(QSGClipNode *) {}
310 virtual void visitNode(QSGNode *n);
311 virtual void visitChildren(QSGNode *n);
312};
313
314#ifndef QT_NO_DEBUG_STREAM
315Q_QUICK_EXPORT QDebug operator<<(QDebug, const QSGNode *n);
316Q_QUICK_EXPORT QDebug operator<<(QDebug, const QSGGeometryNode *n);
317Q_QUICK_EXPORT QDebug operator<<(QDebug, const QSGTransformNode *n);
318Q_QUICK_EXPORT QDebug operator<<(QDebug, const QSGOpacityNode *n);
319Q_QUICK_EXPORT QDebug operator<<(QDebug, const QSGRootNode *n);
320
321#endif
322
323Q_DECLARE_OPERATORS_FOR_FLAGS(QSGNode::DirtyState)
324Q_DECLARE_OPERATORS_FOR_FLAGS(QSGNode::Flags)
325
327
328#endif // QSGNODE_H
\inmodule QtCore
Definition qlist.h:74
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition qmatrix4x4.h:25
\inmodule QtCore\reentrant
Definition qrect.h:483
QSGAbstractRenderer gives access to the scene graph nodes and rendering.
The QSGBasicGeometryNode class serves as a baseclass for geometry based nodes.
Definition qsgnode.h:155
const QSGClipNode * clipList() const
Will be set during rendering to contain the clip of the geometry for that rendering pass.
Definition qsgnode.h:164
const QSGGeometry * geometry() const
Returns this node's geometry.
Definition qsgnode.h:160
QSGGeometry * geometry()
Returns this node's geometry.
Definition qsgnode.h:161
void setRendererClipList(const QSGClipNode *c)
Definition qsgnode.h:167
void setRendererMatrix(const QMatrix4x4 *m)
Definition qsgnode.h:166
const QMatrix4x4 * matrix() const
Will be set during rendering to contain transformation of the geometry for that rendering pass.
Definition qsgnode.h:163
The QSGClipNode class implements the clipping functionality in the scene graph.
Definition qsgnode.h:224
bool isRectangular() const
Returns if this clip node has a rectangular clip.
Definition qsgnode.h:230
QRectF clipRect() const
Returns the clip rect of this node.
Definition qsgnode.h:233
The QSGGeometryNode class is used for all rendered content in the scene graph.
Definition qsgnode.h:191
qreal inheritedOpacity() const
Set during rendering to specify the inherited opacity for that rendering pass.
Definition qsgnode.h:208
QSGMaterial * opaqueMaterial() const
Returns the opaque material of the QSGGeometryNode.
Definition qsgnode.h:200
QSGMaterial * material() const
Returns the material of the QSGGeometryNode.
Definition qsgnode.h:197
int renderOrder() const
Returns the render order of this geometry node.
Definition qsgnode.h:205
The QSGGeometry class provides low-level storage for graphics primitives in the \l{Qt Quick Scene Gra...
Definition qsggeometry.h:15
The QSGMaterial class encapsulates rendering state for a shader program.
Definition qsgmaterial.h:15
static QString description(const QSGNode *node)
Definition qsgnode_p.h:34
The QSGNodeVisitor class is a helper class for traversing the scene graph.
Definition qsgnode.h:297
virtual void enterOpacityNode(QSGOpacityNode *)
Definition qsgnode.h:308
virtual void leaveGeometryNode(QSGGeometryNode *)
Definition qsgnode.h:307
virtual void enterTransformNode(QSGTransformNode *)
Definition qsgnode.h:302
virtual void leaveTransformNode(QSGTransformNode *)
Definition qsgnode.h:303
virtual void leaveOpacityNode(QSGOpacityNode *)
Definition qsgnode.h:309
virtual void leaveClipNode(QSGClipNode *)
Definition qsgnode.h:305
virtual void enterClipNode(QSGClipNode *)
Definition qsgnode.h:304
virtual void enterGeometryNode(QSGGeometryNode *)
Definition qsgnode.h:306
\group qtquick-scenegraph-nodes \title Qt Quick Scene Graph Node classes
Definition qsgnode.h:37
QSGNode * nextSibling() const
Returns the node after this in the parent's list of children.
Definition qsgnode.h:107
Flags flags() const
Returns the set of flags for this node.
Definition qsgnode.h:118
DirtyStateBit
Used in QSGNode::markDirty() to indicate how the scene graph has changed.
Definition qsgnode.h:69
QSGNode * previousSibling() const
Returns the node before this in the parent's list of children.
Definition qsgnode.h:108
Flag
The QSGNode::Flag enum describes flags on the QSGNode.
Definition qsgnode.h:49
QT_DEPRECATED DirtyState dirtyState() const
Definition qsgnode.h:114
QSGNode * lastChild() const
Returns the last child of this node.
Definition qsgnode.h:106
NodeType
Can be used to figure out the type of node.
Definition qsgnode.h:39
@ BasicNodeType
Definition qsgnode.h:40
@ TransformNodeType
Definition qsgnode.h:42
@ RootNodeType
Definition qsgnode.h:45
@ GeometryNodeType
Definition qsgnode.h:41
@ ClipNodeType
Definition qsgnode.h:43
@ OpacityNodeType
Definition qsgnode.h:44
QSGNode * parent() const
Returns the parent node of this node.
Definition qsgnode.h:93
QSGNode * firstChild() const
Returns the first child of this node.
Definition qsgnode.h:105
NodeType type() const
Returns the type of this node.
Definition qsgnode.h:110
QT_DEPRECATED void clearDirty()
Definition qsgnode.h:112
virtual void preprocess()
Override this function to do processing on the node before it is rendered.
Definition qsgnode.h:122
QScopedPointer< QSGNodePrivate > d_ptr
Definition qsgnode.h:149
The QSGOpacityNode class is used to change opacity of nodes.
Definition qsgnode.h:279
qreal opacity() const
Returns this opacity node's opacity.
Definition qsgnode.h:285
qreal combinedOpacity() const
Returns this node's accumulated opacity.
Definition qsgnode.h:288
The renderer class is the abstract baseclass used for rendering the QML scene graph.
The QSGRootNode is the toplevel root of any scene graph.
Definition qsgnode.h:262
The QSGTransformNode class implements transformations in the scene graph.
Definition qsgnode.h:244
const QMatrix4x4 & combinedMatrix() const
Set during rendering to the combination of all parent matrices for that rendering pass.
Definition qsgnode.h:253
const QMatrix4x4 & matrix() const
Returns this transform node's matrix.
Definition qsgnode.h:250
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
else opt state
[0]
Combined button and popup list for selecting options.
#define QT_WARNING_POP
#define QT_WARNING_DISABLE_GCC(text)
#define QT_WARNING_PUSH
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition qflags.h:174
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
Definition qflags.h:194
Flags
const GLfloat * m
GLenum type
GLfloat n
const GLubyte * c
GLuint GLenum matrix
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const void * bits
GLfixed GLfixed GLint GLint order
void Q_QUICK_EXPORT qsgnode_set_description(QSGNode *node, const QString &description)
Definition qsgnode.cpp:639
Q_QUICK_EXPORT QDebug operator<<(QDebug, const QSGNode *n)
Definition qsgnode.cpp:1554
#define QT_DEPRECATED
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
unsigned int uint
Definition qtypes.h:29
double qreal
Definition qtypes.h:92