/// <summary> /// Write out any error details received from the Oculus SDK, into the debug output window. /// Please note that writing text to the debug output window is a slow operation and will affect performance, /// if too many messages are written in a short timespan. /// </summary> /// <param name="oculus">OculusWrap object for which the error occurred.</param> /// <param name="result">Error code to write in the debug text.</param> /// <param name="message">Error message to include in the debug text.</param> public static void WriteErrorDetails(Wrap oculus, OVRTypes.Result result, string message) { if (result >= OVRTypes.Result.Success) { return; } // Retrieve the error message from the last occurring error. OVRTypes.ErrorInfo errorInformation = oculus.GetLastError(); string formattedMessage = string.Format("{0}. \nMessage: {1} (Error code={2})", message, errorInformation.ErrorString, errorInformation.Result); throw new Exception(formattedMessage); }
/// <summary> /// Gets the description of the buffers in the TextureSwapChain /// </summary> /// <param name="textureSwapChainDescription">Returns the description of the specified chain.</param> /// <returns>Returns an ovrResult for which the return code is negative upon error. </returns> public OVRTypes.Result GetDescription(out OVRTypes.TextureSwapChainDesc textureSwapChainDescription) { if (Disposed) { throw new ObjectDisposedException("TextureSwapChain"); } OVRTypes.TextureSwapChainDesc textureSwapChainDesc = new OVRTypes.TextureSwapChainDesc(); OVRTypes.Result result = OVR.GetTextureSwapChainDesc(Session, TextureSwapChainPtr, ref textureSwapChainDesc); textureSwapChainDescription = textureSwapChainDesc; return(result); }
void AssertSuccess(OVRTypes.Result result, Wrap oculus, string message) { if (result >= OVRTypes.Result.Success) { return; } // Retrieve the error message from the last occurring error. OVRTypes.ErrorInfo errorInformation = oculus.GetLastError(); string formattedMessage = string.Format("{0}. Message: {1} (Error code={2})", message, errorInformation.ErrorString, errorInformation.Result); Trace.WriteLine(formattedMessage); throw new HeadsetError(formattedMessage); }
/// <summary> /// Creates a handle to an HMD. /// /// Upon success the returned Hmd must be eventually freed with Dispose() when it is no longer needed. /// </summary> /// <param name="graphicsLuid"> /// Provides a system specific graphics adapter identifier that locates which /// graphics adapter has the HMD attached. This must match the adapter used by the application /// or no rendering output will be possible. This is important for stability on multi-adapter systems. An /// application that simply chooses the default adapter will not run reliably on multi-adapter systems. /// </param> public Hmd Hmd_Create(out OVRTypes.GraphicsLuid graphicsLuid) { IntPtr hmdPtr = IntPtr.Zero; graphicsLuid = new OVRTypes.GraphicsLuid(); OVRTypes.Result result = OVR.Create(ref hmdPtr, ref graphicsLuid); if (result < OVRTypes.Result.Success) { return(null); } Hmd hmd = new Hmd(OVR, hmdPtr); // Ensure that this created HMD is disposed, when this Wrap class is being disposed. CreatedHmds.Add(hmd); return(hmd); }
/// <summary> /// Initializes all Oculus functionality. /// </summary> /// <param name="initializationParameters"> /// Initialization parameters to pass to the ovr_Initialize call. /// </param> /// <remarks> /// Library init/shutdown, must be called around all other OVR code. /// No other functions calls besides ovr_InitializeRenderingShim are allowed /// before ovr_Initialize succeeds or after ovr_Shutdown. /// </remarks> public bool Initialize(OVRTypes.InitParams initializationParameters = null) { if (Initialized) { throw new InvalidOperationException("The Oculus wrapper has already been initialized."); } /* * // Ensure that the DllOvr.dll is loaded, using the bitness matching that of the current process. * LoadDllOvr(); */ OVRTypes.Result success = OVR.Initialize(initializationParameters); if (success < OVRTypes.Result.Success) { return(false); } Initialized = true; return(true); }