ovr_sdk

view LibOVR/Src/CAPI/CAPI_HMDRenderState.cpp @ 0:1b39a1b46319

initial 0.4.4
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 14 Jan 2015 06:51:16 +0200
parents
children
line source
1 /************************************************************************************
3 Filename : OVR_CAPI_HMDRenderState.cpp
4 Content : Combines all of the rendering state associated with the HMD
5 Created : February 2, 2014
6 Authors : Michael Antonov
8 Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved.
10 Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
11 you may not use the Oculus VR Rift SDK except in compliance with the License,
12 which is provided at the time of installation or download, or which
13 otherwise accompanies this software in either electronic or hard copy form.
15 You may obtain a copy of the License at
17 http://www.oculusvr.com/licenses/LICENSE-3.2
19 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
20 distributed under the License is distributed on an "AS IS" BASIS,
21 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 See the License for the specific language governing permissions and
23 limitations under the License.
25 ************************************************************************************/
27 #include "CAPI_HMDRenderState.h"
29 namespace OVR { namespace CAPI {
32 //-------------------------------------------------------------------------------------
33 // ***** HMDRenderState
35 ovrHmdDesc HMDRenderState::GetDesc() const
36 {
37 ovrHmdDesc d;
38 memset(&d, 0, sizeof(d));
40 d.Type = ovrHmd_Other;
42 d.ProductName = OurHMDInfo.ProductName;
43 d.Manufacturer = OurHMDInfo.Manufacturer;
44 d.Resolution.w = OurHMDInfo.ResolutionInPixels.w;
45 d.Resolution.h = OurHMDInfo.ResolutionInPixels.h;
46 d.WindowsPos.x = OurHMDInfo.DesktopX;
47 d.WindowsPos.y = OurHMDInfo.DesktopY;
48 d.DisplayDeviceName = OurHMDInfo.DisplayDeviceName;
49 d.DisplayId = OurHMDInfo.DisplayId;
50 d.VendorId = (short)OurHMDInfo.VendorId;
51 d.ProductId = (short)OurHMDInfo.ProductId;
52 d.FirmwareMajor = (short)OurHMDInfo.FirmwareMajor;
53 d.FirmwareMinor = (short)OurHMDInfo.FirmwareMinor;
54 d.CameraFrustumFarZInMeters = OurHMDInfo.CameraFrustumFarZInMeters;
55 d.CameraFrustumHFovInRadians = OurHMDInfo.CameraFrustumHFovInRadians;
56 d.CameraFrustumNearZInMeters = OurHMDInfo.CameraFrustumNearZInMeters;
57 d.CameraFrustumVFovInRadians = OurHMDInfo.CameraFrustumVFovInRadians;
59 OVR_strcpy(d.SerialNumber, sizeof(d.SerialNumber), OurHMDInfo.PrintedSerial.ToCStr());
61 d.HmdCaps = ovrHmdCap_Present | ovrHmdCap_NoVSync;
62 d.TrackingCaps = ovrTrackingCap_MagYawCorrection | ovrTrackingCap_Orientation;
63 d.DistortionCaps = ovrDistortionCap_Chromatic | ovrDistortionCap_TimeWarp |
64 ovrDistortionCap_Vignette | ovrDistortionCap_SRGB |
65 ovrDistortionCap_FlipInput | ovrDistortionCap_ProfileNoTimewarpSpinWaits |
66 ovrDistortionCap_HqDistortion | ovrDistortionCap_LinuxDevFullscreen;
68 #if defined(OVR_OS_WIN32) || defined(OVR_OS_WIN64)
69 // TODO: this gets enabled for everything, but is only applicable for DX11+
70 d.DistortionCaps |= ovrDistortionCap_ComputeShader;
71 #endif
73 if( OurHMDInfo.InCompatibilityMode )
74 d.HmdCaps |= ovrHmdCap_ExtendDesktop;
76 if (strstr(OurHMDInfo.ProductName, "DK1"))
77 {
78 d.Type = ovrHmd_DK1;
79 }
80 else if (strstr(OurHMDInfo.ProductName, "DK2"))
81 {
82 d.Type = ovrHmd_DK2;
83 d.HmdCaps |= ovrHmdCap_LowPersistence | ovrHmdCap_DynamicPrediction;
84 d.TrackingCaps |= ovrTrackingCap_Position;
85 d.DistortionCaps |= ovrDistortionCap_Overdrive;
86 }
88 const DistortionRenderDesc& leftDistortion = Distortion[0];
89 const DistortionRenderDesc& rightDistortion = Distortion[1];
91 // The suggested FOV (assuming eye rotation)
92 d.DefaultEyeFov[0] = CalculateFovFromHmdInfo(StereoEye_Left, leftDistortion, RenderInfo, OVR_DEFAULT_EXTRA_EYE_ROTATION);
93 d.DefaultEyeFov[1] = CalculateFovFromHmdInfo(StereoEye_Right, rightDistortion, RenderInfo, OVR_DEFAULT_EXTRA_EYE_ROTATION);
95 // FOV extended across the entire screen
96 d.MaxEyeFov[0] = GetPhysicalScreenFov(StereoEye_Left, leftDistortion);
97 d.MaxEyeFov[1] = GetPhysicalScreenFov(StereoEye_Right, rightDistortion);
99 if (OurHMDInfo.Shutter.Type == HmdShutter_RollingRightToLeft)
100 {
101 d.EyeRenderOrder[0] = ovrEye_Right;
102 d.EyeRenderOrder[1] = ovrEye_Left;
103 }
104 else
105 {
106 d.EyeRenderOrder[0] = ovrEye_Left;
107 d.EyeRenderOrder[1] = ovrEye_Right;
108 }
110 // MA: Taking this out on purpose.
111 // Important information for those that are required to do their own timing,
112 // because of shortfalls in timing code.
113 //d.VsyncToNextVsync = OurHMDInfo.Shutter.VsyncToNextVsync;
114 //d.PixelPersistence = OurHMDInfo.Shutter.PixelPersistence;
116 return d;
117 }
120 ovrSizei HMDRenderState::GetFOVTextureSize(int eye, ovrFovPort fov, float pixelsPerDisplayPixel) const
121 {
122 OVR_ASSERT((unsigned)eye < 2);
123 StereoEye seye = (eye == ovrEye_Left) ? StereoEye_Left : StereoEye_Right;
124 return CalculateIdealPixelSize(seye, Distortion[eye], fov, pixelsPerDisplayPixel);
125 }
127 ovrEyeRenderDesc HMDRenderState::CalcRenderDesc(ovrEyeType eyeType, const ovrFovPort& fov) const
128 {
129 const HmdRenderInfo& hmdri = RenderInfo;
130 StereoEye eye = (eyeType == ovrEye_Left) ? StereoEye_Left : StereoEye_Right;
131 ovrEyeRenderDesc e0;
133 e0.Eye = eyeType;
134 e0.Fov = fov;
135 e0.HmdToEyeViewOffset = CalculateEyeVirtualCameraOffset(hmdri, eye, false);
136 e0.DistortedViewport = GetFramebufferViewport(eye, hmdri);
137 e0.PixelsPerTanAngleAtCenter = Distortion[0].PixelsPerTanAngleAtCenter;
139 return e0;
140 }
142 }} // namespace OVR::CAPI