Ocean
rendering/Manager.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_MANAGER_H
9 #define META_OCEAN_RENDERING_MANAGER_H
10 
12 #include "ocean/rendering/Engine.h"
13 
14 #include "ocean/base/Singleton.h"
15 
16 #include <map>
17 #include <vector>
18 
19 namespace Ocean
20 {
21 
22 namespace Rendering
23 {
24 
25 /**
26  * This class manages all scene graphs.<br>
27  * Use this manager to receive a specific render engine.<br>
28  * @ingroup rendering
29  */
30 class OCEAN_RENDERING_EXPORT Manager : public Singleton<Manager>
31 {
32  friend class Engine;
33  friend class Singleton<Manager>;
34 
35  public:
36 
37  /**
38  * Definition of a vector holding engine names.
39  */
40  typedef std::vector<std::string> EngineNames;
41 
42  private:
43 
44  /**
45  * Class holding engine informations.
46  */
48  {
49  public:
50 
51  /**
52  * Creates an information object.
53  */
54  EngineInformation() = default;
55 
56  /**
57  * Creates a new engine information object.
58  * @param name The name of the engine object.
59  * @param callback Callback function creating the engine object
60  * @param graphicAPI Graphic API supported by the engine
61  */
62  EngineInformation(const std::string& name, const Engine::CreateCallback& callback, const Engine::GraphicAPI graphicAPI);
63 
64  /**
65  * Returns the engine of this information object.
66  * @param preferredGraphicAPI Graphic API preferred for rendering
67  * @return Exsiting engine object or new created engine object
68  */
69  EngineRef engine(const Engine::GraphicAPI preferredGraphicAPI);
70 
71  /**
72  * Returns the name of this information object.
73  * @return Engine name
74  */
75  inline const std::string& name() const;
76 
77  /**
78  * Returns the graphic API supported by the engine of this information object.
79  * @return Supported graphic API
80  */
81  inline Engine::GraphicAPI graphicAPI() const;
82 
83  /**
84  * Releases the stored engine object.
85  */
86  void release();
87 
88  /**
89  * Returns whether no internal engine object is stored.
90  * @return True, if so
91  */
92  bool isNull() const;
93 
94  protected:
95 
96  /// Engine name.
97  std::string name_;
98 
99  /// Engine creation callback function.
101 
102  /// Supported graphic API.
104 
105  /// Engine object.
107  };
108 
109  /**
110  * Definition of a map mapping rendering engine priorities to engine information objects.
111  */
112  typedef std::multimap<unsigned int, EngineInformation> EngineMap;
113 
114  public:
115 
116  /**
117  * Returns a render engine of a specific scene graph.
118  * If no engine name is specified one of the registered engines is returned.
119  * @param engine Name of the engine to return
120  * @param graphicAPI Preferred graphic API used for rendering, however there is no guarantee for this API
121  * @return Specified render engine
122  */
123  EngineRef engine(const std::string& engine = std::string(), const Engine::GraphicAPI graphicAPI = Engine::API_DEFAULT);
124 
125  /**
126  * Returns all names of registered engines.
127  * @return Engine names
128  */
130 
131  /**
132  * Returns the graphic API supported by a specified engine.
133  * @param engine Name of the engine to return the graphic API for
134  * @return Supported graphic API, default api if the engine is unknown
135  */
136  Engine::GraphicAPI supportedGraphicAPI(const std::string& engine);
137 
138  /**
139  * Releases all registered rendering engines.
140  */
141  void release();
142 
143  private:
144 
145  /**
146  * Destructs the manager.
147  */
148  virtual ~Manager();
149 
150  /**
151  * Registers a new render engine.
152  * @param engineName Name of the render engine
153  * @param callback Callback function which will create the engine object requested
154  * @param graphicAPI Graphic API supported by the engine
155  * @param priority Priority of this engine, if a default engine is requested the engine with higher priority will be retuned
156  */
157  void registerEngine(const std::string& engineName, const Engine::CreateCallback& callback, const Engine::GraphicAPI graphicAPI, const unsigned int priority);
158 
159  /**
160  * Unregisters a render engine.
161  * @param engine Name of the render engine to unregister
162  * @return True, if succeeded
163  */
164  bool unregisterEngine(const std::string& engine);
165 
166  /**
167  * Callback function to inform this manager that an engine is not in use anymore.
168  * @param engine Engine which is out of use
169  */
170  void onRemoveEngine(const Engine* engine);
171 
172  private:
173 
174  /// Registered engines.
176 
177  /// Manager lock.
179 };
180 
181 inline const std::string& Manager::EngineInformation::name() const
182 {
183  return name_;
184 }
185 
187 {
188  return graphicAPI_;
189 }
190 
191 }
192 
193 }
194 
195 #endif // META_OCEAN_RENDERING_MANAGER_H
This class implements a recursive lock object.
Definition: Lock.h:31
This class is the base class for all rendering engines like.
Definition: Engine.h:46
GraphicAPI
Definition of different graphic APIs.
Definition: Engine.h:57
@ API_DEFAULT
Invalid graphic api id.
Definition: Engine.h:59
Class holding engine informations.
Definition: rendering/Manager.h:48
EngineInformation()=default
Creates an information object.
const std::string & name() const
Returns the name of this information object.
Definition: rendering/Manager.h:181
Engine::GraphicAPI graphicAPI() const
Returns the graphic API supported by the engine of this information object.
Definition: rendering/Manager.h:186
bool isNull() const
Returns whether no internal engine object is stored.
EngineRef engine_
Engine object.
Definition: rendering/Manager.h:106
void release()
Releases the stored engine object.
std::string name_
Engine name.
Definition: rendering/Manager.h:97
EngineInformation(const std::string &name, const Engine::CreateCallback &callback, const Engine::GraphicAPI graphicAPI)
Creates a new engine information object.
EngineRef engine(const Engine::GraphicAPI preferredGraphicAPI)
Returns the engine of this information object.
Engine::CreateCallback createCallback_
Engine creation callback function.
Definition: rendering/Manager.h:100
This class manages all scene graphs.
Definition: rendering/Manager.h:31
void onRemoveEngine(const Engine *engine)
Callback function to inform this manager that an engine is not in use anymore.
bool unregisterEngine(const std::string &engine)
Unregisters a render engine.
void release()
Releases all registered rendering engines.
Lock lock_
Manager lock.
Definition: rendering/Manager.h:178
std::multimap< unsigned int, EngineInformation > EngineMap
Definition of a map mapping rendering engine priorities to engine information objects.
Definition: rendering/Manager.h:112
EngineRef engine(const std::string &engine=std::string(), const Engine::GraphicAPI graphicAPI=Engine::API_DEFAULT)
Returns a render engine of a specific scene graph.
std::vector< std::string > EngineNames
Definition of a vector holding engine names.
Definition: rendering/Manager.h:40
EngineNames engines()
Returns all names of registered engines.
virtual ~Manager()
Destructs the manager.
void registerEngine(const std::string &engineName, const Engine::CreateCallback &callback, const Engine::GraphicAPI graphicAPI, const unsigned int priority)
Registers a new render engine.
Engine::GraphicAPI supportedGraphicAPI(const std::string &engine)
Returns the graphic API supported by a specified engine.
EngineMap engineMap_
Registered engines.
Definition: rendering/Manager.h:175
This template class is the base class for all singleton objects.
Definition: Singleton.h:71
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15