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