AnnOgreVRRenderer.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "systemMacro.h"
4 
5 #include <string>
6 #include <array>
7 #include <algorithm>
8 
9 #include <Ogre.h>
10 
11 #include <GL/glew.h>
12 #include <GLFW/glfw3.h>
13 
14 #include <AnnTypes.h>
15 
16 #include <Compositor/OgreCompositorManager2.h>
17 
18 #ifndef _WIN32
19 using GUID = void*;
20 #endif
21 
22 namespace Annwvyn
23 {
24  class AnnHandController;
26 
27  constexpr const size_t MAX_CONTROLLER_NUMBER = 2;
28 
30  struct AnnPose
31  {
34 
37  };
38 
40 
43  {
44  public:
46 
48 #ifndef _DEBUG
49  static constexpr const char* const PluginRenderSystemGL3Plus { "./RenderSystem_GL3Plus" };
50 #ifdef _WIN32
51  static constexpr const char* const Ogre_glTF_Plugin { "./Ogre_glTF" };
52 #else
53  static constexpr const char* const Ogre_glTF_Plugin { "./libOgre_glTF.so" };
54 #endif
55 #else
56  static constexpr const char* const PluginRenderSystemGL3Plus { "./RenderSystem_GL3Plus_d" };
57 #ifdef _WIN32
58  static constexpr const char* const Ogre_glTF_Plugin { "./Ogre_glTF_d" };
59 #else
60  static constexpr const char* const Ogre_glTF_Plugin { "./libOgre_glTF_d.so" };
61 #endif
62 #endif
63 
65  static constexpr const char* const GLRenderSystem3Plus { "OpenGL 3+ Rendering Subsystem" };
67  static constexpr const char* const RESOURCE_GROUP_COMPOSITOR = "RG_ANN_COMPOSITOR";
68 
70  const size_t numberOfThreads;
71 
73  enum compositorIndex : size_t {
74  leftEyeCompositor = 0,
75  rightEyeCompositor = 1,
76  monoCompositor = 2,
77  nbCompositor = 3,
78  };
79 
81  enum class ShadowFiltering {
82  low,
83  medium,
84  high
85  };
86 
88  void setShadowFiltering(ShadowFiltering level) const;
89 
92  static void setAntiAliasingLevel(uint8_t AA);
93 
95  enum DebugMode {
99  };
100 
102  AnnOgreVRRenderer(const std::string& windowName);
103 
105  virtual ~AnnOgreVRRenderer();
106 
108  Ogre::SceneManager* getSceneManager() const;
109 
111  Ogre::Root* getRoot() const;
112 
114  Ogre::RenderWindow* getWindow() const;
115 
117  Ogre::SceneNode* getCameraInformationNode() const;
118 
120  Ogre::Timer* getTimer() const;
121 
123  double getUpdateTime() const;
124 
126  void getOgreConfig() const;
127 
130  void initOgreRoot(const std::string& loggerName);
131 
133  virtual void initPipeline() final;
134 
136  virtual void initVrHmd() = 0;
137 
139  virtual void initScene() = 0;
140 
142  virtual void initCameras();
143 
145  virtual void initRttRendering() = 0;
146 
148  virtual void initClientHmdRendering() = 0;
149 
151  virtual bool shouldQuit() = 0;
152 
154  virtual bool shouldRecenter() = 0;
155 
157  virtual bool isVisibleInHmd() = 0;
158 
160  virtual void updateTracking() final;
161 
163  virtual void getTrackingPoseAndVRTiming() = 0;
164 
166  virtual void renderAndSubmitFrame() = 0;
167 
169  virtual void recenter() = 0;
170 
172  virtual void cycleDebugHud() {};
173 
175  void setNearClippingDistance(float distance);
176 
178  void setFarClippingDistance(float distance);
179 
181  static void detachCameraFromParent(Ogre::Camera* camera);
182 
185  virtual void updateEyeCameraFrustrum() = 0;
186 
188  virtual bool usesCustomAudioDevice() { return false; }
189 
192 
195 
197  virtual void showDebug(DebugMode mode) = 0;
198 
200  std::array<AnnHandControllerPtr, MAX_CONTROLLER_NUMBER> getHandControllerArray() const;
201 
203  static size_t getHanControllerArraySize();
204 
206  bool handControllersAvailable() const;
207 
209  static void makeValidPath(std::string& hlmsFolder);
210 
212  virtual void handleIPDChange() = 0;
213 
215  void applyCameraRigPose(AnnPose pose) const;
216 
218  void syncGameplayBody();
219 
222  void calculateTimingFromOgre();
223 
225  static void loadOpenGLFunctions();
226 
228  unsigned int createCombinedRenderTexture(unsigned int w, unsigned int h);
229 
231  GLuintPair createSeparatedRenderTextures(const combinedTextureSizeArray& textureSizes);
232 
234  std::tuple<Ogre::TexturePtr, unsigned int> createAdditionalRenderBuffer(unsigned int w, unsigned int h, std::string name = "") const;
235 
237  void createWindow(unsigned int w = 1280, unsigned int h = 720, bool vsync = false);
238 
240  std::string getName() const;
241 
243  void loadHLMSLibrary(std::string path = "./hlms/");
244 
246  void loadCompositor(const std::string& path = "./compositor/", const std::string& type = "FileSystem");
247 
249  void setSkyColor(Ogre::ColourValue skyColor, float multiplier, const char* renderingNodeName) const;
250 
252  void setExposure(float exposure, float minAuto, float maxAuto, const char* postProcessMaterial = "HDR/DownScale03_SumLumEnd") const;
253 
255  void setBloomThreshold(float minThreshold, float fullColorThreshold, const char* brightnessPassMaterial = "HDR/BrightPass_Start");
256 
258  void createMainSmgr();
259 
261  bool shouldPauseFlag() const;
262 
264  bool shouldHideHands() const;
265 
267  static void glEasyCopy(GLuint source, GLuint dest, GLuint width, GLuint height);
268 
270  void _resetOgreTimer() const;
271 
273  bool isCompositorLoaded() const;
274 
276  bool isHlmsLibLoaded() const;
277 
279  static std::string getAudioDeviceNameFromGUID(GUID guid);
280 
281  private:
283  const GLuint glMajor, glMinor;
284 
286  GLFWwindow* glfwWindow;
287 
289  static constexpr const char* const SL { "GLSL" };
290 
292  int windowW, windowH;
293 
294  protected:
295  void doStereoRender();
296 
298  void handleWindowMessages();
299 
302 
305 
307  void changedAA() const;
308 
310  static AnnOgreVRRenderer* self;
311 
313  Ogre::SceneManager* smgr;
314 
317 
319  Ogre::RenderWindow* window;
320 
322  double updateTime, then, now;
323 
326 
329 
331  Ogre::Vector3 feetPosition;
332 
334  Ogre::Quaternion bodyOrientation;
335 
338 
340  Ogre::SceneNode* gameplayCharacterRoot;
341 
344 
346  Ogre::Camera* monoCam;
347 
349  Ogre::SceneNode* cameraRig;
350 
353 
355  Ogre::RenderTexture* rttEyesCombined;
356 
359 
361  static uint8_t AALevel;
362 
365 
367  std::array<std::vector<byte>, 2> currentControllerButtonsPressed, lastControllerButtonsPressed;
368 
371 
373  static constexpr const char* const rttTextureName = { "RttTex" };
374 
376  bool pauseFlag;
377 
379  bool hideHands;
380 
383 
386 
387  private:
389  enum side : uint8_t { left = 0x0,
390  right = 0x1 };
391  };
392 
394 }
std::unique_ptr< Ogre::Root > root
Ogre root object.
DebugMode
Type of Debug render you can do.
file for defining macros used for symbol export regarding the way the OS does things.
virtual bool usesCustomAudioDevice()
(Optional) return true if audio has to come out from a specific audio device
bool compositorLoaded
Compositor resources loaded.
Abstract class for VR Renderers. Serve as interface between Annwvyn, and "OgreHMDRender" object...
AnnVect3 position
A 3D vector representing a position.
std::shared_ptr< AnnHandController > AnnHandControllerPtr
uID frameCounter
Counter of frames.
std::string name
Name of the window.
constexpr const size_t MAX_CONTROLLER_NUMBER
AnnPose trackedHeadPose
The current position of the head center defined by the client library projected in World Space...
const size_t numberOfThreads
number of hardware threads
A 3D Vector.
Definition: AnnVect3.hpp:16
Ogre::Quaternion bodyOrientation
Orientation of the head.
Namespace containing the totality of Annwvyn components.
Definition: AnnGetter.cpp:8
Ogre::Vector3 feetPosition
Position of the head.
A pose refer to the combination of a position and an orientation. It permit to define the placement o...
std::vector< uint8_t > released
bool hideHands
Store if we should hide the hands.
Ogre::Camera * monoCam
Monoscopic camera.
unsigned long long uID
Definition: AnnTypes.h:39
Ogre::Real farClippingDistance
Distance between eyeCamera and farClippingDistance.
AnnQuaternion orientation
A quaternion representing an orientation.
Ogre::RenderWindow * window
Render window. VR isn&#39;t drawn to this window. A window is mandatory to init the RenderSystem.
Represent a Quaternion.
virtual std::string getAudioDeviceIdentifierSubString()
(Optional) return the sub string to search on the audio device list to get the correct one ...
std::array< Ogre::CompositorWorkspace *, nbCompositor > compositorWorkspaces
Compositor workspaces. 0 = left, 1 = right, 2 = monoscopic, plugged to the render window...
std::array< std::vector< byte >, 2 > lastControllerButtonsPressed
ShadowFiltering
Liist of the levels of shadow filtering available.
Ogre::RenderTexture * rttEyesCombined
Render target that serve as intermediate buffer for the eyeCameras.
std::string rendererName
Name of the renderer object.
Ogre::SceneNode * gameplayCharacterRoot
Node that represent the head base. Move this in 3D to move the viewpoint.
Data types definition for Annwvyn.
#define AnnDllExport
Definition: systemMacro.h:24
void * GUID
Ogre::Real nearClippingDistance
Distance between eyeCamera and nearClippingDistance.
double updateTime
Update Time.
std::array< AnnHandControllerPtr, MAX_CONTROLLER_NUMBER > handControllers
Array of hand controller.
Ogre::SceneManager * smgr
SceneManager of the VR world.
GLFWwindow * glfwWindow
GL FrameWork window.
compositorIndex
Indexes of the compositor workspace.
bool pauseFlag
Store if we suggest you to pause reacting to user inputs...
Ogre::SceneNode * cameraRig
Camera rig, node where all the cameras are attached.
std::array< Ogre::Camera *, 2 > eyeCameras
Cameras that have to be put where the user&#39;s eye is.
static uint8_t AALevel
Level of anti aliasing to use.
bool hlmsLoaded
Compositor resources loaded.
std::array< Ogre::RenderTexture *, 2 > rttEyeSeparated
Couple of render textures separated.