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