mirror of
https://github.com/mii443/rust-openvr.git
synced 2025-08-23 16:49:31 +00:00
Added groundwork for the compositor
This commit is contained in:
@ -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/");
|
||||
|
||||
|
||||
}
|
@ -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 ();
|
||||
}
|
||||
"""
|
||||
|
||||
|
42
src/lib.rs
42
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<Compositor, openvr_sys::HmdError> {
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user