Overte C++ Documentation
GraphicsEngine.h
1 //
2 // GraphicsEngine.h
3 //
4 // Created by Sam Gateau on 29/6/2018.
5 // Copyright 2018 High Fidelity, Inc.
6 //
7 // Distributed under the Apache License, Version 2.0.
8 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
9 //
10 #ifndef hifi_GraphicsEngine_h
11 #define hifi_GraphicsEngine_h
12 
13 #include <gl/OffscreenGLCanvas.h>
14 #include <gl/GLWidget.h>
15 #include <qmutex.h>
16 
17 #include <render/Engine.h>
18 #include <procedural/ProceduralSkybox.h>
19 
20 #include <OctreeConstants.h>
21 #include <shared/RateCounter.h>
22 
23 #include "FrameTimingsScriptingInterface.h"
24 
25 
26 struct AppRenderArgs {
27  render::Args _renderArgs;
28  glm::mat4 _eyeToWorld;
29  glm::mat4 _view;
30  glm::mat4 _eyeOffsets[2];
31  glm::mat4 _eyeProjections[2];
32  glm::mat4 _headPose;
33  glm::mat4 _sensorToWorld;
34  float _sensorToWorldScale{ 1.0f };
35  bool _isStereo{ false };
36 };
37 
38 using RenderArgsEditor = std::function <void(AppRenderArgs&)>;
39 
40 
41 class GraphicsEngine {
42 public:
43  GraphicsEngine();
44  ~GraphicsEngine();
45 
46  void initializeGPU(GLWidget*);
47  void initializeRender();
48  void startup();
49  void shutdown();
50 
51  render::ScenePointer getRenderScene() const { return _renderScene; }
52  render::EnginePointer getRenderEngine() const { return _renderEngine; }
53  gpu::ContextPointer getGPUContext() const { return _gpuContext; }
54 
55  // Same as the one in application
56  bool shouldPaint() const;
57  bool checkPendingRenderEvent();
58 
59  size_t getRenderFrameCount() const { return _renderFrameCount; }
60  float getRenderLoopRate() const { return _renderLoopCounter.rate(); }
61 
62  // Feed GRaphics Engine with new frame configuration
63  void editRenderArgs(RenderArgsEditor editor);
64 
65 private:
66  // Thread specific calls
67  void render_performFrame();
68  void render_runRenderFrame(RenderArgs* renderArgs);
69 
70 protected:
71 
72  mutable QRecursiveMutex _renderArgsMutex;
73  AppRenderArgs _appRenderArgs;
74 
75  RateCounter<500> _renderLoopCounter;
76 
77  uint32_t _renderFrameCount{ 0 };
78  render::ScenePointer _renderScene{ new render::Scene(glm::vec3(-0.5f * (float)TREE_SCALE), (float)TREE_SCALE) };
79  render::EnginePointer _renderEngine{ new render::RenderEngine() };
80 
81  gpu::ContextPointer _gpuContext; // initialized during window creation
82 
83  QObject* _renderEventHandler{ nullptr };
84  friend class RenderEventHandler;
85 
86  FrameTimingsScriptingInterface _frameTimingsScriptingInterface;
87 
88  std::shared_ptr<ProceduralSkybox> _splashScreen { std::make_shared<ProceduralSkybox>() };
89 #ifndef Q_OS_ANDROID
90  std::atomic<bool> _programsCompiled { false };
91 #else
92  std::atomic<bool> _programsCompiled { true };
93 #endif
94 
95  friend class Application;
96 };
97 
98 #endif // hifi_GraphicsEngine_h
customized canvas that simply forwards requests/events to the singleton application
Definition: GLWidget.h:22