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