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

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of qtquick3d/src/quick3d/extensions/qquick3dextensionhelpers.cpp