This commit is contained in:
Benjamin Saunders
2017-07-04 00:03:21 -07:00
parent 5014f02285
commit cfa525eee6
2 changed files with 16 additions and 11 deletions

View File

@ -32,8 +32,9 @@ impl<'a> Compositor<'a> {
temp.split(|&x| x == b' ').map(|x| CString::new(x.to_vec()).expect("extension name contained null byte")).collect() temp.split(|&x| x == b' ').map(|x| CString::new(x.to_vec()).expect("extension name contained null byte")).collect()
} }
pub fn vulkan_device_extensions_required(&self, physical_device: *mut VkPhysicalDevice_T) -> Vec<CString> { /// Safety: physical_device must be a valid VkPhysicalDevice
let temp = unsafe { pub unsafe fn vulkan_device_extensions_required(&self, physical_device: *mut VkPhysicalDevice_T) -> Vec<CString> {
let temp = {
let n = self.0.GetVulkanDeviceExtensionsRequired.unwrap()(physical_device, ptr::null_mut(), 0); let n = self.0.GetVulkanDeviceExtensionsRequired.unwrap()(physical_device, ptr::null_mut(), 0);
let mut buffer: Vec<u8> = Vec::new(); let mut buffer: Vec<u8> = Vec::new();
buffer.resize(n as usize, mem::uninitialized()); buffer.resize(n as usize, mem::uninitialized());
@ -69,7 +70,11 @@ impl<'a> Compositor<'a> {
/// Display the supplied texture for the next frame. /// Display the supplied texture for the next frame.
/// ///
/// If `bounds` is None, the entire texture will be used. Lens distortion is handled by the OpenVR implementation. /// If `bounds` is None, the entire texture will be used. Lens distortion is handled by the OpenVR implementation.
pub fn submit(&self, eye: Eye, texture: &Texture, bounds: Option<&texture::Bounds>) -> Result<(), CompositorError> { ///
/// # Safety
///
/// The handles you supply must be valid and comply with the graphics API's synchronization requirements.
pub unsafe fn submit(&self, eye: Eye, texture: &Texture, bounds: Option<&texture::Bounds>) -> Result<(), CompositorError> {
use self::texture::Handle::*; use self::texture::Handle::*;
let flags = match texture.handle { let flags = match texture.handle {
Vulkan(_) => sys::EVRSubmitFlags_EVRSubmitFlags_Submit_Default, Vulkan(_) => sys::EVRSubmitFlags_EVRSubmitFlags_Submit_Default,
@ -89,12 +94,11 @@ impl<'a> Compositor<'a> {
}, },
eColorSpace: texture.color_space as sys::EColorSpace, eColorSpace: texture.color_space as sys::EColorSpace,
}; };
let e = unsafe { let e = self.0.Submit.unwrap()(
self.0.Submit.unwrap()(eye as sys::EVREye, eye as sys::EVREye,
&texture as *const _ as *mut _, &texture as *const _ as *mut _,
bounds.map(|x| x as *const _ as *mut texture::Bounds as *mut _).unwrap_or(ptr::null_mut()), bounds.map(|x| x as *const _ as *mut texture::Bounds as *mut _).unwrap_or(ptr::null_mut()),
flags) flags);
};
if e == sys::EVRCompositorError_EVRCompositorError_VRCompositorError_None { if e == sys::EVRCompositorError_EVRCompositorError_VRCompositorError_None {
Ok(()) Ok(())
} else { } else {
@ -159,6 +163,7 @@ impl error::Error for CompositorError {
SHARED_TEXTURES_NOT_SUPPORTED => "SHARED_TEXTURES_NOT_SUPPORTED", SHARED_TEXTURES_NOT_SUPPORTED => "SHARED_TEXTURES_NOT_SUPPORTED",
INDEX_OUT_OF_RANGE => "INDEX_OUT_OF_RANGE", INDEX_OUT_OF_RANGE => "INDEX_OUT_OF_RANGE",
ALREADY_SUBMITTED => "ALREADY_SUBMITTED", ALREADY_SUBMITTED => "ALREADY_SUBMITTED",
INVALID_BOUNDS => "INVALID_BOUNDS",
_ => "UNKNOWN", _ => "UNKNOWN",
} }
} }

View File

@ -8,8 +8,8 @@ use openvr_sys as sys;
mod tracking; mod tracking;
mod system; pub mod system;
mod compositor; pub mod compositor;
pub use tracking::*; pub use tracking::*;