/// <summary> /// /// </summary> /// <param name="parameters"></param> public OculusRiftDisplay(Game game, GraphicsDevice device, GameParameters parameters) : base(game, device, parameters) { window = CreateForm(parameters, null); oculus = new Wrap(); // Initialize the Oculus runtime. oculus.Initialize(); // Use the head mounted display, if it's available, otherwise use the debug HMD. int numberOfHeadMountedDisplays = oculus.Hmd_Detect(); if (numberOfHeadMountedDisplays > 0) { hmd = oculus.Hmd_Create(0); } else { hmd = oculus.Hmd_CreateDebug(OculusWrap.OVR.HmdType.DK2); } if (hmd == null) { MessageBox.Show("Oculus Rift not detected.", "Uh oh", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (hmd.ProductName == string.Empty) { MessageBox.Show("The HMD is not enabled.", "There's a tear in the Rift", MessageBoxButtons.OK, MessageBoxIcon.Error); } OVR.Recti destMirrorRect; OVR.Recti sourceRenderTargetRect; hmd.AttachToWindow(window.Handle, out destMirrorRect, out sourceRenderTargetRect); // Create a backbuffer that's the same size as the HMD's resolution. OVR.Sizei backBufferSize; backBufferSize.Width = hmd.Resolution.Width; backBufferSize.Height = hmd.Resolution.Height; Input.OculusRiftSensors.RecenterPosition = hmd.RecenterPose; var deviceFlags = DeviceCreationFlags.None; deviceFlags |= parameters.UseDebugDevice ? DeviceCreationFlags.Debug : DeviceCreationFlags.None; var driverType = DriverType.Hardware; var featureLevel = HardwareProfileChecker.GetFeatureLevel(parameters.GraphicsProfile); swapChainDesc = new SwapChainDescription { BufferCount = 1, ModeDescription = new ModeDescription(backBufferSize.Width, backBufferSize.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm), IsWindowed = true, OutputHandle = window.Handle, SampleDescription = new SampleDescription(parameters.MsaaLevel, 0), SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput | Usage.ShaderInput, Flags = SwapChainFlags.None, }; D3D.Device.CreateWithSwapChain(driverType, deviceFlags, new[] { featureLevel }, swapChainDesc, out d3dDevice, out swapChain); var factory = swapChain.GetParent <Factory>(); factory.MakeWindowAssociation(window.Handle, WindowAssociationFlags.IgnoreAll); clientWidth = window.ClientSize.Width; clientHeight = window.ClientSize.Height; }