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
qssgrendernode_p.h
Go to the documentation of this file.
1// Copyright (C) 2008-2012 NVIDIA Corporation.
2// Copyright (C) 2019 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
4// Qt-Security score:significant reason:default
5
6
7#ifndef QSSG_RENDER_NODE_H
8#define QSSG_RENDER_NODE_H
9
10//
11// W A R N I N G
12// -------------
13//
14// This file is not part of the Qt API. It exists purely as an
15// implementation detail. This header file may change from version to
16// version without notice, or even be removed.
17//
18// We mean it.
19//
20
21#include <QtQuick3DRuntimeRender/private/qssgrendergraphobject_p.h>
22
23#include <QtQuick3DUtils/private/qssgutils_p.h>
24#include <QtQuick3DUtils/private/qssgbounds3_p.h>
25#include <QtQuick3DUtils/private/qssginvasivelinkedlist_p.h>
26
27#include <QtGui/QMatrix4x4>
28#include <QtGui/qquaternion.h>
29#include <QtGui/QVector3D>
30
31QT_BEGIN_NAMESPACE
32
33struct QSSGRenderModel;
34struct QSSGRenderLight;
35class QSSGRenderCamera;
36struct QSSGRenderText;
37struct QSSGRenderNode;
38class QSSGBufferManager;
40class QSSGRenderRoot;
41
42struct Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRenderNode : public QSSGRenderGraphObject
43{
44 enum class LocalState : quint8
45 {
46 Active = 1 << 0,
47 Pickable = 1 << 1,
48 Imported = 1 << 2,
49 };
50
51 enum class GlobalState : quint8
52 {
53 Active = 1 << 3,
54 Pickable = 1 << 4,
55 Imported = 1 << 5,
56 };
57
58 enum class DirtyFlag : quint32
59 {
60 TransformDirty = 1 << 6,
61 OpacityDirty = 1 << 7,
62 ActiveDirty = 1 << 8,
63 PickableDirty = 1 << 9,
64 TagDirty = 1 << 10,
65 ImportDirty = 1 << 11,
66 SubNodeDirty = 1 << 12, // Sub-nodes should set/unest this if they "extend" the dirty flags provided by the node
67 StickyDirty = 1 << 13, // Sticky flag (Only used by import scenes.)
68
69 GlobalValuesDirty = TransformDirty | OpacityDirty | ActiveDirty | PickableDirty | ImportDirty,
70 SubtreeUpdateMask = GlobalValuesDirty | StickyDirty,
71 DirtyMask = GlobalValuesDirty | SubNodeDirty
72 };
73 using FlagT = std::underlying_type_t<DirtyFlag>;
74
75 static constexpr QVector3D initScale { 1.0f, 1.0f, 1.0f };
76
77 // changing any one of these means you have to
78 // set this object dirty
79 QVector3D pivot;
80 int staticFlags = 0;
81
82 // This only sets dirty, not transform dirty
83 // Opacity of 1 means opaque, opacity of zero means transparent.
84 float localOpacity = 1.0f;
85
86 // Nodes are initially dirty and locally active!
87 FlagT flags { FlagT(DirtyFlag::GlobalValuesDirty) | FlagT(LocalState::Active) };
88 // These end up right handed
89 QMatrix4x4 localTransform;
90
91 // node graph members.
92 QSSGRenderRoot **rootNodeRef = nullptr;
93 QSSGRenderNode *parent = nullptr;
94 QSSGRenderNode *nextSibling = nullptr;
95 QSSGRenderNode *previousSibling = nullptr;
96 QSSGRenderNode *instanceRoot = nullptr;
97
98 // Handle(s) to the render data.
99 QSSGRenderNodeHandle h;
100 QSSGRenderNodeTag tag;
101
102 using ChildList = QSSGInvasiveLinkedList<QSSGRenderNode, &QSSGRenderNode::previousSibling, &QSSGRenderNode::nextSibling>;
103 ChildList children;
104
105 QString debugObjectName;
106
107 QSSGRenderNode();
108 QSSGRenderNode(Type type, FlagT flags = 0);
109 ~QSSGRenderNode() override;
110
111 // Sets this object dirty and walks down the graph setting all
112 // children who are not dirty to be dirty.
113 void markDirty(DirtyFlag dirtyFlag);
114 void clearDirty(DirtyFlag dirtyFlag);
115 [[nodiscard]] inline constexpr bool isDirty(DirtyFlag dirtyFlag = DirtyFlag::DirtyMask) const { return ((flags & FlagT(dirtyFlag)) != 0); }
116 void setState(LocalState state, bool on = true);
117 [[nodiscard]] inline constexpr bool getLocalState(LocalState stateFlag) const { return ((flags & FlagT(stateFlag)) != 0); }
118 [[nodiscard]] inline constexpr bool getGlobalState(GlobalState stateFlag) const { return ((flags & FlagT(stateFlag)) != 0); }
119
120 void addChild(QSSGRenderNode &inChild);
121 void removeChild(QSSGRenderNode &inChild);
122
123 // Remove this node from the graph.
124 // It is no longer the the parent's child lists
125 // and all of its children no longer have a parent
126 // finally they are no longer siblings of each other.
127 void removeFromGraph();
128
129 // Calculates a tranform matrix based on the position, scale, pivot and rotation arguments.
130 // NOTE!!!: This function does not update or mark any nodes as dirty, if the returned matrix is set on a node then
131 // markDirty, calculateGlobalVariables etc. needs to be called as needed!
132 [[nodiscard]] static QMatrix4x4 calculateTransformMatrix(QVector3D position, QVector3D scale, QVector3D pivot, QQuaternion rotation);
133
134 // Get the bounds of us and our children in our local space.
135 QSSGBounds3 getBounds(QSSGBufferManager &inManager,
136 bool inIncludeChildren = true) const;
137 QSSGBounds3 getChildBounds(QSSGBufferManager &inManager) const;
138 // Assumes CalculateGlobalVariables has already been called.
139 [[nodiscard]] static QVector3D getGlobalPos(const QMatrix4x4 &globalTransform) { return QVector3D(globalTransform(0, 3), globalTransform(1, 3), globalTransform(2, 3)); }
140 // Pulls the 3rd column out of the global transform.
141 [[nodiscard]] static QVector3D getDirection(const QMatrix4x4 &globalTransform);
142 // Multiplies (0,0,-1) by the inverse transpose of the upper 3x3 of the global transform.
143 // This is correct w/r/t to scaling and which the above getDirection is not.
144 [[nodiscard]] static QVector3D getScalingCorrectDirection(const QMatrix4x4 &globalTransform);
145
146 // outMVP and outNormalMatrix are returned ready to upload to openGL, meaning they are
147 // row-major.
148 static void calculateMVP(const QMatrix4x4 &globalTransform,
149 const QMatrix4x4 &inViewProjection,
150 QMatrix4x4 &outMVP);
151 static void calculateNormalMatrix(const QMatrix4x4 &globalTransform,
152 QMatrix3x3 &outNormalMatrix);
153 static void calculateMVPAndNormalMatrix(const QMatrix4x4 &globalTransfor,
154 const QMatrix4x4 &inViewProjection,
155 QMatrix4x4 &outMVP,
156 QMatrix3x3 &outNormalMatrix);
157
158 // The Squared value of \a val
159 // This is mainly used for setting the sorting bias on models and particles
160 // since we're using the squared distance when sorting.
161 [[nodiscard]] static inline float signedSquared(float val)
162 {
163 const float sign = (val >= 0.0f) ? 1.0f : -1.0f;
164 return sign * val * val;
165 }
166};
167
168QT_END_NAMESPACE
169
170#endif
Combined button and popup list for selecting options.