Torque3D Documentation / _generateds / oculusVRHMDDevice.h

oculusVRHMDDevice.h

Engine/source/platform/input/oculusVR/oculusVRHMDDevice.h

More...

Classes:

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _OCULUSVRHMDDEVICE_H_
 25#define _OCULUSVRHMDDEVICE_H_
 26
 27#include "core/util/str.h"
 28#include "math/mQuat.h"
 29#include "math/mPoint2.h"
 30#include "math/mPoint3.h"
 31#include "math/mPoint4.h"
 32#include "platform/input/oculusVR/oculusVRConstants.h"
 33#include "platform/types.h"
 34#include "gfx/gfxTextureHandle.h"
 35#include "math/mRect.h"
 36#include "gfx/gfxDevice.h"
 37
 38#include "OVR_CAPI.h"
 39
 40class GuiCanvas;
 41class GameConnection;
 42struct DisplayPose;
 43class OculusVRSensorDevice;
 44struct OculusTexture;
 45
 46
 47class OculusVRHMDDevice
 48{
 49public:
 50   enum SimulationTypes {
 51      ST_RIFT_PREVIEW,
 52   };
 53
 54protected:
 55   bool mIsValid;
 56
 57   bool mVsync;
 58   bool mTimewarp;
 59
 60   bool mRenderConfigurationDirty;
 61   bool mFrameReady;
 62
 63   ovrHmd mDevice;
 64
 65   U32 mSupportedCaps;
 66   U32 mCurrentCaps;
 67
 68   // From OVR::DeviceInfo
 69   String   mProductName;
 70   String   mManufacturer;
 71   U32      mVersion;
 72
 73   // Device type (D3D11, etc)
 74   String   mDisplayDeviceType;
 75
 76   // Adapter index
 77   S32      mDisplayId;
 78
 79   // Whole screen resolution
 80   Point2I  mResolution;
 81
 82   // Physical screen size in meters
 83   Point2F  mScreenSize;
 84
 85   // Physical distance between lens centers, in meters
 86   F32      mLensSeparation;
 87
 88   // Physical distance between the user's eye centers as defined in the current profile
 89   F32      mProfileInterpupillaryDistance;
 90
 91   // Physical distance between the user's eye centers
 92   F32      mInterpupillaryDistance;
 93
 94   // The amount to offset the projection matrix to account for the eye not being in the
 95   // center of the screen.
 96   Point2F mProjectionCenterOffset;
 97
 98   // Current pose of eyes
 99   ovrEyeRenderDesc mEyeRenderDesc[2];
100
101   GameConnection *mConnection;
102
103   OculusVRSensorDevice *mSensor;
104   U32 mActionCodeIndex;
105
106   ovrGraphicsLuid mLuid;
107
108protected:
109   void updateRenderInfo();
110
111public:
112   OculusVRHMDDevice();
113   ~OculusVRHMDDevice();
114
115   void cleanUp();
116
117   // Set the HMD properties based on information from the OVR device
118   void set(ovrHmd hmd, ovrGraphicsLuid luid, U32 actionCodeIndex);
119
120   // Sets optimal display size for canvas
121   void setOptimalDisplaySize(GuiCanvas *canvas);
122
123   bool isValid() const {return mIsValid;}
124
125   const char* getProductName() const { return mProductName.c_str(); }
126   const char* getManufacturer() const { return mManufacturer.c_str(); }
127   U32 getVersion() const { return mVersion; }
128
129   // Windows display device name used in EnumDisplaySettings/CreateDC
130   const char* getDisplayDeviceType () const { return mDisplayDeviceType.c_str(); }
131
132   // MacOS display ID
133   S32 getDisplayDeviceId() const { return mDisplayId; }
134
135   // Whole screen resolution
136   const Point2I& getResolution() const { return mResolution; }
137
138   // Physical screen size in meters
139   const Point2F& getScreenSize() const { return mScreenSize; }
140
141   // Physical distance between lens centers, in meters
142   F32 getLensSeparation() const { return mLensSeparation; }
143
144   // Physical distance between the user's eye centers as defined by the current profile
145   F32 getProfileIPD() const { return mProfileInterpupillaryDistance; }
146
147   // Physical distance between the user's eye centers
148   F32 getIPD() const { return mInterpupillaryDistance; }
149
150   // Set a new physical distance between the user's eye centers
151   void setIPD(F32 ipd);
152
153   // The amount to offset the projection matrix to account for the eye not being in the
154   // center of the screen.
155   const Point2F& getProjectionCenterOffset() const { return mProjectionCenterOffset; }
156   
157   void getStereoViewports(RectI *dest) const { dMemcpy(dest, mEyeViewport, sizeof(mEyeViewport)); }
158   void getStereoTargets(GFXTextureTarget **dest) const { dest[0] = mEyeRT[0]; dest[1] = mEyeRT[1]; }
159
160   void getFovPorts(FovPort *dest) const { dMemcpy(dest, &mRenderLayer.Fov[0], sizeof(mRenderLayer.Fov)); }
161   
162   /// Returns eye offsets in torque coordinate space, i.e. z being up, x being left-right, and y being depth (forward).
163   void getEyeOffsets(Point3F *offsets) const { 
164      offsets[0] = Point3F(-mEyeRenderDesc[0].HmdToEyeViewOffset.x, mEyeRenderDesc[0].HmdToEyeViewOffset.z, -mEyeRenderDesc[0].HmdToEyeViewOffset.y); 
165      offsets[1] = Point3F(-mEyeRenderDesc[1].HmdToEyeViewOffset.x, mEyeRenderDesc[1].HmdToEyeViewOffset.z, -mEyeRenderDesc[1].HmdToEyeViewOffset.y); }
166
167   void getFrameEyePose(DisplayPose *outPose, U32 eyeId) const;
168
169   void updateCaps();
170
171   void onStartFrame();
172   void onEndFrame();
173   void onDeviceDestroy();
174
175   Point2I generateRenderTarget(GFXTextureTargetRef &target, GFXTexHandle &depth, Point2I desiredSize);
176   void clearRenderTargets();
177
178   bool isDisplayingWarning();
179   void dismissWarning();
180
181   bool setupTargets();
182
183   /// Designates canvas we are drawing to. Also updates render targets
184   void setDrawCanvas(GuiCanvas *canvas) { if (mDrawCanvas != canvas) { mDrawCanvas = canvas; } updateRenderInfo(); }
185
186   virtual void setCurrentConnection(GameConnection *connection) { mConnection = connection; }
187   virtual GameConnection* getCurrentConnection() { return mConnection; }
188
189   GFXTexHandle getPreviewTexture();
190
191   String dumpMetrics();
192
193   // Stereo RT
194   GFXTexHandle mDebugStereoTexture;
195   GFXTexHandle mStereoDepthTexture;
196   GFXTextureTargetRef mStereoRT;
197
198   // Eye RTs (if we are using separate targets)
199   GFXTextureTargetRef mEyeRT[2];
200
201   // Desired viewport for each eye
202   RectI mEyeViewport[2];
203
204   F32 mCurrentPixelDensity;
205   F32 smDesiredPixelDensity;
206
207   ovrTrackingState mLastTrackingState;
208   OculusTexture* mTextureSwapSet;
209   ovrLayerEyeFov mRenderLayer;
210   ovrLayerDirect mDebugRenderLayer;
211   ovrViewScaleDesc mScaleDesc;
212   ovrTexture* mDebugMirrorTexture;
213   GFXTexHandle mDebugMirrorTextureHandle;
214
215   GFXDevice::GFXDeviceRenderStyles mDesiredRenderingMode;
216
217   GFXFormat mRTFormat;
218
219   // Canvas we should be drawing
220   GuiCanvas *mDrawCanvas;
221
222   OculusVRSensorDevice *getSensorDevice() { return mSensor; }
223};
224
225#endif   // _OCULUSVRHMDDEVICE_H_
226