leetvr / hotham

Hotham is a tool for creating incredible standalone VR games.
Apache License 2.0
393 stars 28 forks source link

Rasmusgo/xr time now #437

Closed rasmusgo closed 1 year ago

rasmusgo commented 1 year ago

This PR adds a method that retrieves the current time as a openxr::Time that can be passed to openxr instead of predicted display time to get more accurate poses with the trade-off that they will be old when the frame is done rendering and displayed to the user.

This function relies on the appropriate time conversion extension being enabled. It can be enabled when creating the engine like this:

    let mut extensions = xr::ExtensionSet::default();
    #[cfg(windows)]
    {
        extensions.khr_win32_convert_performance_counter_time = true;
    }
    #[cfg(not(windows))]
    {
        extensions.khr_convert_timespec_time = true;
    }
    let extensions = Some(extensions);
    let mut engine_builder = EngineBuilder::new();
    engine_builder.openxr_extensions(extensions);
    let mut engine = engine_builder.build();

(I couldn't get it prettier because of moving mut and temporary variables being dropped. The builder pattern could probably be made to work better.)

kanerogers commented 1 year ago

How do you feel about just enabling the extension regardless? Doesn't seem like there'd be much of an issue doing that?

rasmusgo commented 1 year ago

How do you feel about just enabling the extension regardless? Doesn't seem like there'd be much of an issue doing that?

Sounds good to me! I'll try to find a good place to put it.

rasmusgo commented 1 year ago

Enabling it automatically breaks the compatibility with the hotham simulator:

Error [GENERAL | xrCreateInstance | OpenXR-Loader] : LoaderInstance::CreateInstance, no support found for requested extension: XR_KHR_win32_convert_performance_counter_time
Error [GENERAL | xrCreateInstance | OpenXR-Loader] : xrCreateInstance failed
thread 'main' panicked at '!!FATAL ERROR - Unable to initialize OpenXR!!: a requested extension is not supported', hotham\src\engine.rs:106:14