nuclear@0: /************************************************************************************ nuclear@0: nuclear@0: Filename : OVR_CAPI_HMDRenderState.cpp nuclear@0: Content : Combines all of the rendering state associated with the HMD nuclear@0: Created : February 2, 2014 nuclear@0: Authors : Michael Antonov nuclear@0: nuclear@0: Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. nuclear@0: nuclear@0: Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); nuclear@0: you may not use the Oculus VR Rift SDK except in compliance with the License, nuclear@0: which is provided at the time of installation or download, or which nuclear@0: otherwise accompanies this software in either electronic or hard copy form. nuclear@0: nuclear@0: You may obtain a copy of the License at nuclear@0: nuclear@0: http://www.oculusvr.com/licenses/LICENSE-3.2 nuclear@0: nuclear@0: Unless required by applicable law or agreed to in writing, the Oculus VR SDK nuclear@0: distributed under the License is distributed on an "AS IS" BASIS, nuclear@0: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. nuclear@0: See the License for the specific language governing permissions and nuclear@0: limitations under the License. nuclear@0: nuclear@0: ************************************************************************************/ nuclear@0: nuclear@0: #include "CAPI_HMDRenderState.h" nuclear@0: nuclear@0: namespace OVR { namespace CAPI { nuclear@0: nuclear@0: nuclear@0: //------------------------------------------------------------------------------------- nuclear@0: // ***** HMDRenderState nuclear@0: nuclear@0: ovrHmdDesc HMDRenderState::GetDesc() const nuclear@0: { nuclear@0: ovrHmdDesc d; nuclear@0: memset(&d, 0, sizeof(d)); nuclear@0: nuclear@0: d.Type = ovrHmd_Other; nuclear@0: nuclear@0: d.ProductName = OurHMDInfo.ProductName; nuclear@0: d.Manufacturer = OurHMDInfo.Manufacturer; nuclear@0: d.Resolution.w = OurHMDInfo.ResolutionInPixels.w; nuclear@0: d.Resolution.h = OurHMDInfo.ResolutionInPixels.h; nuclear@0: d.WindowsPos.x = OurHMDInfo.DesktopX; nuclear@0: d.WindowsPos.y = OurHMDInfo.DesktopY; nuclear@0: d.DisplayDeviceName = OurHMDInfo.DisplayDeviceName; nuclear@0: d.DisplayId = OurHMDInfo.DisplayId; nuclear@0: d.VendorId = (short)OurHMDInfo.VendorId; nuclear@0: d.ProductId = (short)OurHMDInfo.ProductId; nuclear@0: d.FirmwareMajor = (short)OurHMDInfo.FirmwareMajor; nuclear@0: d.FirmwareMinor = (short)OurHMDInfo.FirmwareMinor; nuclear@0: d.CameraFrustumFarZInMeters = OurHMDInfo.CameraFrustumFarZInMeters; nuclear@0: d.CameraFrustumHFovInRadians = OurHMDInfo.CameraFrustumHFovInRadians; nuclear@0: d.CameraFrustumNearZInMeters = OurHMDInfo.CameraFrustumNearZInMeters; nuclear@0: d.CameraFrustumVFovInRadians = OurHMDInfo.CameraFrustumVFovInRadians; nuclear@0: nuclear@0: OVR_strcpy(d.SerialNumber, sizeof(d.SerialNumber), OurHMDInfo.PrintedSerial.ToCStr()); nuclear@0: nuclear@0: d.HmdCaps = ovrHmdCap_Present | ovrHmdCap_NoVSync; nuclear@0: d.TrackingCaps = ovrTrackingCap_MagYawCorrection | ovrTrackingCap_Orientation; nuclear@0: d.DistortionCaps = ovrDistortionCap_Chromatic | ovrDistortionCap_TimeWarp | nuclear@0: ovrDistortionCap_Vignette | ovrDistortionCap_SRGB | nuclear@0: ovrDistortionCap_FlipInput | ovrDistortionCap_ProfileNoTimewarpSpinWaits | nuclear@0: ovrDistortionCap_HqDistortion | ovrDistortionCap_LinuxDevFullscreen; nuclear@0: nuclear@0: #if defined(OVR_OS_WIN32) || defined(OVR_OS_WIN64) nuclear@0: // TODO: this gets enabled for everything, but is only applicable for DX11+ nuclear@0: d.DistortionCaps |= ovrDistortionCap_ComputeShader; nuclear@0: #endif nuclear@0: nuclear@0: if( OurHMDInfo.InCompatibilityMode ) nuclear@0: d.HmdCaps |= ovrHmdCap_ExtendDesktop; nuclear@0: nuclear@0: if (strstr(OurHMDInfo.ProductName, "DK1")) nuclear@0: { nuclear@0: d.Type = ovrHmd_DK1; nuclear@0: } nuclear@0: else if (strstr(OurHMDInfo.ProductName, "DK2")) nuclear@0: { nuclear@0: d.Type = ovrHmd_DK2; nuclear@0: d.HmdCaps |= ovrHmdCap_LowPersistence | ovrHmdCap_DynamicPrediction; nuclear@0: d.TrackingCaps |= ovrTrackingCap_Position; nuclear@0: d.DistortionCaps |= ovrDistortionCap_Overdrive; nuclear@0: } nuclear@0: nuclear@0: const DistortionRenderDesc& leftDistortion = Distortion[0]; nuclear@0: const DistortionRenderDesc& rightDistortion = Distortion[1]; nuclear@0: nuclear@0: // The suggested FOV (assuming eye rotation) nuclear@0: d.DefaultEyeFov[0] = CalculateFovFromHmdInfo(StereoEye_Left, leftDistortion, RenderInfo, OVR_DEFAULT_EXTRA_EYE_ROTATION); nuclear@0: d.DefaultEyeFov[1] = CalculateFovFromHmdInfo(StereoEye_Right, rightDistortion, RenderInfo, OVR_DEFAULT_EXTRA_EYE_ROTATION); nuclear@0: nuclear@0: // FOV extended across the entire screen nuclear@0: d.MaxEyeFov[0] = GetPhysicalScreenFov(StereoEye_Left, leftDistortion); nuclear@0: d.MaxEyeFov[1] = GetPhysicalScreenFov(StereoEye_Right, rightDistortion); nuclear@0: nuclear@0: if (OurHMDInfo.Shutter.Type == HmdShutter_RollingRightToLeft) nuclear@0: { nuclear@0: d.EyeRenderOrder[0] = ovrEye_Right; nuclear@0: d.EyeRenderOrder[1] = ovrEye_Left; nuclear@0: } nuclear@0: else nuclear@0: { nuclear@0: d.EyeRenderOrder[0] = ovrEye_Left; nuclear@0: d.EyeRenderOrder[1] = ovrEye_Right; nuclear@0: } nuclear@0: nuclear@0: // MA: Taking this out on purpose. nuclear@0: // Important information for those that are required to do their own timing, nuclear@0: // because of shortfalls in timing code. nuclear@0: //d.VsyncToNextVsync = OurHMDInfo.Shutter.VsyncToNextVsync; nuclear@0: //d.PixelPersistence = OurHMDInfo.Shutter.PixelPersistence; nuclear@0: nuclear@0: return d; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: ovrSizei HMDRenderState::GetFOVTextureSize(int eye, ovrFovPort fov, float pixelsPerDisplayPixel) const nuclear@0: { nuclear@0: OVR_ASSERT((unsigned)eye < 2); nuclear@0: StereoEye seye = (eye == ovrEye_Left) ? StereoEye_Left : StereoEye_Right; nuclear@0: return CalculateIdealPixelSize(seye, Distortion[eye], fov, pixelsPerDisplayPixel); nuclear@0: } nuclear@0: nuclear@0: ovrEyeRenderDesc HMDRenderState::CalcRenderDesc(ovrEyeType eyeType, const ovrFovPort& fov) const nuclear@0: { nuclear@0: const HmdRenderInfo& hmdri = RenderInfo; nuclear@0: StereoEye eye = (eyeType == ovrEye_Left) ? StereoEye_Left : StereoEye_Right; nuclear@0: ovrEyeRenderDesc e0; nuclear@0: nuclear@0: e0.Eye = eyeType; nuclear@0: e0.Fov = fov; nuclear@0: e0.HmdToEyeViewOffset = CalculateEyeVirtualCameraOffset(hmdri, eye, false); nuclear@0: e0.DistortedViewport = GetFramebufferViewport(eye, hmdri); nuclear@0: e0.PixelsPerTanAngleAtCenter = Distortion[0].PixelsPerTanAngleAtCenter; nuclear@0: nuclear@0: return e0; nuclear@0: } nuclear@0: nuclear@0: }} // namespace OVR::CAPI nuclear@0: