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 };
47
48 enum class GlobalState : quint8
49 {
50 Active = 1 << 2,
51 Pickable = 1 << 3
52 };
53
54 enum class DirtyFlag : quint32
55 {
56 TransformDirty = 1 << 4,
57 OpacityDirty = 1 << 5,
58 ActiveDirty = 1 << 6,
59 PickableDirty = 1 << 7,
60 TagDirty = 1 << 8,
61 SubNodeDirty = 1 << 9, // Sub-nodes should set/unest this if they "extend" the dirty flags provided by the node
62
63 GlobalValuesDirty = TransformDirty | OpacityDirty | ActiveDirty | PickableDirty,
64 DirtyMask = GlobalValuesDirty | SubNodeDirty
65 };
66 using FlagT = std::underlying_type_t<DirtyFlag>;
67
68 static constexpr QVector3D initScale { 1.0f, 1.0f, 1.0f };
69
70 // changing any one of these means you have to
71 // set this object dirty
72 QVector3D pivot;
73 int staticFlags = 0;
74
75 // This only sets dirty, not transform dirty
76 // Opacity of 1 means opaque, opacity of zero means transparent.
77 float localOpacity = 1.0f;
78
79 // Nodes are initially dirty and locally active!
80 FlagT flags { FlagT(DirtyFlag::GlobalValuesDirty) | FlagT(LocalState::Active) };
81 // These end up right handed
82 QMatrix4x4 localTransform;
83
84 // node graph members.
85 QSSGRenderRoot **rootNodeRef = nullptr;
86 QSSGRenderNode *parent = nullptr;
87 QSSGRenderNode *nextSibling = nullptr;
88 QSSGRenderNode *previousSibling = nullptr;
89 QSSGRenderNode *instanceRoot = nullptr;
90
91 // Handle(s) to the render data.
92 QSSGRenderNodeHandle h;
93 QSSGRenderNodeTag tag;
94
95 using ChildList = QSSGInvasiveLinkedList<QSSGRenderNode, &QSSGRenderNode::previousSibling, &QSSGRenderNode::nextSibling>;
96 ChildList children;
97
98 QString debugObjectName;
99
100 QSSGRenderNode();
101 QSSGRenderNode(Type type, FlagT flags = 0);
102 ~QSSGRenderNode() override;
103
104 // Sets this object dirty and walks down the graph setting all
105 // children who are not dirty to be dirty.
106 void markDirty(DirtyFlag dirtyFlag);
107 void clearDirty(DirtyFlag dirtyFlag);
108 [[nodiscard]] inline constexpr bool isDirty(DirtyFlag dirtyFlag = DirtyFlag::DirtyMask) const { return ((flags & FlagT(dirtyFlag)) != 0); }
109 void setState(LocalState state, bool on = true);
110 [[nodiscard]] inline constexpr bool getLocalState(LocalState stateFlag) const { return ((flags & FlagT(stateFlag)) != 0); }
111 [[nodiscard]] inline constexpr bool getGlobalState(GlobalState stateFlag) const { return ((flags & FlagT(stateFlag)) != 0); }
112
113 void addChild(QSSGRenderNode &inChild);
114 void removeChild(QSSGRenderNode &inChild);
115
116 // Remove this node from the graph.
117 // It is no longer the the parent's child lists
118 // and all of its children no longer have a parent
119 // finally they are no longer siblings of each other.
120 void removeFromGraph();
121
122 // Calculates a tranform matrix based on the position, scale, pivot and rotation arguments.
123 // NOTE!!!: This function does not update or mark any nodes as dirty, if the returned matrix is set on a node then
124 // markDirty, calculateGlobalVariables etc. needs to be called as needed!
125 [[nodiscard]] static QMatrix4x4 calculateTransformMatrix(QVector3D position, QVector3D scale, QVector3D pivot, QQuaternion rotation);
126
127 // Get the bounds of us and our children in our local space.
128 QSSGBounds3 getBounds(QSSGBufferManager &inManager,
129 bool inIncludeChildren = true) const;
130 QSSGBounds3 getChildBounds(QSSGBufferManager &inManager) const;
131 // Assumes CalculateGlobalVariables has already been called.
132 [[nodiscard]] static QVector3D getGlobalPos(const QMatrix4x4 &globalTransform) { return QVector3D(globalTransform(0, 3), globalTransform(1, 3), globalTransform(2, 3)); }
133 // Pulls the 3rd column out of the global transform.
134 [[nodiscard]] static QVector3D getDirection(const QMatrix4x4 &globalTransform);
135 // Multiplies (0,0,-1) by the inverse transpose of the upper 3x3 of the global transform.
136 // This is correct w/r/t to scaling and which the above getDirection is not.
137 [[nodiscard]] static QVector3D getScalingCorrectDirection(const QMatrix4x4 &globalTransform);
138
139 // outMVP and outNormalMatrix are returned ready to upload to openGL, meaning they are
140 // row-major.
141 static void calculateMVP(const QMatrix4x4 &globalTransform,
142 const QMatrix4x4 &inViewProjection,
143 QMatrix4x4 &outMVP);
144 static void calculateNormalMatrix(const QMatrix4x4 &globalTransform,
145 QMatrix3x3 &outNormalMatrix);
146 static void calculateMVPAndNormalMatrix(const QMatrix4x4 &globalTransfor,
147 const QMatrix4x4 &inViewProjection,
148 QMatrix4x4 &outMVP,
149 QMatrix3x3 &outNormalMatrix);
150
151 // The Squared value of \a val
152 // This is mainly used for setting the sorting bias on models and particles
153 // since we're using the squared distance when sorting.
154 [[nodiscard]] static inline float signedSquared(float val)
155 {
156 const float sign = (val >= 0.0f) ? 1.0f : -1.0f;
157 return sign * val * val;
158 }
159};
160
161QT_END_NAMESPACE
162
163#endif