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 
33 struct AppRenderArgs {
34  render::Args _renderArgs;
35  glm::mat4 _eyeToWorld;
36  glm::mat4 _view;
37  glm::mat4 _eyeOffsets[2];
38  glm::mat4 _eyeProjections[2];
39  glm::mat4 _headPose;
40  glm::mat4 _sensorToWorld;
41  float _sensorToWorldScale{ 1.0f };
42  bool _isStereo{ false };
43 };
44 
45 using RenderArgsEditor = std::function <void(AppRenderArgs&)>;
46 
51 public:
53  ~GraphicsEngine();
54 
55 #ifdef USE_GL
62  void initializeGPU(GLWidget* primaryWidget);
63 #else
70  void initializeGPU(VKWidget* primaryWidget);
71 #endif
72 
77 
81  void startup();
82 
88  void shutdown();
89 
93  render::ScenePointer getRenderScene() const { return _renderScene; }
94 
98  render::EnginePointer getRenderEngine() const { return _renderEngine; }
99 
103  gpu::ContextPointer getGPUContext() const { return _gpuContext; }
104 
112  bool shouldPaint() const;
113 
121 
125  size_t getRenderFrameCount() const { return _renderFrameCount; }
126 
130  float getRenderLoopRate() const { return _renderLoopCounter.rate(); }
131 
136  void editRenderArgs(RenderArgsEditor editor);
137 
138 private:
139  // Thread specific calls
144  void render_performFrame();
145 
150  void render_runRenderFrame(RenderArgs* renderArgs);
151 
152 protected:
156  mutable QRecursiveMutex _renderArgsMutex;
157 
163 
167  RateCounter<500> _renderLoopCounter;
168 
172  uint32_t _renderFrameCount{ 0 };
173 
177  render::ScenePointer _renderScene{ new render::Scene(glm::vec3(-0.5f * (float)TREE_SCALE), (float)TREE_SCALE) };
178 
183  render::EnginePointer _renderEngine{ new render::RenderEngine() };
184 
188  gpu::ContextPointer _gpuContext; // initialized during window creation
189 
194  QObject* _renderEventHandler{ nullptr };
195 
196  friend class RenderEventHandler;
197 
201  FrameTimingsScriptingInterface _frameTimingsScriptingInterface;
202 
206  std::shared_ptr<ProceduralSkybox> _splashScreen { std::make_shared<ProceduralSkybox>() };
207 
211  NetworkTexturePointer _texture;
212 #ifndef Q_OS_ANDROID
217  std::atomic<bool> _programsCompiled { false };
218 #else
219  std::atomic<bool> _programsCompiled { true };
220 #endif
221 
222  friend class Application;
223 };
224 
225 #endif // hifi_GraphicsEngine_h
customized canvas that simply forwards requests/events to the singleton application
Definition: GLWidget.h:22
Definition: GraphicsEngine.h:50
gpu::ContextPointer getGPUContext() const
Definition: GraphicsEngine.h:103
void initializeGPU(GLWidget *primaryWidget)
Definition: GraphicsEngine.cpp:52
bool shouldPaint() const
render::ScenePointer _renderScene
Definition: GraphicsEngine.h:177
render::ScenePointer getRenderScene() const
Definition: GraphicsEngine.h:93
void initializeRender()
QRecursiveMutex _renderArgsMutex
Definition: GraphicsEngine.h:156
render::EnginePointer getRenderEngine() const
Definition: GraphicsEngine.h:98
FrameTimingsScriptingInterface _frameTimingsScriptingInterface
Definition: GraphicsEngine.h:201
QObject * _renderEventHandler
Definition: GraphicsEngine.h:194
NetworkTexturePointer _texture
Definition: GraphicsEngine.h:211
void initializeGPU(VKWidget *primaryWidget)
uint32_t _renderFrameCount
Definition: GraphicsEngine.h:172
size_t getRenderFrameCount() const
Definition: GraphicsEngine.h:125
bool checkPendingRenderEvent()
AppRenderArgs _appRenderArgs
Definition: GraphicsEngine.h:162
std::atomic< bool > _programsCompiled
Definition: GraphicsEngine.h:217
gpu::ContextPointer _gpuContext
Definition: GraphicsEngine.h:188
std::shared_ptr< ProceduralSkybox > _splashScreen
Definition: GraphicsEngine.h:206
RateCounter< 500 > _renderLoopCounter
Definition: GraphicsEngine.h:167
render::EnginePointer _renderEngine
Definition: GraphicsEngine.h:183
float getRenderLoopRate() const
Definition: GraphicsEngine.h:130
void editRenderArgs(RenderArgsEditor editor)
Definition: interface/src/graphics/RenderEventHandler.h:31
customized canvas that simply forwards requests/events to the singleton application
Definition: VKWidget.h:31
Definition: Args.h:100
Scene is a container for Items. Items are introduced, modified or erased in the scene through Transac...
Definition: Scene.h:274
Definition: GraphicsEngine.h:33