From cad1e5fcda8b24c2364419bead27fa66e8a0d603 Mon Sep 17 00:00:00 2001 From: Colin Sherratt Date: Sun, 5 Jul 2015 00:06:45 -0400 Subject: [PATCH] Added groundwork for the compositor --- examples/test.rs | 14 ++++++++++++++ scripts/gen.py | 1 + src/lib.rs | 42 +++++++++++++++++++++++++++++++++++++++++- src/sys/lib.rs | 1 + 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/examples/test.rs b/examples/test.rs index 98039ed..4f759da 100644 --- a/examples/test.rs +++ b/examples/test.rs @@ -23,5 +23,19 @@ fn main() { println!("eye_to_head: {:?}", ivr.eye_to_head_transform(vr::Eye::Left)); println!("vsync: {:?}", ivr.time_since_last_vsync()); println!("poses {:?}", ivr.tracked_devices(0.).as_slice()); + + println!("Trying to create a compositor"); + match ivr.compositor() { + Err(err) => println!("Could not create compositor {:?}", err), + Ok(comp) => { + println!("\tCreated one!"); + println!("\tis fullscreen ={}", comp.is_fullscreen()); + println!("\tis vsync ={}", comp.get_vsync()); + println!("\tcan render scene ={}", comp.can_render_scene()); + } + } + println!("Done! \\o/"); + + } \ No newline at end of file diff --git a/scripts/gen.py b/scripts/gen.py index 8066918..7a59a7d 100644 --- a/scripts/gen.py +++ b/scripts/gen.py @@ -90,6 +90,7 @@ extern "C" { pub fn VR_Shutdown(); pub fn VR_IsHmdPresent() -> bool; pub fn VR_GetStringForHmdError(err: HmdError) -> *const u8; + pub fn VR_GetGenericInterface(name: *const u8, err: *mut HmdError) -> *const (); } """ diff --git a/src/lib.rs b/src/lib.rs index 4345b25..9f66a57 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -195,6 +195,7 @@ impl IVRSystem { } } + /// Fetch the tracked results from the HMD pub fn tracked_devices(&self, time: f32) -> TrackedDevicePoses { unsafe { let mut data: [openvr_sys::TrackedDevicePose_t; 16] = std::mem::zeroed(); @@ -221,6 +222,19 @@ impl IVRSystem { out } } + + /// If the device supports a compositor return a instance + pub fn compositor(&self) -> Result { + unsafe { + let mut err = openvr_sys::HmdError::None; + let name = std::ffi::CString::new("IVRCompositor_006").unwrap(); + let ptr = openvr_sys::VR_GetGenericInterface(name.as_ptr(), &mut err as *mut openvr_sys::HmdError); + match err { + openvr_sys::HmdError::None => Ok(Compositor(ptr)), + err => Err(err) + } + } + } } impl Drop for IVRSystem { @@ -231,4 +245,30 @@ impl Drop for IVRSystem { println!("Should be done now."); } } -} \ No newline at end of file +} + +/// A VR compositor +pub struct Compositor(*const ()); + +impl Compositor { + /// Check to see if the compositor is fullscreen + pub fn is_fullscreen(&self) -> bool { + unsafe { + openvr_sys::VR_IVRCompositor_IsFullscreen(self.0) + } + } + + /// Check if vsync in enabled + pub fn get_vsync(&self) -> bool { + unsafe { + openvr_sys::VR_IVRCompositor_GetVSync(self.0) + } + } + + /// Check if vsync in enabled + pub fn can_render_scene(&self) -> bool { + unsafe { + openvr_sys::VR_IVRCompositor_CanRenderScene(self.0) + } + } +} diff --git a/src/sys/lib.rs b/src/sys/lib.rs index d844d5c..02b4db7 100755 --- a/src/sys/lib.rs +++ b/src/sys/lib.rs @@ -11,6 +11,7 @@ extern "C" { pub fn VR_Shutdown(); pub fn VR_IsHmdPresent() -> bool; pub fn VR_GetStringForHmdError(err: HmdError) -> *const u8; + pub fn VR_GetGenericInterface(name: *const i8, err: *mut HmdError) -> *const (); } pub type TrackedDeviceIndex_t = u32;