Skip to content

Commit

Permalink
refactor(client_openxr): ♻️ Do not recreate OpenXR session (#2519)
Browse files Browse the repository at this point in the history
* refactor(client_openxr): ♻️ Do not recreate OpenXR session

* Address comments
  • Loading branch information
zmerp authored Nov 29, 2024
1 parent 587bdc3 commit 04d9b69
Show file tree
Hide file tree
Showing 6 changed files with 517 additions and 491 deletions.
46 changes: 42 additions & 4 deletions alvr/client_openxr/src/extra_extensions/multimodal_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,32 @@ pub const META_DETACHED_CONTROLLERS_EXTENSION_NAME: &str = "XR_META_detached_con

static TYPE_SIMULTANEOUS_HANDS_AND_CONTROLLERS_TRACKING_RESUME_INFO_META: Lazy<xr::StructureType> =
Lazy::new(|| xr::StructureType::from_raw(1000532002));
static TYPE_SIMULTANEOUS_HANDS_AND_CONTROLLERS_TRACKING_PAUSE_INFO_META: Lazy<xr::StructureType> =
Lazy::new(|| xr::StructureType::from_raw(1000532003));

#[repr(C)]
pub struct SimultaneousHandsAndControllersTrackingResumeInfoMETA {
ty: xr::StructureType,
next: *const c_void,
}
#[repr(C)]
pub struct SimultaneousHandsAndControllersTrackingPauseInfoMETA {
ty: xr::StructureType,
next: *const c_void,
}

pub type ResumeSimultaneousHandsAndControllersTrackingMETA =
unsafe extern "system" fn(
sys::Session,
*const SimultaneousHandsAndControllersTrackingResumeInfoMETA,
) -> sys::Result;
pub type PauseSimultaneousHandsAndControllersTrackingMETA =
unsafe extern "system" fn(
sys::Session,
*const SimultaneousHandsAndControllersTrackingPauseInfoMETA,
) -> sys::Result;

pub fn resume_simultaneous_hands_and_controllers_tracking<G>(
pub fn resume_simultaneous_hands_and_controllers_tracking_meta<G>(
session: &xr::Session<G>,
) -> xr::Result<()> {
let resume_simultaneous_hands_and_controllers_tracking_meta = unsafe {
Expand All @@ -48,13 +60,39 @@ pub fn resume_simultaneous_hands_and_controllers_tracking<G>(
ty: *TYPE_SIMULTANEOUS_HANDS_AND_CONTROLLERS_TRACKING_RESUME_INFO_META,
next: ptr::null(),
};

unsafe {
super::xr_res(resume_simultaneous_hands_and_controllers_tracking_meta(
session.as_raw(),
&resume_info,
))?;
))
}
}

pub fn pause_simultaneous_hands_and_controllers_tracking_meta<G>(
session: &xr::Session<G>,
) -> xr::Result<()> {
let pause_simultaneous_hands_and_controllers_tracking_meta = unsafe {
let mut pause_simultaneous_hands_and_controllers_tracking_meta = None;
let _ = (session.instance().fp().get_instance_proc_addr)(
session.instance().as_raw(),
c"xrPauseSimultaneousHandsAndControllersTrackingMETA".as_ptr(),
&mut pause_simultaneous_hands_and_controllers_tracking_meta,
);

pause_simultaneous_hands_and_controllers_tracking_meta.map(|pfn| {
mem::transmute::<VoidFunction, PauseSimultaneousHandsAndControllersTrackingMETA>(pfn)
})
}
.ok_or(sys::Result::ERROR_EXTENSION_NOT_PRESENT)?;

Ok(())
let pause_info = SimultaneousHandsAndControllersTrackingPauseInfoMETA {
ty: *TYPE_SIMULTANEOUS_HANDS_AND_CONTROLLERS_TRACKING_PAUSE_INFO_META,
next: ptr::null(),
};
unsafe {
super::xr_res(pause_simultaneous_hands_and_controllers_tracking_meta(
session.as_raw(),
&pause_info,
))
}
}
Loading

0 comments on commit 04d9b69

Please sign in to comment.