ovr_sdk

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/LibOVR/Src/CAPI/CAPI_HMDRenderState.cpp	Wed Jan 14 06:51:16 2015 +0200
     1.3 @@ -0,0 +1,143 @@
     1.4 +/************************************************************************************
     1.5 +
     1.6 +Filename    :   OVR_CAPI_HMDRenderState.cpp
     1.7 +Content     :   Combines all of the rendering state associated with the HMD
     1.8 +Created     :   February 2, 2014
     1.9 +Authors     :   Michael Antonov
    1.10 +
    1.11 +Copyright   :   Copyright 2014 Oculus VR, LLC All Rights reserved.
    1.12 +
    1.13 +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); 
    1.14 +you may not use the Oculus VR Rift SDK except in compliance with the License, 
    1.15 +which is provided at the time of installation or download, or which 
    1.16 +otherwise accompanies this software in either electronic or hard copy form.
    1.17 +
    1.18 +You may obtain a copy of the License at
    1.19 +
    1.20 +http://www.oculusvr.com/licenses/LICENSE-3.2 
    1.21 +
    1.22 +Unless required by applicable law or agreed to in writing, the Oculus VR SDK 
    1.23 +distributed under the License is distributed on an "AS IS" BASIS,
    1.24 +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.25 +See the License for the specific language governing permissions and
    1.26 +limitations under the License.
    1.27 +
    1.28 +************************************************************************************/
    1.29 +
    1.30 +#include "CAPI_HMDRenderState.h"
    1.31 +
    1.32 +namespace OVR { namespace CAPI {
    1.33 +
    1.34 +
    1.35 +//-------------------------------------------------------------------------------------
    1.36 +// ***** HMDRenderState
    1.37 +
    1.38 +ovrHmdDesc HMDRenderState::GetDesc() const
    1.39 +{
    1.40 +    ovrHmdDesc d;
    1.41 +    memset(&d, 0, sizeof(d));
    1.42 +    
    1.43 +    d.Type = ovrHmd_Other;
    1.44 +     
    1.45 +    d.ProductName       = OurHMDInfo.ProductName;    
    1.46 +    d.Manufacturer      = OurHMDInfo.Manufacturer;
    1.47 +    d.Resolution.w      = OurHMDInfo.ResolutionInPixels.w;
    1.48 +    d.Resolution.h      = OurHMDInfo.ResolutionInPixels.h;
    1.49 +    d.WindowsPos.x      = OurHMDInfo.DesktopX;
    1.50 +    d.WindowsPos.y      = OurHMDInfo.DesktopY;
    1.51 +    d.DisplayDeviceName = OurHMDInfo.DisplayDeviceName;
    1.52 +    d.DisplayId         = OurHMDInfo.DisplayId;
    1.53 +    d.VendorId          = (short)OurHMDInfo.VendorId;
    1.54 +    d.ProductId         = (short)OurHMDInfo.ProductId;
    1.55 +    d.FirmwareMajor     = (short)OurHMDInfo.FirmwareMajor;
    1.56 +    d.FirmwareMinor     = (short)OurHMDInfo.FirmwareMinor;
    1.57 +    d.CameraFrustumFarZInMeters  = OurHMDInfo.CameraFrustumFarZInMeters;
    1.58 +    d.CameraFrustumHFovInRadians = OurHMDInfo.CameraFrustumHFovInRadians;
    1.59 +    d.CameraFrustumNearZInMeters = OurHMDInfo.CameraFrustumNearZInMeters;
    1.60 +    d.CameraFrustumVFovInRadians = OurHMDInfo.CameraFrustumVFovInRadians;
    1.61 +
    1.62 +    OVR_strcpy(d.SerialNumber, sizeof(d.SerialNumber), OurHMDInfo.PrintedSerial.ToCStr());
    1.63 +
    1.64 +    d.HmdCaps           = ovrHmdCap_Present | ovrHmdCap_NoVSync;
    1.65 +    d.TrackingCaps      = ovrTrackingCap_MagYawCorrection | ovrTrackingCap_Orientation;
    1.66 +    d.DistortionCaps    = ovrDistortionCap_Chromatic | ovrDistortionCap_TimeWarp |
    1.67 +                          ovrDistortionCap_Vignette | ovrDistortionCap_SRGB |
    1.68 +                          ovrDistortionCap_FlipInput | ovrDistortionCap_ProfileNoTimewarpSpinWaits |
    1.69 +                          ovrDistortionCap_HqDistortion | ovrDistortionCap_LinuxDevFullscreen;
    1.70 +
    1.71 +#if defined(OVR_OS_WIN32) || defined(OVR_OS_WIN64)
    1.72 +    // TODO: this gets enabled for everything, but is only applicable for DX11+
    1.73 +    d.DistortionCaps   |= ovrDistortionCap_ComputeShader;
    1.74 +#endif
    1.75 +
    1.76 +    if( OurHMDInfo.InCompatibilityMode )
    1.77 +        d.HmdCaps |= ovrHmdCap_ExtendDesktop;
    1.78 +
    1.79 +    if (strstr(OurHMDInfo.ProductName, "DK1"))
    1.80 +    {
    1.81 +        d.Type = ovrHmd_DK1;        
    1.82 +    }
    1.83 +    else if (strstr(OurHMDInfo.ProductName, "DK2"))
    1.84 +    {
    1.85 +        d.Type        = ovrHmd_DK2;
    1.86 +        d.HmdCaps    |= ovrHmdCap_LowPersistence | ovrHmdCap_DynamicPrediction;
    1.87 +        d.TrackingCaps |= ovrTrackingCap_Position;
    1.88 +		d.DistortionCaps |= ovrDistortionCap_Overdrive;
    1.89 +    }
    1.90 +        
    1.91 +    const DistortionRenderDesc& leftDistortion  = Distortion[0];
    1.92 +    const DistortionRenderDesc& rightDistortion = Distortion[1];
    1.93 +  
    1.94 +    // The suggested FOV (assuming eye rotation)
    1.95 +    d.DefaultEyeFov[0] = CalculateFovFromHmdInfo(StereoEye_Left, leftDistortion, RenderInfo, OVR_DEFAULT_EXTRA_EYE_ROTATION);
    1.96 +    d.DefaultEyeFov[1] = CalculateFovFromHmdInfo(StereoEye_Right, rightDistortion, RenderInfo, OVR_DEFAULT_EXTRA_EYE_ROTATION);
    1.97 +
    1.98 +    // FOV extended across the entire screen
    1.99 +    d.MaxEyeFov[0] = GetPhysicalScreenFov(StereoEye_Left, leftDistortion);
   1.100 +    d.MaxEyeFov[1] = GetPhysicalScreenFov(StereoEye_Right, rightDistortion);
   1.101 +    
   1.102 +    if (OurHMDInfo.Shutter.Type == HmdShutter_RollingRightToLeft)
   1.103 +    {
   1.104 +        d.EyeRenderOrder[0] = ovrEye_Right;
   1.105 +        d.EyeRenderOrder[1] = ovrEye_Left;
   1.106 +    }
   1.107 +    else
   1.108 +    {
   1.109 +        d.EyeRenderOrder[0] = ovrEye_Left;
   1.110 +        d.EyeRenderOrder[1] = ovrEye_Right;
   1.111 +    }    
   1.112 +
   1.113 +    // MA: Taking this out on purpose.
   1.114 +	// Important information for those that are required to do their own timing,
   1.115 +    // because of shortfalls in timing code.
   1.116 +	//d.VsyncToNextVsync = OurHMDInfo.Shutter.VsyncToNextVsync;
   1.117 +	//d.PixelPersistence = OurHMDInfo.Shutter.PixelPersistence;
   1.118 +
   1.119 +    return d;
   1.120 +}
   1.121 +
   1.122 +
   1.123 +ovrSizei HMDRenderState::GetFOVTextureSize(int eye, ovrFovPort fov, float pixelsPerDisplayPixel) const
   1.124 +{
   1.125 +    OVR_ASSERT((unsigned)eye < 2);
   1.126 +    StereoEye seye = (eye == ovrEye_Left) ? StereoEye_Left : StereoEye_Right;
   1.127 +    return CalculateIdealPixelSize(seye, Distortion[eye], fov, pixelsPerDisplayPixel);
   1.128 +}
   1.129 +
   1.130 +ovrEyeRenderDesc HMDRenderState::CalcRenderDesc(ovrEyeType eyeType, const ovrFovPort& fov) const
   1.131 +{    
   1.132 +    const HmdRenderInfo&   hmdri = RenderInfo;
   1.133 +    StereoEye        eye   = (eyeType == ovrEye_Left) ? StereoEye_Left : StereoEye_Right;
   1.134 +    ovrEyeRenderDesc e0;
   1.135 +    
   1.136 +    e0.Eye                       = eyeType;
   1.137 +    e0.Fov                       = fov;
   1.138 +    e0.HmdToEyeViewOffset        = CalculateEyeVirtualCameraOffset(hmdri, eye, false);
   1.139 +    e0.DistortedViewport         = GetFramebufferViewport(eye, hmdri);
   1.140 +    e0.PixelsPerTanAngleAtCenter = Distortion[0].PixelsPerTanAngleAtCenter;
   1.141 +
   1.142 +    return e0;
   1.143 +}
   1.144 +
   1.145 +}} // namespace OVR::CAPI
   1.146 +