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_GRAPH_OBJECT_H |
6 | #define QSSG_RENDER_GRAPH_OBJECT_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/qtquick3druntimerenderglobal_p.h> |
20 | #include <QtQuick3DUtils/private/qquick3dprofiler_p.h> |
21 | #include <QtCore/QString> |
22 | #include <QtCore/QDebug> |
23 | |
24 | QT_BEGIN_NAMESPACE |
25 | |
26 | class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRenderGraphObject |
27 | { |
28 | Q_DISABLE_COPY_MOVE(QSSGRenderGraphObject) |
29 | public: |
30 | // Types should be setup on construction. Change the type |
31 | // at your own risk as the type is used for RTTI purposes. |
32 | // See QSSGRenderGraphObject, QQuick3DObject and QSSceneDesc (asset useage). |
33 | |
34 | enum BaseType : quint32 { |
35 | // Internal types |
36 | Node = 0x1000, |
37 | Light = 0x2000, |
38 | Camera = 0x4000, |
39 | Renderable = 0x8000, |
40 | Resource = 0x10000, |
41 | Material = 0x20000, |
42 | Texture = 0x40000, |
43 | Extension = 0x80000, |
44 | User = 0x80000000 |
45 | }; |
46 | |
47 | enum class Type : quint32 { |
48 | Unknown = 0, |
49 | // Nodes |
50 | Node = BaseType::Node, |
51 | Layer, // Node |
52 | Joint, // Node |
53 | Skeleton, // Node (A resource to the model node) |
54 | ImportScene, // Node |
55 | ReflectionProbe, |
56 | // Light nodes |
57 | DirectionalLight = BaseType::Light | BaseType::Node, |
58 | PointLight, |
59 | SpotLight, |
60 | // Camera nodes |
61 | OrthographicCamera = BaseType::Camera | BaseType::Node, |
62 | PerspectiveCamera, |
63 | CustomFrustumCamera, // Perspective camera with user specified frustum bounds. |
64 | CustomCamera, |
65 | // Renderable nodes |
66 | Model = BaseType::Renderable | BaseType::Node, // Renderable Node |
67 | Item2D, // Renderable Node |
68 | Particles, // Renderable Node |
69 | // Resources |
70 | SceneEnvironment = BaseType::Resource, // Resource |
71 | Effect, // Resource |
72 | Geometry, // Resource |
73 | TextureData, // Resource |
74 | MorphTarget, // Resource |
75 | ModelInstance, // Resource |
76 | ModelBlendParticle, // Resource |
77 | ResourceLoader, // Resource [meta] |
78 | // Materials |
79 | DefaultMaterial = BaseType::Material | BaseType::Resource, // Resource |
80 | PrincipledMaterial, // Resource |
81 | CustomMaterial, // Resource |
82 | SpecularGlossyMaterial, //Resource |
83 | Skin, // Resource |
84 | // Textures |
85 | Image2D = BaseType::Texture | BaseType::Resource, // Resource |
86 | ImageCube, // Resource |
87 | RenderExtension = BaseType::Extension, // Extension |
88 | // User types E.g.: (User | Node) + 1) |
89 | }; |
90 | using TypeT = std::underlying_type_t<Type>; |
91 | |
92 | enum class Flags : quint32 { |
93 | HasGraphicsResources = 0x1 |
94 | }; |
95 | using FlagT = std::underlying_type_t<Flags>; |
96 | |
97 | [[nodiscard]] static inline constexpr bool isNodeType(Type type) noexcept |
98 | { |
99 | return (TypeT(type) & BaseType::Node); |
100 | } |
101 | |
102 | [[nodiscard]] static inline constexpr bool isLight(Type type) noexcept |
103 | { |
104 | return (TypeT(type) & BaseType::Light); |
105 | } |
106 | |
107 | [[nodiscard]] static inline constexpr bool isCamera(Type type) noexcept |
108 | { |
109 | return (TypeT(type) & BaseType::Camera); |
110 | } |
111 | |
112 | [[nodiscard]] static inline constexpr bool isMaterial(Type type) noexcept |
113 | { |
114 | return (TypeT(type) & BaseType::Material); |
115 | } |
116 | |
117 | [[nodiscard]] static inline constexpr bool isTexture(Type type) noexcept |
118 | { |
119 | return (TypeT(type) & BaseType::Texture); |
120 | } |
121 | |
122 | [[nodiscard]] static inline constexpr bool isRenderable(Type type) noexcept |
123 | { |
124 | return (TypeT(type) & BaseType::Renderable); |
125 | } |
126 | |
127 | [[nodiscard]] static inline constexpr bool isResource(Type type) noexcept |
128 | { |
129 | return (TypeT(type) & BaseType::Resource); |
130 | } |
131 | |
132 | [[nodiscard]] static inline constexpr bool isExtension(Type type) noexcept |
133 | { |
134 | return (TypeT(type) & BaseType::Extension); |
135 | } |
136 | |
137 | // Note: This could have been a non-static member, as we never create or use |
138 | // user types we do the built-in types; In any case just follow the existing pattern. |
139 | [[nodiscard]] static inline constexpr bool isUserType(Type type) noexcept |
140 | { |
141 | return (TypeT(type) & BaseType::User); |
142 | } |
143 | |
144 | // Objects tagged with HasGraphicsResources get special handling and will be queued for release |
145 | // on the render thread after the frame has been submitted. See cleanupNodes() in the scene manager. |
146 | [[nodiscard]] inline bool hasGraphicsResources() noexcept |
147 | { |
148 | return ((flags & FlagT(Flags::HasGraphicsResources)) != 0); |
149 | } |
150 | |
151 | const Type type; |
152 | FlagT flags { 0 }; |
153 | Q_QUICK3D_PROFILE_ID |
154 | |
155 | explicit QSSGRenderGraphObject(QSSGRenderGraphObject::Type inType); |
156 | explicit QSSGRenderGraphObject(QSSGRenderGraphObject::Type inType, FlagT inFlags) : type(inType), flags(inFlags) {} |
157 | virtual ~QSSGRenderGraphObject(); |
158 | |
159 | #ifndef QT_NO_DEBUG_STREAM |
160 | friend Q_QUICK3DRUNTIMERENDER_EXPORT QDebug operator<<(QDebug stream, QSSGRenderGraphObject::Type type); |
161 | #endif |
162 | }; |
163 | |
164 | #ifndef QT_NO_DEBUG_STREAM |
165 | Q_QUICK3DRUNTIMERENDER_EXPORT QDebug operator<<(QDebug, QSSGRenderGraphObject::Type type); |
166 | #endif |
167 | |
168 | QT_END_NAMESPACE |
169 | |
170 | #endif |
171 | |