OVRWindow
 All Classes Functions Enumerations
OVRWindow.h
1 /*
2  * The MIT License (MIT)
3  *
4  * Copyright (c) 2014 Jeremy Othieno.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
31 #ifndef OVRWINDOW_H
32 #define OVRWINDOW_H
33 #define GL_GLEXT_PROTOTYPES
34 
35 #include <OVR_CAPI.h>
36 #include <QWindow>
37 #include <QOpenGLFunctions>
38 #include <QMatrix4x4>
39 
40 
41 union ovrGLConfig;
42 union ovrGLTexture_s;
43 typedef ovrGLTexture_s ovrGLTexture;
44 
45 class OVRWindow : public QWindow, protected QOpenGLFunctions
46 {
47 Q_OBJECT
48 public:
70  enum class Feature : unsigned int
71  {
72  LowPersistence = ovrHmdCap_LowPersistence,
73  LatencyTesting = ovrHmdCap_LatencyTest,
74  DynamicPrediction = ovrHmdCap_DynamicPrediction,
75 
76  OrientationTracking = ovrSensorCap_Orientation,
77  YawCorrection = ovrSensorCap_YawCorrection,
78  PositionalTracking = ovrSensorCap_Position,
79 
80  ChromaticAberrationCorrection = ovrDistortionCap_Chromatic,
81  Timewarp = ovrDistortionCap_TimeWarp,
82  Vignette = ovrDistortionCap_Vignette,
83  };
87  enum class Vision
88  {
89  Monocular,
90  Binocular
91  };
95  enum class LOD
96  {
97  Lowest,
98  Low,
99  Medium,
100  High,
101  Highest
102  };
110  {
111  QMatrix4x4 view;
112  struct
113  {
114  QMatrix4x4 perspective;
115  QMatrix4x4 ortho;
116  } projection;
117  };
128  OVRWindow(const unsigned int& index, const std::initializer_list<OVRWindow::Feature>& features);
136  OVRWindow();
140  virtual ~OVRWindow();
144  bool hasValidGL() const;
148  QOpenGLContext& getGL();
152  const ovrHmdDesc& getDeviceInfo() const;
156  const QSet<OVRWindow::Feature>& getEnabledFeatures() const;
162  void enableFeature(const OVRWindow::Feature& feature, const bool enable = true);
168  void enableFeatures(const std::initializer_list<OVRWindow::Feature>& features, const bool enable = true);
173  bool isFeatureEnabled(const OVRWindow::Feature& feature) const;
178  bool isFeatureSupported(const OVRWindow::Feature& feature) const;
182  const OVRWindow::Vision& getVision() const;
187  void setVision(const OVRWindow::Vision& vision);
191  const OVRWindow::LOD& getLOD() const;
199  void setLOD(const OVRWindow::LOD& lod);
206  void enableDynamicLOD(const bool enable = true);
210  float getIPD() const;
215  void setIPD(const float& ipd);
219  void forceZeroIPD(const bool& force);
223  const float& getPixelDensity() const;
227  void setPixelDensity(const float& density);
231  const float& getNearClippingDistance() const;
236  void setNearClippingDistance(const float& near);
240  const float& getFarClippingDistance() const;
245  void setFarClippingDistance(const float& far);
249  bool isMultisamplingEnabled() const;
254  void enableMultisampling(const bool enable = true);
255 protected:
259  virtual void initializeGL();
263  virtual void paintGL(const OVRWindow::FrameRenderContext& context, const float& dt);
270  virtual void resizeGL(const unsigned int& width, const unsigned int& height);
274  void makeCurrent();
278  void doneCurrent();
284  virtual void changeLOD(const OVRWindow::LOD& lod);
285 private:
289  void updateGL();
294  void requestUpdateGL();
298  void configureGL();
302  void paintGL();
306  ovrGLConfig& getOvrGlConfig() const;
310  ovrGLTexture& getOvrGlTexture(const ovrEyeType& eye) const;
314  void sanitizeRenderTargetConfiguration();
318  void sanitizeDeviceConfiguration();
322  void sanitizeRenderingConfiguration();
327  void adjustLOD(const float& dt, const unsigned int& tolerance);
332  void resizeEvent(QResizeEvent* const) override final;
337  void exposeEvent(QExposeEvent* const) override final;
342  bool event(QEvent* const) override final;
348  const OVRWindow::FrameRenderContext& getFrameRenderContext(const ovrEyeType& eye, const ovrPosef& pose);
352  const ovrHmdDesc _device;
356  QSet<OVRWindow::Feature> _enabledFeatures;
360  bool _enableDynamicLOD;
364  QOpenGLContext _gl;
368  bool _pendingUpdateRequest;
372  struct
373  {
374  GLuint fbo;
375  GLuint pixel;
376  GLuint depth;
377  QSize resolution;
378  } _renderTarget;
382  ovrFovPort _FOV[ovrEye_Count];
386  ovrEyeRenderDesc _renderInfo[ovrEye_Count];
390  OVRWindow::FrameRenderContext _frameRenderContext[ovrEye_Count];
394  float _nearClippingPlaneDistance;
398  float _farClippingPlaneDistance;
402  bool _forceZeroIPD;
406  float _pixelDensity;
410  OVRWindow::Vision _vision;
414  OVRWindow::LOD _LOD;
418  struct
419  {
420  bool renderTarget;
421  bool rendering;
422  struct { bool hmd, sensor; } device;
423  bool projections[ovrEye_Count];
424  } _dirty;
425 public slots:
429  void toggleVision();
433  void reduceLOD();
437  void increaseLOD();
441  void toggleDynamicLOD();
445  void toggleMultisampling();
446 signals:
450  void initialized();
455  void LODChanged(const OVRWindow::LOD& currentLOD);
456 };
457 
458 #endif // OVRWINDOW_H
void enableDynamicLOD(const bool enable=true)
Definition: OVRWindow.cpp:337
void setIPD(const float &ipd)
Definition: OVRWindow.cpp:374
float getIPD() const
Definition: OVRWindow.cpp:367
Vision
Definition: OVRWindow.h:87
void makeCurrent()
Definition: OVRWindow.cpp:157
void setVision(const OVRWindow::Vision &vision)
Definition: OVRWindow.cpp:264
void setFarClippingDistance(const float &far)
Definition: OVRWindow.cpp:439
const QSet< OVRWindow::Feature > & getEnabledFeatures() const
Return a set of all enabled features.
Definition: OVRWindow.cpp:178
void toggleMultisampling()
Toggle multisampling.
Definition: OVRWindow.cpp:470
void reduceLOD()
Reduce the interface's level of detail.
Definition: OVRWindow.cpp:344
void setNearClippingDistance(const float &near)
Definition: OVRWindow.cpp:420
bool isMultisamplingEnabled() const
Definition: OVRWindow.cpp:451
void doneCurrent()
Definition: OVRWindow.cpp:164
void toggleVision()
Toggle vision modes.
Definition: OVRWindow.cpp:275
void enableFeatures(const std::initializer_list< OVRWindow::Feature > &features, const bool enable=true)
Definition: OVRWindow.cpp:226
LOD
Definition: OVRWindow.h:95
void toggleDynamicLOD()
Toggle dynamic LOD.
Definition: OVRWindow.cpp:360
QOpenGLContext & getGL()
Return the OVRWindow's OpenGL context.
Definition: OVRWindow.cpp:150
void setLOD(const OVRWindow::LOD &lod)
Definition: OVRWindow.cpp:289
const float & getPixelDensity() const
Definition: OVRWindow.cpp:394
const OVRWindow::LOD & getLOD() const
Definition: OVRWindow.cpp:282
bool isFeatureSupported(const OVRWindow::Feature &feature) const
Definition: OVRWindow.cpp:241
virtual void resizeGL(const unsigned int &width, const unsigned int &height)
This virtual function is called whenever the window is resized.
Definition: OVRWindow.cpp:133
const float & getFarClippingDistance() const
Definition: OVRWindow.cpp:432
bool isFeatureEnabled(const OVRWindow::Feature &feature) const
Definition: OVRWindow.cpp:234
Definition: OVRWindow.h:45
const OVRWindow::Vision & getVision() const
Definition: OVRWindow.cpp:257
virtual ~OVRWindow()
The destructor.
Definition: OVRWindow.cpp:109
A frame's render context.
Definition: OVRWindow.h:109
void enableMultisampling(const bool enable=true)
Definition: OVRWindow.cpp:458
const ovrHmdDesc & getDeviceInfo() const
Return the Oculus Rift's information.
Definition: OVRWindow.cpp:171
virtual void paintGL(const OVRWindow::FrameRenderContext &context, const float &dt)
This virtual function is called whenever a new frame needs to be rendered.
Definition: OVRWindow.cpp:138
void increaseLOD()
Increase the interface's level of detail.
Definition: OVRWindow.cpp:352
void setPixelDensity(const float &density)
Definition: OVRWindow.cpp:401
void LODChanged(const OVRWindow::LOD &currentLOD)
bool hasValidGL() const
Returns true if the OVRWindow has a valid OpenGL context, false otherwise.
Definition: OVRWindow.cpp:143
void enableFeature(const OVRWindow::Feature &feature, const bool enable=true)
Definition: OVRWindow.cpp:185
Feature
Definition: OVRWindow.h:70
virtual void changeLOD(const OVRWindow::LOD &lod)
This virtual function is called whenever the level of detail (LOD) is changed.
Definition: OVRWindow.cpp:301
virtual void initializeGL()
Initialize OpenGL.
Definition: OVRWindow.cpp:128
OVRWindow()
Instantiate an OVRWindow object that is attached to an Oculus Rift device.
Definition: OVRWindow.cpp:93
void initialized()
const float & getNearClippingDistance() const
Definition: OVRWindow.cpp:413
void forceZeroIPD(const bool &force)
Definition: OVRWindow.cpp:382