Ocean
Loading...
Searching...
No Matches
Object.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_RENDERING_OBJECT_H
9#define META_OCEAN_RENDERING_OBJECT_H
10
12
13#include "ocean/base/Lock.h"
15
16#include <map>
17#include <set>
18
19namespace Ocean
20{
21
22namespace Rendering
23{
24
25// Forward declaration.
26class Engine;
27// Forward declaration.
28class Object;
29
30/**
31 * Definition of a rendering object reference with an internal reference counter.
32 * @see Object.
33 * @ingroup rendering
34 */
36
37/**
38 * Definition of a vector holding rendering object references.
39 * @ingroup rendering
40 */
41typedef std::vector<ObjectRef> ObjectRefs;
42
43/**
44 * Definition of a vector holding rendering object references.
45 * @ingroup rendering
46 */
47typedef std::set<ObjectRef> ObjectRefSet;
48
49/**
50 * This class is the base class for all rendering objects.
51 * @ingroup rendering
52 */
53class OCEAN_RENDERING_EXPORT Object
54{
55 friend class Ocean::ObjectRef<Object>;
56
57 public:
58
59 /**
60 * Definition of different object type.
61 */
63 {
64 /// Unknown type.
66 /// Absolute transform type.
68 /// Attribute type.
70 /// AttributeSet type.
72 /// Background type.
74 /// Billboard type.
76 /// BitmapFramebuffer type.
78 /// BlendAttribute type.
80 /// Box type.
82 /// Cone type.
84 /// Cylinder type.
86 /// DepthAttribute type.
88 /// DirectionalLight type.
90 /// Framebuffer type.
92 /// FrameTexture2D type.
94 /// Geometry type.
96 /// Group type.
98 /// IndependentPrimitive type.
100 /// LightSource type.
102 /// Lines type.
104 /// Line strips type.
106 /// LOD type.
108 /// Material type.
110 /// Node type.
112 /// Object type.
114 /// ParallelView type.
116 /// PerspectiveView type.
118 /// PhantomAttribute type.
120 /// PointLight type.
122 /// Points type.
124 /// Primitive type.
126 /// PrimitiveAttribute type.
128 /// QuadStrips type.
130 /// Quads type.
132 /// Renderable type.
134 /// Scene type.
136 /// ShaderProgram type.
138 /// Shape type.
140 /// SkyBackground type.
142 /// Sphere type.
144 /// SpotLight type.
146 /// StereoAttribute type.
148 /// StereoView type.
150 /// StripPrimitive type.
152 /// Switch type.
154 /// Text type.
156 /// Texture type.
158 /// Texture2D type.
160 /// MediaTexture2D type.
162 /// TextureFramebuffer type.
164 /// Textures type.
166 /// Transform type.
168 /// TriangleFans type.
170 /// Triangles type.
172 /// TriangleStrips type.
174 /// UndistortedBackground type.
176 /// VertexSet type.
178 /// View type.
180 /// WindowFramebuffer type.
181 TYPE_WINDOW_FRAMEBUFFER
182 };
183
184 /**
185 * Definition of a map holding object ids to reference counters.
186 */
187 typedef std::unordered_map<ObjectId, unsigned int> ObjectIdMap;
188
189 public:
190
191 /**
192 * Returns the unique object id of this object.
193 * @return Unique object id
194 */
195 inline ObjectId id() const;
196
197 /**
198 * Returns the name of this object.
199 * @return Object name
200 */
201 inline const std::string& name() const;
202
203 /**
204 * Sets or changes the name of this object.
205 * @param name New object name
206 */
207 virtual void setName(const std::string& name);
208
209 /**
210 * Returns the name of the owner engine.
211 * @return Owner engine
212 */
213 virtual const std::string& engineName() const = 0;
214
215 /**
216 * Returns the type of this object.
217 * @return Object type
218 */
219 virtual ObjectType type() const;
220
221 /**
222 * Returns all parent objects.
223 * @return Vector holding all parent objects
224 */
226
227 /**
228 * Returns all parent nodes.
229 * @return Set holding all parent nodes
230 */
232
233 /**
234 * Returns descriptive information about the object as string.
235 * The descriptive information can be used during debugging.
236 * @return The object's descriptive information, if any
237 */
238 virtual std::string descriptiveInformation() const;
239
240 /**
241 * Translates an object type to a readable string.
242 * @param objectType The object type to translate
243 * @return The resulting readable string of the object type
244 */
245 static std::string translateObjectType(const ObjectType objectType);
246
247 protected:
248
249 /**
250 * Creates a new object.
251 */
253
254 /**
255 * Disabled copy constructor.
256 * @param object Object which would be copied
257 */
258 Object(const Object& object) = delete;
259
260 /**
261 * Destructs an object.
262 */
263 virtual ~Object();
264
265 /**
266 * Returns the render engine which is owner of this object.
267 * @return Rendering engine
268 */
269 Engine& engine() const;
270
271 /**
272 * Registers a parent node for this (child) node.
273 * @param parentId Id of the parent node to register
274 */
275 inline void registerParent(const ObjectId parentId);
276
277 /**
278 * Unregisters a parent node for this (child) node.
279 * @param parentId Id of the parent node to unregister
280 */
281 inline void unregisterParent(const ObjectId parentId);
282
283 /**
284 * Registers this object at a child as parent object.
285 * @param child New child object for this object
286 */
288
289 /**
290 * Unregisters this object from a child as parent.
291 * @param child Child object to unregister
292 */
294
295 /**
296 * Disabled copy operator.
297 * @param object Object which would be copied
298 * @return Reference to this object
299 */
300 Object& operator=(const Object& object) = delete;
301
302 protected:
303
304 /// Lock for the object
306
307 private:
308
309 /// Unique object id.
311
312 /// Object name.
313 std::string objectName;
314
315 /// Object ids of parent objects.
317};
318
319inline ObjectId Object::id() const
320{
321 return objectId;
322}
323
324inline const std::string& Object::name() const
325{
326 return objectName;
327}
328
329inline void Object::registerParent(const ObjectId parentId)
330{
331 const ScopedLock scopedLock(objectLock);
332
333 ++objectParents.insert(std::make_pair(parentId, 0)).first->second;
334}
335
336inline void Object::unregisterParent(const ObjectId parentId)
337{
338 const ScopedLock scopedLock(objectLock);
339
340 ObjectIdMap::iterator i = objectParents.find(parentId);
341 ocean_assert(i != objectParents.end());
342
343 ocean_assert(i->second != 0);
344
345 if (--i->second == 0)
346 {
347 objectParents.erase(i);
348 }
349}
350
351/**
352 * Write the descriptive information of an object to a stream.
353 * @param stream The stream to which the object's description will be written
354 * @param object The object to be written to the stream
355 * @ingroup rendering
356 */
357inline std::ostream& operator<<(std::ostream& stream, const Object& object)
358{
359 stream << object.descriptiveInformation();
360
361 return stream;
362}
363
364/**
365 * Write the descriptive information of an object to a message object.
366 * @param messageObject The message object to which the object's description will be written
367 * @param object The object to be written to the message object
368 * @tparam tActive True, if the messenger object is active; False, if the messenger object is disabled
369 * @ingroup rendering
370 */
371template <bool tActive>
372inline MessageObject<tActive>& operator<<(MessageObject<tActive>& messageObject, const Object& object)
373{
374 return messageObject << object.descriptiveInformation();
375}
376
377/**
378 * Write the descriptive information of an object to a message object.
379 * @param messageObject The message object to which the object's description will be written
380 * @param object The object to be written to the message object
381 * @tparam tActive True, if the messenger object is active; False, if the messenger object is disabled
382 * @ingroup rendering
383 */
384template <bool tActive>
385inline MessageObject<tActive>& operator<<(MessageObject<tActive>&& messageObject, const Object& object)
386{
387 return messageObject << object.descriptiveInformation();
388}
389
390}
391
392}
393
394#endif // META_OCEAN_RENDERING_OBJECT_H
This class implements a recursive lock object.
Definition Lock.h:31
Messenger object, one object for each message.
Definition Messenger.h:427
This template class implements a object reference with an internal reference counter.
Definition base/ObjectRef.h:58
This class is the base class for all rendering engines like.
Definition Engine.h:46
This class is the base class for all rendering objects.
Definition Object.h:54
std::string objectName
Object name.
Definition Object.h:313
ObjectIdMap objectParents
Object ids of parent objects.
Definition Object.h:316
ObjectRefSet parentNodes() const
Returns all parent nodes.
virtual std::string descriptiveInformation() const
Returns descriptive information about the object as string.
std::unordered_map< ObjectId, unsigned int > ObjectIdMap
Definition of a map holding object ids to reference counters.
Definition Object.h:187
virtual ~Object()
Destructs an object.
static std::string translateObjectType(const ObjectType objectType)
Translates an object type to a readable string.
Object()
Creates a new object.
virtual void setName(const std::string &name)
Sets or changes the name of this object.
Lock objectLock
Lock for the object.
Definition Object.h:305
Engine & engine() const
Returns the render engine which is owner of this object.
void unregisterThisObjectAsParent(const ObjectRef &child)
Unregisters this object from a child as parent.
const std::string & name() const
Returns the name of this object.
Definition Object.h:324
void unregisterParent(const ObjectId parentId)
Unregisters a parent node for this (child) node.
Definition Object.h:336
ObjectType
Definition of different object type.
Definition Object.h:63
@ TYPE_PRIMITIVE_ATTRIBUTE
PrimitiveAttribute type.
Definition Object.h:127
@ TYPE_DIRECTIONAL_LIGHT
DirectionalLight type.
Definition Object.h:89
@ TYPE_ATTRIBUTE
Attribute type.
Definition Object.h:69
@ TYPE_ABSOLUTE_TRANSFORM
Absolute transform type.
Definition Object.h:67
@ TYPE_MATERIAL
Material type.
Definition Object.h:109
@ TYPE_FRAMEBUFFER
Framebuffer type.
Definition Object.h:91
@ TYPE_OBJECT
Object type.
Definition Object.h:113
@ TYPE_BLEND_ATTRIBUTE
BlendAttribute type.
Definition Object.h:79
@ TYPE_BITMAP_FRAMEBUFFER
BitmapFramebuffer type.
Definition Object.h:77
@ TYPE_FRAME_TEXTURE_2D
FrameTexture2D type.
Definition Object.h:93
@ TYPE_SHADER_PROGRAM
ShaderProgram type.
Definition Object.h:137
@ TYPE_UNDISTORTED_BACKGROUND
UndistortedBackground type.
Definition Object.h:175
@ TYPE_SCENE
Scene type.
Definition Object.h:135
@ TYPE_POINTS
Points type.
Definition Object.h:123
@ TYPE_TEXTURES
Textures type.
Definition Object.h:165
@ TYPE_UNKNOWN
Unknown type.
Definition Object.h:65
@ TYPE_LINE_STRIPS
Line strips type.
Definition Object.h:105
@ TYPE_TEXTURE_2D
Texture2D type.
Definition Object.h:159
@ TYPE_LIGHT_SOURCE
LightSource type.
Definition Object.h:101
@ TYPE_SKY_BACKGROUND
SkyBackground type.
Definition Object.h:141
@ TYPE_QUAD_STRIPS
QuadStrips type.
Definition Object.h:129
@ TYPE_POINT_LIGHT
PointLight type.
Definition Object.h:121
@ TYPE_STEREO_ATTRIBUTE
StereoAttribute type.
Definition Object.h:147
@ TYPE_RENDERABLE
Renderable type.
Definition Object.h:133
@ TYPE_PRIMITIVE
Primitive type.
Definition Object.h:125
@ TYPE_DEPTH_ATTRIBUTE
DepthAttribute type.
Definition Object.h:87
@ TYPE_SPHERE
Sphere type.
Definition Object.h:143
@ TYPE_LOD
LOD type.
Definition Object.h:107
@ TYPE_LINES
Lines type.
Definition Object.h:103
@ TYPE_MEDIA_TEXTURE_2D
MediaTexture2D type.
Definition Object.h:161
@ TYPE_PARALLEL_VIEW
ParallelView type.
Definition Object.h:115
@ TYPE_TRIANGLE_FANS
TriangleFans type.
Definition Object.h:169
@ TYPE_STRIP_PRIMITIVE
StripPrimitive type.
Definition Object.h:151
@ TYPE_CYLINDER
Cylinder type.
Definition Object.h:85
@ TYPE_TEXTURE
Texture type.
Definition Object.h:157
@ TYPE_PHANTOM_ATTRIBUTE
PhantomAttribute type.
Definition Object.h:119
@ TYPE_SHAPE
Shape type.
Definition Object.h:139
@ TYPE_GEOMETRY
Geometry type.
Definition Object.h:95
@ TYPE_VIEW
View type.
Definition Object.h:179
@ TYPE_TRIANGLES
Triangles type.
Definition Object.h:171
@ TYPE_SWITCH
Switch type.
Definition Object.h:153
@ TYPE_INDEPENDENT_PRIMITIVE
IndependentPrimitive type.
Definition Object.h:99
@ TYPE_NODE
Node type.
Definition Object.h:111
@ TYPE_BOX
Box type.
Definition Object.h:81
@ TYPE_CONE
Cone type.
Definition Object.h:83
@ TYPE_GROUP
Group type.
Definition Object.h:97
@ TYPE_PERSPECTIVE_VIEW
PerspectiveView type.
Definition Object.h:117
@ TYPE_STEREO_VIEW
StereoView type.
Definition Object.h:149
@ TYPE_TRIANGLE_STRIPS
TriangleStrips type.
Definition Object.h:173
@ TYPE_ATTRIBUTE_SET
AttributeSet type.
Definition Object.h:71
@ TYPE_BACKGROUND
Background type.
Definition Object.h:73
@ TYPE_BILLBOARD
Billboard type.
Definition Object.h:75
@ TYPE_TEXT
Text type.
Definition Object.h:155
@ TYPE_TEXTURE_FRAMEBUFFER
TextureFramebuffer type.
Definition Object.h:163
@ TYPE_SPOT_LIGHT
SpotLight type.
Definition Object.h:145
@ TYPE_QUADS
Quads type.
Definition Object.h:131
@ TYPE_TRANSFORM
Transform type.
Definition Object.h:167
@ TYPE_VERTEX_SET
VertexSet type.
Definition Object.h:177
ObjectRefs parentObjects() const
Returns all parent objects.
ObjectId id() const
Returns the unique object id of this object.
Definition Object.h:319
virtual const std::string & engineName() const =0
Returns the name of the owner engine.
Object(const Object &object)=delete
Disabled copy constructor.
ObjectId objectId
Unique object id.
Definition Object.h:310
void registerParent(const ObjectId parentId)
Registers a parent node for this (child) node.
Definition Object.h:329
virtual ObjectType type() const
Returns the type of this object.
void registerThisObjectAsParent(const ObjectRef &child)
Registers this object at a child as parent object.
Object & operator=(const Object &object)=delete
Disabled copy operator.
This class implements a scoped lock object for recursive lock objects.
Definition Lock.h:135
std::set< ObjectRef > ObjectRefSet
Definition of a vector holding rendering object references.
Definition Object.h:47
std::ostream & operator<<(std::ostream &stream, const Object &object)
Write the descriptive information of an object to a stream.
Definition Object.h:357
Ocean::ObjectRef< Object > ObjectRef
Definition of a rendering object reference with an internal reference counter.
Definition Object.h:35
std::vector< ObjectRef > ObjectRefs
Definition of a vector holding rendering object references.
Definition Object.h:41
The namespace covering the entire Ocean framework.
Definition Accessor.h:15