protected override void Destroy() { if (Device != null) { if (!(Device is DummyDevice)) { physicalDeviceInUse = false; } Device.Dispose(); Device = null; } }
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 STRIDE_GRAPHICS_API_DIRECT3D11 Device = new OculusOvrHmd(); #endif break; } case VRApi.OpenVR: { #if STRIDE_GRAPHICS_API_DIRECT3D11 Device = new OpenVRHmd(); #endif break; } case VRApi.WindowsMixedReality: { #if STRIDE_GRAPHICS_API_DIRECT3D11 && STRIDE_PLATFORM_UWP if (Windows.Graphics.Holographic.HolographicSpace.IsAvailable && GraphicsDevice.Presenter is WindowsMixedRealityGraphicsPresenter) { Device = new WindowsMixedRealityHmd(); } #endif break; } //case VRApi.Fove: //{ //#if STRIDE_GRAPHICS_API_DIRECT3D11 // Device = new FoveHmd(); //#endif //break; //} //case VRApi.Google: //{ //#if STRIDE_PLATFORM_IOS || STRIDE_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); } } }