1 | // Copyright (C) 2008-2012 NVIDIA Corporation. |
---|---|
2 | // Copyright (C) 2023 The Qt Company Ltd. |
3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
4 | |
5 | #ifndef QSSGRENDERGRAPHOBJECT_P_H |
6 | #define QSSGRENDERGRAPHOBJECT_P_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 <ssg/qssgrendergraphobject.h> |
20 | |
21 | #include <ssg/qssgrenderbasetypes.h> |
22 | |
23 | #include <QtQuick3DUtils/private/qssgassert_p.h> |
24 | |
25 | namespace QSSGRenderGraphObjectUtils { |
26 | constexpr QSSGResourceId getResourceId(const QSSGRenderGraphObject &o) |
27 | { |
28 | QSSG_ASSERT(QSSGRenderGraphObject::isResource(o.type), return QSSGResourceId::Invalid); |
29 | return QSSGResourceId{ quintptr(&o) }; |
30 | } |
31 | |
32 | template <typename T = QSSGRenderGraphObject> |
33 | T *getResource(QSSGResourceId resId) |
34 | { |
35 | return static_cast<T *>(reinterpret_cast<QSSGRenderGraphObject *>(resId)); |
36 | } |
37 | |
38 | constexpr QSSGNodeId getNodeId(const QSSGRenderGraphObject &o) |
39 | { |
40 | QSSG_ASSERT(QSSGRenderGraphObject::isNodeType(o.type), return QSSGNodeId::Invalid); |
41 | return QSSGNodeId{ quintptr(&o) }; |
42 | } |
43 | |
44 | template <typename T = QSSGRenderGraphObject> |
45 | T *getNode(QSSGNodeId nodeId) |
46 | { |
47 | return static_cast<T *>(reinterpret_cast<QSSGRenderGraphObject *>(nodeId)); |
48 | } |
49 | |
50 | constexpr QSSGCameraId getCameraId(const QSSGRenderGraphObject &o) |
51 | { |
52 | QSSG_ASSERT(QSSGRenderGraphObject::isCamera(o.type), return QSSGCameraId::Invalid); |
53 | return QSSGCameraId{ quintptr(&o) }; |
54 | } |
55 | |
56 | template <typename T = QSSGRenderGraphObject> |
57 | T *getCamera(QSSGCameraId cameraId) |
58 | { |
59 | return static_cast<T *>(reinterpret_cast<QSSGRenderGraphObject *>(cameraId)); |
60 | } |
61 | |
62 | constexpr QSSGExtensionId getExtensionId(const QSSGRenderGraphObject &o) |
63 | { |
64 | QSSG_ASSERT(QSSGRenderGraphObject::isExtension(o.type), return QSSGExtensionId::Invalid); |
65 | return QSSGExtensionId{ quintptr(&o) }; |
66 | } |
67 | |
68 | template <typename T = QSSGRenderGraphObject> |
69 | T *getExtension(QSSGExtensionId extensionId) |
70 | { |
71 | return static_cast<T *>(reinterpret_cast<QSSGRenderGraphObject *>(extensionId)); |
72 | } |
73 | |
74 | template <typename QSSGTypeId> |
75 | constexpr bool isNull(QSSGTypeId id) { return (id == QSSGTypeId::Invalid); } |
76 | } |
77 | |
78 | #endif // QSSGRENDERGRAPHOBJECT_P_H |
79 |