Overte C++ Documentation
render/src/render/Engine.h
1 //
2 // Engine.h
3 // render/src/render
4 //
5 // Created by Sam Gateau on 3/3/15.
6 // Copyright 2014 High Fidelity, Inc.
7 // Copyright 2024 Overte e.V.
8 //
9 // Distributed under the Apache License, Version 2.0.
10 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
11 //
12 
13 #ifndef hifi_render_Engine_h
14 #define hifi_render_Engine_h
15 
16 #include <SettingHandle.h>
17 
18 #include <gpu/Batch.h>
19 #include <task/Task.h>
20 
21 #include "Scene.h"
22 
23 namespace render {
24 
25 
26 
27  class RenderContext : public task::JobContext {
28  public:
29  RenderContext() : task::JobContext() {}
30  virtual ~RenderContext() {}
31 
32  RenderArgs* args;
33  ScenePointer _scene;
34  };
35  using RenderContextPointer = std::shared_ptr<RenderContext>;
36 
37  Task_DeclareCategoryTimeProfilerClass(RenderTimeProfiler, trace_render);
38 
39  Task_DeclareTypeAliases(RenderContext, RenderTimeProfiler)
40 
41  // Versions of the COnfig integrating a gpu & batch timer
42  class GPUJobConfig : public JobConfig {
43  Q_OBJECT
44  Q_PROPERTY(double gpuRunTime READ getGPURunTime)
45  Q_PROPERTY(double batchRunTime READ getBatchRunTime)
46 
47  double _msGPURunTime { 0.0 };
48  double _msBatchRunTime { 0.0 };
49  public:
50  using Persistent = PersistentConfig<GPUJobConfig>;
51 
52  GPUJobConfig() = default;
53  GPUJobConfig(bool enabled) : JobConfig(enabled) {}
54 
55  // Running Time measurement on GPU and for Batch execution
56  void setGPUBatchRunTime(double msGpuTime, double msBatchTime) { _msGPURunTime = msGpuTime; _msBatchRunTime = msBatchTime; }
57  double getGPURunTime() const { return _msGPURunTime; }
58  double getBatchRunTime() const { return _msBatchRunTime; }
59  };
60 
61  class GPUTaskConfig : public TaskConfig {
62  Q_OBJECT
63  Q_PROPERTY(double gpuRunTime READ getGPURunTime)
64  Q_PROPERTY(double batchRunTime READ getBatchRunTime)
65 
66  double _msGPURunTime { 0.0 };
67  double _msBatchRunTime { 0.0 };
68  public:
69 
70  using Persistent = PersistentConfig<GPUTaskConfig>;
71 
72 
73  GPUTaskConfig() = default;
74  GPUTaskConfig(bool enabled) : render::TaskConfig(enabled) {}
75 
76  // Running Time measurement on GPU and for Batch execution
77  void setGPUBatchRunTime(double msGpuTime, double msBatchTime) { _msGPURunTime = msGpuTime; _msBatchRunTime = msBatchTime; }
78  double getGPURunTime() const { return _msGPURunTime; }
79  double getBatchRunTime() const { return _msBatchRunTime; }
80  };
81 
82 
83  // The render engine holds all render tasks, and is itself a render task.
84  // State flows through tasks to jobs via the render and scene contexts -
85  // the engine should not be known from its jobs.
86  class RenderEngine : public Engine {
87  public:
88 
89  enum TransformSlot : uint8_t {
90  TS_MAIN_VIEW = 0,
91  TS_BACKGROUND_VIEW
92  };
93 
94  RenderEngine();
95  ~RenderEngine() = default;
96 
97  // Load any persisted settings, and set up the presets
98  // This should be run after adding all jobs, and before building ui
99  void load();
100 
101  // Register the scene
102  void registerScene(const ScenePointer& scene) { _context->_scene = scene; }
103 
104  // acces the RenderContext
105  RenderContextPointer getRenderContext() const { return _context; }
106 
107  protected:
108  };
109  using EnginePointer = std::shared_ptr<RenderEngine>;
110 
111 }
112 
113 #endif // hifi_render_Engine_h