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
qquick3dextensionhelpers.cpp
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
6
7#include <QtQuick3DUtils/private/qssgassert_p.h>
8#include <QtQuick3DRuntimeRender/private/qssgrendernode_p.h>
9
11
12/*!
13 \typedef QSSGNodeId
14 \relates QtQuick3D
15
16 The QSSGNodeId is a handle to a QtQuick3D node object. \l Node objects are all
17 objects that inherits from \l Node, like the \l Model item.
18*/
19
20/*!
21 \typedef QSSGResourceId
22 \relates QtQuick3D
23
24 The QSSGResourceId is a handle to a QtQuick3D object. Resources are usually all
25 \l {Node}{none-node} types.
26*/
27
28/*!
29 \typedef QSSGCameraId
30 \relates QtQuick3D
31
32 The QSSGCameraId is a handle to a QtQuick3D \l Camera object, like the \l PerspectiveCamera item.
33
34 \note Cameras are also nodes.
35*/
36
37/*!
38 \typedef QSSGExtensionId
39 \relates QtQuick3D
40
41 The QSSGExtensionId is a handle to a QtQuick3D extension type, like items that inherits from the
42 \l RenderExtension type.
43
44 \sa QQuick3DRenderExtension, QSSGRenderExtension
45*/
46
47/*!
48 \class QQuick3DExtensionHelpers
49 \inmodule QtQuick3D
50 \since 6.6
51
52 \brief Helper functions for the Extensions APIs.
53*/
54
55QQuick3DExtensionHelpers::QQuick3DExtensionHelpers()
56{
57
58}
59
60/*!
61 \return a \c QSSGNodeId that can be used to retrieve the object in the engine
62 corresponding to \a node.
63
64 //! \sa QSSGFrameData::getNode()
65*/
66QSSGNodeId QQuick3DExtensionHelpers::getNodeId(const QQuick3DObject &node)
67{
68 auto *po = QQuick3DObjectPrivate::get(&node);
69 QSSG_ASSERT_X(QSSGRenderGraphObject::isNodeType(po->type), "Type is not a node", return QSSGNodeId::Invalid);
70 // NOTE: Implementation detail (don't rely on this in user code).
71 return static_cast<QSSGNodeId>(quintptr(QQuick3DObjectPrivate::get(&node)->spatialNode));
72}
73
74/*!
75 \return a \c QSSGResourceId that can be used to retrieve the corresponding \a resource object
76 in the engine.
77
78 //! \sa QSSGFrameData::getResource()
79*/
80QSSGResourceId QQuick3DExtensionHelpers::getResourceId(const QQuick3DObject &resource)
81{
82 auto *po = QQuick3DObjectPrivate::get(&resource);
83 QSSG_ASSERT_X(QSSGRenderGraphObject::isResource(po->type), "Type is not a resource", return QSSGResourceId::Invalid);
84 // NOTE: Implementation detail (don't rely on this in user code).
85 return static_cast<QSSGResourceId>(quintptr(QQuick3DObjectPrivate::get(&resource)->spatialNode));
86}
87
88/*!
89 \return a \c QSSGCameraId that can be used to retrieve the corresponding \a camera object
90 in the engine.
91
92 //! \sa QSSGFrameData::getNode()
93*/
94QSSGCameraId QQuick3DExtensionHelpers::getCameraId(const QQuick3DObject &camera)
95{
96 auto *po = QQuick3DObjectPrivate::get(&camera);
97 QSSG_ASSERT_X(QSSGRenderGraphObject::isCamera(po->type), "Type is not a camera", return QSSGCameraId::Invalid);
98 // NOTE: Implementation detail (don't rely on this in user code).
99 return static_cast<QSSGCameraId>(quintptr(po->spatialNode));
100}
101
102QSSGExtensionId QQuick3DExtensionHelpers::getExtensionId(const QQuick3DObject &extension)
103{
104 auto *po = QQuick3DObjectPrivate::get(&extension);
105 QSSG_ASSERT_X(QSSGRenderGraphObject::isExtension(po->type), "Type is not an extension", return QSSGExtensionId::Invalid);
106 // NOTE: Implementation detail (don't rely on this in user code).
107 return static_cast<QSSGExtensionId>(quintptr(po->spatialNode));
108}
109
110
111/*!
112 \return the type of the node with the given \a nodeId.
113
114 This function is useful to determine the type of a \a nodeId.
115
116 \sa QSSGRenderGraphObject::Type
117*/
118QSSGRenderGraphObject::Type QQuick3DExtensionHelpers::getNodeIdType(QSSGNodeId nodeId)
119{
120 auto *node = QSSGRenderGraphObjectUtils::getNode(nodeId);
121 return node ? node->type : QSSGRenderGraphObject::Type::Unknown;
122}
123
124QT_END_NAMESPACE