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

source code of qtquick3d/src/runtimerender/graphobjects/qssgrendergraphobject.h