Example #1
0
 protected override void Destroy()
 {
     if (Device != null)
     {
         physicalDeviceInUse = false;
         Device.Dispose();
         Device = null;
     }
 }
Example #2
0
        private void OnEnabledChanged(object sender, EventArgs eventArgs)
        {
            if (Enabled && Device == null)
            {
                if (PreferredApis == null)
                {
                    return;
                }

                double refreshRate = 90.0;

                if (physicalDeviceInUse)
                {
                    Device = null;
                    goto postswitch;
                }

                foreach (var hmdApi in PreferredApis)
                {
                    switch (hmdApi)
                    {
                    case VRApi.Dummy:
                    {
                        Device = new DummyDevice(Services);
                        break;
                    }

                    case VRApi.Oculus:
                    {
#if XENKO_GRAPHICS_API_DIRECT3D11
                        Device = new OculusOvrHmd();
#endif
                        break;
                    }

                    case VRApi.OpenVR:
                    {
#if XENKO_PLATFORM_WINDOWS_DESKTOP
                        Device = new OpenVRHmd(Game);
#endif
                        break;
                    }

                    case VRApi.WindowsMixedReality:
                    {
#if XENKO_GRAPHICS_API_DIRECT3D11 && XENKO_PLATFORM_UWP
                        if (Windows.Graphics.Holographic.HolographicSpace.IsAvailable && GraphicsDevice.Presenter is WindowsMixedRealityGraphicsPresenter)
                        {
                            Device = new WindowsMixedRealityHmd();
                        }
#endif
                        break;
                    }

                    //case VRApi.Fove:
                    //{
                    //#if XENKO_GRAPHICS_API_DIRECT3D11
                    //    Device = new FoveHmd();
                    //#endif
                    //break;
                    //}
                    //case VRApi.Google:
                    //{
                    //#if XENKO_PLATFORM_IOS || XENKO_PLATFORM_ANDROID
                    //    VRDevice = new GoogleVrHmd();
                    //#endif
                    //    break;
                    //}
                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    if (Device != null)
                    {
                        Device.Game = Game;

                        if (Device != null && !Device.CanInitialize)
                        {
                            Device.Dispose();
                            Device = null;
                        }
                        else
                        {
                            break;
                        }
                    }
                }

postswitch:

                var deviceManager = (GraphicsDeviceManager)Services.GetService <IGraphicsDeviceManager>();
                if (Device != null)
                {
                    Game.TreatNotFocusedLikeMinimized = false;
                    Game.IsFixedTimeStep = false;
                    deviceManager.SynchronizeWithVerticalRetrace = false;

                    Device.RenderFrameScaling = PreferredScalings[Device.VRApi];
                    Device.Enable(GraphicsDevice, deviceManager, RequireMirror, MirrorWidth, MirrorHeight);
                    physicalDeviceInUse = true;

#if XENKO_PLATFORM_WINDOWS_DESKTOP
                    if (Device is OpenVRHmd)
                    {
                        refreshRate = ((OpenVRHmd)Device).RefreshRate();
                    }
#endif
                    Game.TargetElapsedTime = Utilities.FromSecondsPrecise(1.0 / refreshRate);
                    Game.WindowMinimumUpdateRate.MinimumElapsedTime    = Game.TargetElapsedTime;
                    Game.MinimizedMinimumUpdateRate.MinimumElapsedTime = Game.TargetElapsedTime;
                }
                else
                {
                    //fallback to dummy device
                    Device = new DummyDevice(Services)
                    {
                        Game = Game,
                        RenderFrameScaling = 1.0f,
                    };
                    Device.Enable(GraphicsDevice, deviceManager, RequireMirror, MirrorWidth, MirrorHeight);
                }
            }
        }
Example #3
0
        private void OnEnabledChanged(object sender, EventArgs eventArgs)
        {
            if (Enabled && Device == null)
            {
                if (PreferredApis == null)
                {
                    return;
                }

                if (physicalDeviceInUse)
                {
                    Device = null;
                    goto postswitch;
                }

                foreach (var hmdApi in PreferredApis)
                {
                    switch (hmdApi)
                    {
                    case VRApi.Dummy:
                    {
                        Device = new DummyDevice(Services);
                    }
                    break;

                    case VRApi.Oculus:
                    {
#if XENKO_GRAPHICS_API_DIRECT3D11
                        Device = new OculusOvrHmd();
#endif
                    }
                    break;

                    case VRApi.OpenVR:
                    {
#if XENKO_GRAPHICS_API_DIRECT3D11
                        Device = new OpenVRHmd();
#endif
                    }
                    break;

                    case VRApi.WindowsMixedReality:
                    {
#if XENKO_GRAPHICS_API_DIRECT3D11 && XENKO_PLATFORM_UWP
                        if (Windows.Graphics.Holographic.HolographicSpace.IsAvailable && GraphicsDevice.Presenter is WindowsMixedRealityGraphicsPresenter)
                        {
                            Device = new WindowsMixedRealityHmd();
                        }
#endif
                    }
                    break;

                    //                        case VRApi.Fove:
                    //                        {
                    //#if XENKO_GRAPHICS_API_DIRECT3D11
                    //                            Device = new FoveHmd();
                    //#endif
                    //                        }
                    //                            break;
                    //                        case VRApi.Google:
                    //                        {
                    //#if XENKO_PLATFORM_IOS || XENKO_PLATFORM_ANDROID
                    //                                VRDevice = new GoogleVrHmd();
                    //#endif
                    //                        }
                    //                            break;
                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    if (Device != null)
                    {
                        Device.Game = Game;

                        if (Device != null && !Device.CanInitialize)
                        {
                            Device.Dispose();
                            Device = null;
                        }
                        else
                        {
                            break;
                        }
                    }
                }

postswitch:

                var deviceManager = (GraphicsDeviceManager)Services.GetService <IGraphicsDeviceManager>();
                if (Device != null)
                {
                    Device.RenderFrameScaling = PreferredScalings[Device.VRApi];
                    Device.Enable(GraphicsDevice, deviceManager, RequireMirror, MirrorWidth, MirrorHeight);
                    physicalDeviceInUse = true;
                }
                else
                {
                    //fallback to dummy device
                    Device = new DummyDevice(Services)
                    {
                        Game = Game,
                        RenderFrameScaling = 1.0f
                    };
                    Device.Enable(GraphicsDevice, deviceManager, RequireMirror, MirrorWidth, MirrorHeight);
                }
            }
        }
Example #4
0
        private void OnEnabledChanged(object sender, EventArgs eventArgs)
        {
            if (Enabled && Device == null)
            {
                if (PreferredApis == null)
                {
                    return;
                }

                double refreshRate = 90.0;

                if (physicalDeviceInUse)
                {
                    Device = null;
                    goto postswitch;
                }

                foreach (var hmdApi in PreferredApis)
                {
                    switch (hmdApi)
                    {
                    case VRApi.OpenXR:
#if XENKO_GRAPHICS_API_VULKAN
                        Device = new OpenXRHmd(Game);
#endif
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    if (Device != null)
                    {
                        Device.Game = Game;

                        if (Device != null && !Device.CanInitialize)
                        {
                            Device.Dispose();
                            Device = null;
                        }
                        else
                        {
                            break;
                        }
                    }
                }

postswitch:

                var deviceManager = (GraphicsDeviceManager)Services.GetService <IGraphicsDeviceManager>();
                if (Device != null)
                {
                    Game.TreatNotFocusedLikeMinimized = false;
                    Game.DrawEvenMinimized            = true;
                    Game.IsFixedTimeStep = false;
                    deviceManager.SynchronizeWithVerticalRetrace = false;

                    Device.RenderFrameScaling = PreferredScalings[Device.VRApi];
                    Device.Enable(GraphicsDevice, deviceManager, RequireMirror);
                    Device.SetTrackingSpace(TrackingSpace.Standing);
                    physicalDeviceInUse = true;

                    // WaitGetPoses should throttle our application, so don't do it elsewhere
                    Game.TargetElapsedTime = TimeSpan.Zero;
                    Game.WindowMinimumUpdateRate.MinimumElapsedTime    = TimeSpan.Zero;
                    Game.MinimizedMinimumUpdateRate.MinimumElapsedTime = TimeSpan.Zero;
                }

                // init virtual buttons for use with VR input
                Xenko.Input.VirtualButton.RegisterExternalVirtualButtonType(typeof(Xenko.VirtualReality.VRButtons));
            }
        }
        private void OnEnabledChanged(object sender, EventArgs eventArgs)
        {
            if (Enabled && Device == null)
            {
                if (PreferredApis == null)
                {
                    return;
                }

                double refreshRate = 90.0;

                if (physicalDeviceInUse)
                {
                    Device = null;
                    goto postswitch;
                }

                foreach (var hmdApi in PreferredApis)
                {
                    switch (hmdApi)
                    {
                    case VRApi.Dummy:
                    {
                        Device = new DummyDevice(Services);
                        break;
                    }

                    /*case VRApi.Oculus:
                     * {
                     #if XENKO_GRAPHICS_API_DIRECT3D11
                     *  Device = new OculusOvrHmd();
                     *
                     #endif
                     *  break;
                     * }*/
                    case VRApi.OpenVR:
                    {
#if XENKO_GRAPHICS_API_VULKAN || XENKO_GRAPHICS_API_DIRECT3D11
                        Device = new OpenVRHmd(Game);
#endif
                        break;

/*                        case VRApi.WindowsMixedReality:
 *                      {
 #if XENKO_GRAPHICS_API_DIRECT3D11 && XENKO_PLATFORM_UWP
 *                          if (Windows.Graphics.Holographic.HolographicSpace.IsAvailable && GraphicsDevice.Presenter is WindowsMixedRealityGraphicsPresenter)
 *                          {
 *                              Device = new WindowsMixedRealityHmd();
 *                          }
 #endif
 *                          break;*/
                    }

                    //case VRApi.Fove:
                    //{
                    //#if XENKO_GRAPHICS_API_DIRECT3D11
                    //    Device = new FoveHmd();
                    //#endif
                    //break;
                    //}
                    //case VRApi.Google:
                    //{
                    //#if XENKO_PLATFORM_IOS || XENKO_PLATFORM_ANDROID
                    //    VRDevice = new GoogleVrHmd();
                    //#endif
                    //    break;
                    //}
                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    if (Device != null)
                    {
                        Device.Game = Game;

                        if (Device != null && !Device.CanInitialize)
                        {
                            Device.Dispose();
                            Device = null;
                        }
                        else
                        {
                            break;
                        }
                    }
                }

postswitch:

                var deviceManager = (GraphicsDeviceManager)Services.GetService <IGraphicsDeviceManager>();
                if (Device != null)
                {
                    Game.TreatNotFocusedLikeMinimized = false;
                    Game.IsFixedTimeStep = false;
                    deviceManager.SynchronizeWithVerticalRetrace = false;

                    Device.RenderFrameScaling = PreferredScalings[Device.VRApi];
                    Device.Enable(GraphicsDevice, deviceManager, RequireMirror);
                    Device.SetTrackingSpace(TrackingSpace.Standing);
                    physicalDeviceInUse = true;

                    // default values
                    Game.TargetElapsedTime = Utilities.FromSecondsPrecise(1.0 / refreshRate);
                    Game.WindowMinimumUpdateRate.MinimumElapsedTime    = Game.TargetElapsedTime;
                    Game.MinimizedMinimumUpdateRate.MinimumElapsedTime = Game.TargetElapsedTime;

#if XENKO_GRAPHICS_API_VULKAN || XENKO_GRAPHICS_API_DIRECT3D11
                    if (Device is OpenVRHmd)
                    {
                        // WaitGetPoses should throttle our application, so don't do it elsewhere
                        //refreshRate = ((OpenVRHmd)Device).RefreshRate();
                        Game.TargetElapsedTime = TimeSpan.Zero; //Utilities.FromSecondsPrecise(1.0 / refreshRate);
                        Game.WindowMinimumUpdateRate.MinimumElapsedTime    = TimeSpan.Zero;
                        Game.MinimizedMinimumUpdateRate.MinimumElapsedTime = TimeSpan.Zero;
                    }
#endif
                }
                else
                {
                    //fallback to dummy device
                    Device = new DummyDevice(Services)
                    {
                        Game = Game,
                        RenderFrameScaling = 1.0f,
                    };
                    Device.Enable(GraphicsDevice, deviceManager, RequireMirror);
                }

                // init virtual buttons for use with VR input
                Xenko.Input.VirtualButton.RegisterExternalVirtualButtonType(typeof(Xenko.VirtualReality.VRButtons));
            }
        }