Example #1
0
    static void Main(string[] args)
    {
        // If the app has a constructor that takes a string array, then
        // we'll use that, and pass the command line arguments into it on
        // creation
        Type appType = typeof(App);
        App  app     = appType.GetConstructor(new Type[] { typeof(string[]) }) != null
                        ? (App)Activator.CreateInstance(appType, new object[] { args })
                        : (App)Activator.CreateInstance(appType);

        if (app == null)
        {
            throw new Exception("StereoKit loader couldn't construct an instance of the App!");
        }

        // Initialize StereoKit, and the app
        if (!SK.Initialize(app.Settings))
        {
            Environment.Exit(1);
        }

        if (Backend.XRType == BackendXRType.OpenXR)
        {
            xrConvertTimeToWin32PerformanceCounterKHR = Backend.OpenXR.GetFunction <XR_xrConvertTimeToWin32PerformanceCounterKHR>("xrConvertTimeToWin32PerformanceCounterKHR");
            xrConvertTimeToWin32PerformanceCounterKHR(Backend.OpenXR.Instance, Backend.OpenXR.Time, out long counter);
            Log.Info($"XrTime: {counter}");
        }

        app.Init();

        // Now pass execution over to StereoKit
        SK.Run(app.Step, () => Log.Info("Bye!"));
    }
Example #2
0
        /// <summary>
        /// Converts an OpenXR time value as returned from Backend.OpenXR.Time to a performance counter value as if generated by the QueryPerformanceCounter function.
        /// </summary>
        /// <param name="openXrTime">The OpenXR time value.</param>
        /// <returns>The equivalent performance counter value.</returns>
        private static long ConvertXrTimeToWin32PerformanceCounter(long openXrTime)
        {
            // Initialize the delegate on first use
            if (openXrConvertTimeToWin32PerformanceCounterKHR == null)
            {
                if (!SK.IsInitialized)
                {
                    throw new InvalidOperationException("Attempting to convert OpenXR time before StereoKit is initialized. Ensure that SK.Initialize() has been called first.");
                }

                if (Backend.XRType != BackendXRType.OpenXR)
                {
                    throw new InvalidOperationException("Cannot convert OpenXR time. Backend XR type is not OpenXR.");
                }

                openXrConvertTimeToWin32PerformanceCounterKHR = Backend.OpenXR.GetFunction <XR_xrConvertTimeToWin32PerformanceCounterKHR>("xrConvertTimeToWin32PerformanceCounterKHR");
            }

            // Get the raw performance counter value
            openXrConvertTimeToWin32PerformanceCounterKHR(Backend.OpenXR.Instance, openXrTime, out long performanceCount);

            return(performanceCount);
        }