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 #ifdef USE_GL
15 #include <gl/GLWidget.h>
16 #else
17 #include <vk/VKWidget.h>
18 #endif
19 #include <qmutex.h>
20 
21 #include <render/Engine.h>
22 #include <procedural/ProceduralSkybox.h>
23 
24 #include <OctreeConstants.h>
25 #include <shared/RateCounter.h>
26 
27 #include "FrameTimingsScriptingInterface.h"
28 
29 
30 struct AppRenderArgs {
31  render::Args _renderArgs;
32  glm::mat4 _eyeToWorld;
33  glm::mat4 _view;
34  glm::mat4 _eyeOffsets[2];
35  glm::mat4 _eyeProjections[2];
36  glm::mat4 _headPose;
37  glm::mat4 _sensorToWorld;
38  float _sensorToWorldScale{ 1.0f };
39  bool _isStereo{ false };
40 };
41 
42 using RenderArgsEditor = std::function <void(AppRenderArgs&)>;
43 
44 
45 class GraphicsEngine {
46 public:
47  GraphicsEngine();
48  ~GraphicsEngine();
49 
50 #ifdef USE_GL
51  void initializeGPU(GLWidget*);
52 #else
53  void initializeGPU(VKWidget*);
54 #endif
55  void initializeRender();
56  void startup();
57  void shutdown();
58 
59  render::ScenePointer getRenderScene() const { return _renderScene; }
60  render::EnginePointer getRenderEngine() const { return _renderEngine; }
61  gpu::ContextPointer getGPUContext() const { return _gpuContext; }
62 
63  // Same as the one in application
64  bool shouldPaint() const;
65  bool checkPendingRenderEvent();
66 
67  size_t getRenderFrameCount() const { return _renderFrameCount; }
68  float getRenderLoopRate() const { return _renderLoopCounter.rate(); }
69 
70  // Feed GRaphics Engine with new frame configuration
71  void editRenderArgs(RenderArgsEditor editor);
72 
73 private:
74  // Thread specific calls
75  void render_performFrame();
76  void render_runRenderFrame(RenderArgs* renderArgs);
77 
78 protected:
79 
80  mutable QRecursiveMutex _renderArgsMutex;
81  AppRenderArgs _appRenderArgs;
82 
83  RateCounter<500> _renderLoopCounter;
84 
85  uint32_t _renderFrameCount{ 0 };
86  render::ScenePointer _renderScene{ new render::Scene(glm::vec3(-0.5f * (float)TREE_SCALE), (float)TREE_SCALE) };
87  render::EnginePointer _renderEngine{ new render::RenderEngine() };
88 
89  gpu::ContextPointer _gpuContext; // initialized during window creation
90 
91  QObject* _renderEventHandler{ nullptr };
92  friend class RenderEventHandler;
93 
94  FrameTimingsScriptingInterface _frameTimingsScriptingInterface;
95 
96  std::shared_ptr<ProceduralSkybox> _splashScreen { std::make_shared<ProceduralSkybox>() };
97  NetworkTexturePointer _texture;
98 #ifndef Q_OS_ANDROID
99  std::atomic<bool> _programsCompiled { false };
100 #else
101  std::atomic<bool> _programsCompiled { true };
102 #endif
103 
104  friend class Application;
105 };
106 
107 #endif // hifi_GraphicsEngine_h
customized canvas that simply forwards requests/events to the singleton application
Definition: GLWidget.h:22
customized canvas that simply forwards requests/events to the singleton application
Definition: VKWidget.h:31