Ejemplo n.º 1
0
 internal static bool IsSupported()
 {
     try
     {
         return(OVR.IsHmdPresent());
     }
     catch
     {
         return(false);
     }
 }
        public override void Dispose()
        {
            if (this.context != null)
            {
                this.context.ClearState();
                this.context.Flush();
            }

            ValveOpenVR.Shutdown();

            base.Dispose();
        }
Ejemplo n.º 3
0
        public override void Dispose()
        {
            _mirrorTexture.Dispose();

            _leftEyeFB.ColorTargets[0].Target.Dispose();
            _leftEyeFB.DepthTarget?.Target.Dispose();
            _leftEyeFB.Dispose();

            _rightEyeFB.ColorTargets[0].Target.Dispose();
            _rightEyeFB.DepthTarget?.Target.Dispose();
            _rightEyeFB.Dispose();

            OVR.Shutdown();
        }
Ejemplo n.º 4
0
        public OpenVRContext(VRContextOptions options)
        {
            _options = options;

            EVRInitError initError = EVRInitError.None;

            _vrSystem = OVR.Init(ref initError, EVRApplicationType.VRApplication_Scene);
            if (initError != EVRInitError.None)
            {
                throw new Exception($"Failed to initialize OpenVR: {OVR.GetStringForHmdError(initError)}");
            }

            _compositor = OVR.Compositor;
            if (_compositor == null)
            {
                throw new Exception("Failed to access the OpenVR Compositor.");
            }
        }
        /// <summary>
        /// Configures the specified windows handler.
        /// </summary>
        /// <param name="windowsHandler">The windows handler.</param>
        public override void Configure(IntPtr windowsHandler)
        {
            base.Configure(windowsHandler);

            this.LoadNativeLibrary();

            var error = EVRInitError.None;

            this.HmdDetected = true;

            this.Hmd = ValveOpenVR.Init(ref error, this.OpenVRApplicationType);
            if (error != EVRInitError.None)
            {
                OpenVRHelper.ReportInitError(error);
                this.Hmd         = null;
                this.HmdDetected = false;
            }

            // Verify common interfaces are valid.
            ValveOpenVR.GetGenericInterface(ValveOpenVR.IVRCompositor_Version, ref error);
            if (error != EVRInitError.None)
            {
                OpenVRHelper.ReportInitError(error);
                this.HmdDetected = false;
            }

            ValveOpenVR.GetGenericInterface(ValveOpenVR.IVROverlay_Version, ref error);
            if (error != EVRInitError.None)
            {
                OpenVRHelper.ReportInitError(error);
                this.HmdDetected = false;
            }

            if (this.Hmd == null)
            {
                ValveOpenVR.Shutdown();
                return;
            }
        }
Ejemplo n.º 6
0
        public static void ReportInitError(EVRInitError error)
        {
            switch (error)
            {
            case EVRInitError.None:
                break;

            case EVRInitError.VendorSpecific_UnableToConnectToOculusRuntime:
                Debug.WriteLine("OpenVR Initialization Failed! Make sure device is on, Oculus runtime is installed, and OVRService_*.exe is running.");
                break;

            case EVRInitError.Init_VRClientDLLNotFound:
                Debug.WriteLine("OpenVR drivers not found! They can be installed via Steam under Library > Tools. Visit http://steampowered.com to install Steam.");
                break;

            case EVRInitError.Driver_RuntimeOutOfDate:
                Debug.WriteLine("OpenVR Initialization Failed! Make sure device's runtime is up to date.");
                break;

            default:
                Debug.WriteLine(ValveOpenVR.GetStringForHmdError(error));
                break;
            }
        }
Ejemplo n.º 7
0
 public override void Dispose()
 {
     OVR.Shutdown();
 }
