aboutsummaryrefslogtreecommitdiffstats
path: root/LibOVR/Src/OVR_Stereo.h
diff options
context:
space:
mode:
Diffstat (limited to 'LibOVR/Src/OVR_Stereo.h')
-rw-r--r--LibOVR/Src/OVR_Stereo.h255
1 files changed, 238 insertions, 17 deletions
diff --git a/LibOVR/Src/OVR_Stereo.h b/LibOVR/Src/OVR_Stereo.h
index dd5499c..f002d14 100644
--- a/LibOVR/Src/OVR_Stereo.h
+++ b/LibOVR/Src/OVR_Stereo.h
@@ -1,21 +1,20 @@
/************************************************************************************
-PublicHeader: OVR.h
Filename : OVR_Stereo.h
Content : Stereo rendering functions
Created : November 30, 2013
Authors : Tom Fosyth
-Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved.
+Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved.
-Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License");
+Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
you may not use the Oculus VR Rift SDK except in compliance with the License,
which is provided at the time of installation or download, or which
otherwise accompanies this software in either electronic or hard copy form.
You may obtain a copy of the License at
-http://www.oculusvr.com/licenses/LICENSE-3.1
+http://www.oculusvr.com/licenses/LICENSE-3.2
Unless required by applicable law or agreed to in writing, the Oculus VR SDK
distributed under the License is distributed on an "AS IS" BASIS,
@@ -28,7 +27,9 @@ limitations under the License.
#ifndef OVR_Stereo_h
#define OVR_Stereo_h
-#include "OVR_Device.h"
+#include "Sensors/OVR_DeviceConstants.h"
+#include "Displays/OVR_Display.h"
+#include "OVR_Profile.h"
// CAPI Forward declaration.
typedef struct ovrFovPort_ ovrFovPort;
@@ -36,6 +37,9 @@ typedef struct ovrRecti_ ovrRecti;
namespace OVR {
+class SensorDevice; // Opaque forward declaration
+
+
//-----------------------------------------------------------------------------------
// ***** Stereo Enumerations
@@ -78,7 +82,6 @@ struct FovPort
FovPort(const ovrFovPort& src);
operator ovrFovPort () const;
-
static FovPort CreateFromRadians(float horizontalFov, float verticalFov)
{
FovPort result;
@@ -134,7 +137,6 @@ struct FovPort
};
-
//-----------------------------------------------------------------------------------
// ***** ScaleAndOffset
@@ -173,6 +175,20 @@ bool FitCubicPolynomial ( float *pResult, const float *pFitX, const float *pFitY
// caused by the Rift lenses.
struct LensConfig
{
+ LensConfig()
+ : Eqn(Distortion_CatmullRom10)
+ //K()
+ , MaxR(0.0f)
+ , MetersPerTanAngleAtCenter(0.0f)
+ //ChromaticAberration()
+ //InvK()
+ , MaxInvR(0.0f)
+ {
+ memset(&K, 0, sizeof(K));
+ memset(&ChromaticAberration, 0, sizeof(ChromaticAberration));
+ memset(&InvK, 0, sizeof(InvK));
+ }
+
// The result is a scaling applied to the distance from the center of the lens.
float DistortionFnScaleRadiusSquared (float rsq) const;
// x,y,z components map to r,g,b scales.
@@ -222,12 +238,12 @@ struct LensConfig
// For internal use - storing and loading lens config data
// Returns true on success.
-bool LoadLensConfig ( LensConfig *presult, UByte const *pbuffer, int bufferSizeInBytes );
+bool LoadLensConfig ( LensConfig *presult, uint8_t const *pbuffer, int bufferSizeInBytes );
// Returns number of bytes needed.
int SaveLensConfigSizeInBytes ( LensConfig const &config );
// Returns true on success.
-bool SaveLensConfig ( UByte *pbuffer, int bufferSizeInBytes, LensConfig const &config );
+bool SaveLensConfig ( uint8_t *pbuffer, int bufferSizeInBytes, LensConfig const &config );
//-----------------------------------------------------------------------------------
@@ -248,6 +264,197 @@ struct DistortionRenderDesc
};
+//-------------------------------------------------------------------------------------
+// ***** HMDInfo
+
+// This structure describes various aspects of the HMD allowing us to configure rendering.
+//
+// Currently included data:
+// - Physical screen dimensions, resolution, and eye distances.
+// (some of these will be configurable with a tool in the future).
+// These arguments allow us to properly setup projection across HMDs.
+// - DisplayDeviceName for identifying HMD screen; system-specific interpretation.
+//
+// TBD:
+// - Power on/ off?
+// - Sensor rates and capabilities
+// - Distortion radius/variables
+// - Screen update frequency
+// - Distortion needed flag
+// - Update modes:
+// Set update mode: Stereo (both sides together), mono (same in both eyes),
+// Alternating, Alternating scan-lines.
+
+// Win32 Oculus VR Display Driver Shim Information
+struct Win32ShimInfo
+{
+ int DeviceNumber;
+ int NativeWidth;
+ int NativeHeight;
+ int Rotation;
+ int UseMirroring;
+
+ Win32ShimInfo() :
+ DeviceNumber(-1),
+ NativeWidth(-1),
+ NativeHeight(-1),
+ Rotation(-1),
+ UseMirroring(1)
+ {
+ }
+};
+
+class HMDInfo
+{
+public:
+ // Name string describing the product: "Oculus Rift DK1", etc.
+ String ProductName;
+ String Manufacturer;
+
+ unsigned Version;
+
+ // Characteristics of the HMD screen and enclosure
+ HmdTypeEnum HmdType;
+ Size<int> ResolutionInPixels;
+ Size<float> ScreenSizeInMeters;
+ float ScreenGapSizeInMeters;
+ float CenterFromTopInMeters;
+ float LensSeparationInMeters;
+ Vector2f PelOffsetR; // Offsets from the green pel in pixels (i.e. usual values are 0.5 or 0.333)
+ Vector2f PelOffsetB;
+
+
+ // Timing & shutter data. All values in seconds.
+ struct ShutterInfo
+ {
+ HmdShutterTypeEnum Type;
+ float VsyncToNextVsync; // 1/framerate
+ float VsyncToFirstScanline; // for global shutter, vsync->shutter open.
+ float FirstScanlineToLastScanline; // for global shutter, will be zero.
+ float PixelSettleTime; // estimated.
+ float PixelPersistence; // Full persistence = 1/framerate.
+ } Shutter;
+
+ // Desktop coordinate position of the screen (can be negative; may not be present on all platforms)
+ int DesktopX;
+ int DesktopY;
+
+ // Windows:
+ // "\\\\.\\DISPLAY3", etc. Can be used in EnumDisplaySettings/CreateDC.
+ String DisplayDeviceName;
+ Win32ShimInfo ShimInfo;
+
+ // MacOS:
+ int DisplayId;
+
+ bool InCompatibilityMode;
+
+ // Printed serial number for the HMD; should match external sticker
+ String PrintedSerial;
+
+ // Tracker descriptor information:
+ int VendorId;
+ int ProductId;
+ int FirmwareMajor;
+ int FirmwareMinor;
+
+ float CameraFrustumHFovInRadians;
+ float CameraFrustumVFovInRadians;
+ float CameraFrustumNearZInMeters;
+ float CameraFrustumFarZInMeters;
+
+ // Constructor initializes all values to 0s.
+ // To create a "virtualized" HMDInfo, use CreateDebugHMDInfo instead.
+ HMDInfo() :
+ ProductName(),
+ Manufacturer(),
+ Version(0),
+ HmdType(HmdType_None),
+ ResolutionInPixels(0),
+ ScreenSizeInMeters(0.0f),
+ ScreenGapSizeInMeters(0.0f),
+ CenterFromTopInMeters(0),
+ LensSeparationInMeters(0),
+ PelOffsetR(0.0f,0.0f),
+ PelOffsetB(0.0f,0.0f),
+ //Shutter (initialized below)
+ DesktopX(0),
+ DesktopY(0),
+ DisplayDeviceName(),
+ ShimInfo(),
+ DisplayId(-1),
+ InCompatibilityMode(false),
+ PrintedSerial(),
+ VendorId(-1),
+ ProductId(-1),
+ FirmwareMajor(-1),
+ FirmwareMinor(-1),
+ CameraFrustumHFovInRadians(0.0f),
+ CameraFrustumVFovInRadians(0.0f),
+ CameraFrustumNearZInMeters(0.0f),
+ CameraFrustumFarZInMeters(0.0f)
+ {
+ Shutter.Type = HmdShutter_LAST;
+ Shutter.VsyncToNextVsync = 0.0f;
+ Shutter.VsyncToFirstScanline = 0.0f;
+ Shutter.FirstScanlineToLastScanline = 0.0f;
+ Shutter.PixelSettleTime = 0.0f;
+ Shutter.PixelPersistence = 0.0f;
+ }
+
+ // Operator = copies local fields only (base class must be correct already)
+ void operator=(const HMDInfo& src)
+ {
+ ProductName = src.ProductName;
+ Manufacturer = src.Manufacturer;
+ Version = src.Version;
+ HmdType = src.HmdType;
+ ResolutionInPixels = src.ResolutionInPixels;
+ ScreenSizeInMeters = src.ScreenSizeInMeters;
+ ScreenGapSizeInMeters = src.ScreenGapSizeInMeters;
+ CenterFromTopInMeters = src.CenterFromTopInMeters;
+ LensSeparationInMeters = src.LensSeparationInMeters;
+ PelOffsetR = src.PelOffsetR;
+ PelOffsetB = src.PelOffsetB;
+ DesktopX = src.DesktopX;
+ DesktopY = src.DesktopY;
+ Shutter = src.Shutter;
+ DisplayDeviceName = src.DisplayDeviceName;
+ ShimInfo = src.ShimInfo;
+ DisplayId = src.DisplayId;
+ InCompatibilityMode = src.InCompatibilityMode;
+ VendorId = src.VendorId;
+ ProductId = src.ProductId;
+ FirmwareMajor = src.FirmwareMajor;
+ FirmwareMinor = src.FirmwareMinor;
+ PrintedSerial = src.PrintedSerial;
+ CameraFrustumHFovInRadians = src.CameraFrustumHFovInRadians;
+ CameraFrustumVFovInRadians = src.CameraFrustumVFovInRadians;
+ CameraFrustumNearZInMeters = src.CameraFrustumNearZInMeters;
+ CameraFrustumFarZInMeters = src.CameraFrustumFarZInMeters;
+ }
+
+ void SetScreenParameters(int hres, int vres,
+ float hsize, float vsize,
+ float vCenterFromTopInMeters, float lensSeparationInMeters,
+ bool compatibilityMode)
+ {
+ ResolutionInPixels = Sizei(hres, vres);
+ ScreenSizeInMeters = Sizef(hsize, vsize);
+ CenterFromTopInMeters = vCenterFromTopInMeters;
+ LensSeparationInMeters = lensSeparationInMeters;
+ InCompatibilityMode = compatibilityMode;
+ }
+
+ bool IsSameDisplay(const HMDInfo& o) const
+ {
+ return DisplayId == o.DisplayId &&
+ DisplayDeviceName.CompareNoCase(o.DisplayDeviceName) == 0;
+ }
+
+ static bool CreateFromSensorAndDisplay(SensorDevice* sensor, Display* display, HMDInfo* hmdi);
+};
+
//-----------------------------------------------------------------------------------
// ***** HmdRenderInfo
@@ -256,7 +463,7 @@ struct DistortionRenderDesc
struct HmdRenderInfo
{
- // The start of this sturucture is intentionally very similar to HMDInfo in OVER_Device.h
+ // The start of this structure is intentionally very similar to HMDInfo in OVER_Device.h
// However to reduce interdependencies, one does not simply #include the other.
HmdTypeEnum HmdType;
@@ -265,6 +472,8 @@ struct HmdRenderInfo
Size<int> ResolutionInPixels;
Size<float> ScreenSizeInMeters;
float ScreenGapSizeInMeters;
+ Vector2f PelOffsetR; // Offsets from the green pel in pixels (i.e. usual values are 0.5 or 0.333)
+ Vector2f PelOffsetB;
// Characteristics of the lenses.
float CenterFromTopInMeters;
@@ -309,6 +518,8 @@ struct HmdRenderInfo
LensSeparationInMeters = 0.0f;
LensDiameterInMeters = 0.0f;
LensSurfaceToMidplateInMeters = 0.0f;
+ PelOffsetR = Vector2f ( 0.0f, 0.0f );
+ PelOffsetB = Vector2f ( 0.0f, 0.0f );
Shutter.Type = HmdShutter_LAST;
Shutter.VsyncToNextVsync = 0.0f;
Shutter.VsyncToFirstScanline = 0.0f;
@@ -336,14 +547,12 @@ struct HmdRenderInfo
};
-
-
//-----------------------------------------------------------------------------------
// Stateless computation functions, in somewhat recommended execution order.
// For examples on how to use many of them, see the StereoConfig::UpdateComputedState function.
-const float OVR_DEFAULT_EXTRA_EYE_ROTATION = 30.0f * Math<float>::DegreeToRadFactor;
+const float OVR_DEFAULT_EXTRA_EYE_ROTATION = 30.0f * MATH_FLOAT_DEGREETORADFACTOR;
// Creates a dummy debug HMDInfo matching a particular HMD model.
// Useful for development without an actual HMD attached.
@@ -409,7 +618,7 @@ ScaleAndOffset2D CreateUVScaleAndOffsetfromNDCScaleandOffset ( ScaleAndOffset
struct StereoEyeParams
{
StereoEye Eye;
- Matrix4f ViewAdjust; // Translation to be applied to view matrix.
+ Matrix4f HmdToEyeViewOffset; // Translation to be applied to view matrix.
// Distortion and the VP on the physical display - the thing to run the distortion shader on.
DistortionRenderDesc Distortion;
@@ -431,9 +640,9 @@ Vector2f TransformScreenNDCToTanFovSpace ( DistortionRenderDesc const &distortio
void TransformScreenNDCToTanFovSpaceChroma ( Vector2f *resultR, Vector2f *resultG, Vector2f *resultB,
DistortionRenderDesc const &distortion,
const Vector2f &framebufferNDC );
-Vector2f TransformTanFovSpaceToRendertargetTexUV ( StereoEyeParams const &eyeParams,
+Vector2f TransformTanFovSpaceToRendertargetTexUV ( ScaleAndOffset2D const &eyeToSourceUV,
Vector2f const &tanEyeAngle );
-Vector2f TransformTanFovSpaceToRendertargetNDC ( StereoEyeParams const &eyeParams,
+Vector2f TransformTanFovSpaceToRendertargetNDC ( ScaleAndOffset2D const &eyeToSourceNDC,
Vector2f const &tanEyeAngle );
Vector2f TransformScreenPixelToScreenNDC( Recti const &distortionViewport,
Vector2f const &pixel );
@@ -455,6 +664,18 @@ Vector2f TransformTanFovSpaceToScreenNDC( DistortionRenderDesc const &distortion
Vector2f TransformRendertargetNDCToTanFovSpace( const ScaleAndOffset2D &eyeToSourceNDC,
const Vector2f &textureNDC );
+// Handy wrappers.
+inline Vector2f TransformTanFovSpaceToRendertargetTexUV ( StereoEyeParams const &eyeParams,
+ Vector2f const &tanEyeAngle )
+{
+ return TransformTanFovSpaceToRendertargetTexUV ( eyeParams.EyeToSourceUV, tanEyeAngle );
+}
+inline Vector2f TransformTanFovSpaceToRendertargetNDC ( StereoEyeParams const &eyeParams,
+ Vector2f const &tanEyeAngle )
+{
+ return TransformTanFovSpaceToRendertargetNDC ( eyeParams.EyeToSourceNDC, tanEyeAngle );
+}
+
} //namespace OVR
-#endif // OVR_Stereo_h \ No newline at end of file
+#endif // OVR_Stereo_h