Ejemplo n.º 8
0
        private static SteamVR CreateInstance()
        {
            initializedState = InitializedStates.Initializing;

            try
            {
                var error = EVRInitError.None;
                if (!SteamVR.usingNativeSupport)
                {
                    ReportGeneralErrors();
                    initializedState = InitializedStates.InitializeFailure;
                    SteamVR_Events.Initialized.Send(false);
                    return(null);
                }

                // Verify common interfaces are valid.

                OpenVR.GetGenericInterface(OpenVR.IVRCompositor_Version, ref error);
                if (error != EVRInitError.None)
                {
                    initializedState = InitializedStates.InitializeFailure;
                    ReportError(error);
                    ReportGeneralErrors();
                    SteamVR_Events.Initialized.Send(false);
                    return(null);
                }

                OpenVR.GetGenericInterface(OpenVR.IVROverlay_Version, ref error);
                if (error != EVRInitError.None)
                {
                    initializedState = InitializedStates.InitializeFailure;
                    ReportError(error);
                    SteamVR_Events.Initialized.Send(false);
                    return(null);
                }

                OpenVR.GetGenericInterface(OpenVR.IVRInput_Version, ref error);
                if (error != EVRInitError.None)
                {
                    initializedState = InitializedStates.InitializeFailure;
                    ReportError(error);
                    SteamVR_Events.Initialized.Send(false);
                    return(null);
                }

                settings = SteamVR_Settings.instance;

                if (Application.isEditor)
                {
                    IdentifyEditorApplication();
                }

                SteamVR_Input.IdentifyActionsFile();

                if (SteamVR_Settings.instance.inputUpdateMode != SteamVR_UpdateModes.Nothing || SteamVR_Settings.instance.poseUpdateMode != SteamVR_UpdateModes.Nothing)
                {
                    SteamVR_Input.Initialize();

#if UNITY_EDITOR
                    if (SteamVR_Input.IsOpeningSetup())
                    {
                        return(null);
                    }
#endif
                }
            }
            catch (System.Exception e)
            {
                Debug.LogError("<b>[SteamVR]</b> " + e);
                SteamVR_Events.Initialized.Send(false);
                return(null);
            }

            _enabled         = true;
            initializedState = InitializedStates.InitializeSuccess;
            SteamVR_Events.Initialized.Send(true);
            return(new SteamVR());
        }
Ejemplo n.º 9
0
        private static SteamVR CreateInstance()
        {
            try
            {
                var error = EVRInitError.None;
                if (!SteamVR.usingNativeSupport)
                {
                    string errorLog = "[SteamVR] Initialization failed. ";

                    if (XRSettings.enabled == false)
                    {
                        errorLog += "VR may be disabled in vrPlayer settings. Go to vrPlayer settings in the editor and check the 'Virtual Reality Supported' checkbox'. ";
                    }
                    if (XRSettings.supportedDevices.Contains("OpenVR") == false)
                    {
                        errorLog += "OpenVR is not in your list of supported virtual reality SDKs. Add it to the list in vrPlayer settings. ";
                    }

                    errorLog += "To force OpenVR initialization call SteamVR.Initialize(true). ";

                    Debug.Log(errorLog);
                    SteamVR_Events.Initialized.Send(false);
                    return(null);
                }

                // Verify common interfaces are valid.

                OpenVR.GetGenericInterface(OpenVR.IVRCompositor_Version, ref error);
                if (error != EVRInitError.None)
                {
                    ReportError(error);
                    SteamVR_Events.Initialized.Send(false);
                    return(null);
                }

                OpenVR.GetGenericInterface(OpenVR.IVROverlay_Version, ref error);
                if (error != EVRInitError.None)
                {
                    ReportError(error);
                    SteamVR_Events.Initialized.Send(false);
                    return(null);
                }

                settings = SteamVR_Settings.instance;

                SteamVR_Input.PreInitialize();

                if (Application.isEditor)
                {
                    IdentifyApplication();
                }

                SteamVR_Input.IdentifyActionsFile();

                if (SteamVR_Settings.instance.inputUpdateMode != SteamVR_UpdateModes.Nothing || SteamVR_Settings.instance.poseUpdateMode != SteamVR_UpdateModes.Nothing)
                {
                    SteamVR_Input.Initialize();
                }
            }
            catch (System.Exception e)
            {
                Debug.LogError(e);
                SteamVR_Events.Initialized.Send(false);
                return(null);
            }

            _enabled = true;
            SteamVR_Events.Initialized.Send(true);
            return(new SteamVR());
        }