updated to latest rustc

This commit is contained in:
Colin Sherratt
2014-07-01 01:34:12 -04:00
parent 148d7693b2
commit 53424c97f7

View File

@ -5,7 +5,7 @@
extern crate cgmath; extern crate cgmath;
extern crate libc; extern crate libc;
use libc::{c_int, c_uint, c_void, c_float}; use libc::{c_int, c_uint, c_void, c_float, c_double};
use std::str::raw::from_c_str; use std::str::raw::from_c_str;
use std::default::Default; use std::default::Default;
use std::ptr; use std::ptr;
@ -108,10 +108,10 @@ pub mod ll {
pub enum Hmd {} pub enum Hmd {}
pub struct HmdDesc { pub struct HmdDesc {
pub handle: *Hmd, pub handle: *const Hmd,
pub hmd_type: c_int, pub hmd_type: c_int,
pub product_name: *c_char, pub product_name: *const c_char,
pub manufacture: *c_char, pub manufacture: *const c_char,
pub hmd_capabilities: c_uint, pub hmd_capabilities: c_uint,
pub sensor_capabilities: c_uint, pub sensor_capabilities: c_uint,
pub distortion_capabilities: c_uint, pub distortion_capabilities: c_uint,
@ -120,7 +120,7 @@ pub mod ll {
pub default_eye_fov: [FovPort, ..2], pub default_eye_fov: [FovPort, ..2],
pub max_eye_fov: [FovPort, ..2], pub max_eye_fov: [FovPort, ..2],
pub eye_render_order: [c_uint, ..2], pub eye_render_order: [c_uint, ..2],
pub display_device_name: *c_char, pub display_device_name: *const c_char,
pub display_id: c_int pub display_id: c_int
} }
@ -168,9 +168,9 @@ pub mod ll {
pub struct RenderApiConfig { pub struct RenderApiConfig {
pub header: RenderApiConfigHeader, pub header: RenderApiConfigHeader,
pub display: *c_void, pub display: *const c_void,
pub window: *c_void, pub window: *const c_void,
pub padd: [*c_void, ..6] pub padd: [*const c_void, ..6]
} }
pub struct FrameTiming { pub struct FrameTiming {
@ -191,7 +191,7 @@ pub mod ll {
pub struct Texture { pub struct Texture {
pub header: TextureHeader, pub header: TextureHeader,
pub texture_id: u32, pub texture_id: u32,
pub padd: [*c_void, ..7] pub padd: [*const c_void, ..7]
} }
pub static Hmd_None : c_int = 0; pub static Hmd_None : c_int = 0;
@ -238,64 +238,87 @@ pub mod ll {
pub fn ovr_Initialize() -> bool; pub fn ovr_Initialize() -> bool;
pub fn ovr_Shutdown(); pub fn ovr_Shutdown();
pub fn ovrHmd_Detect() -> c_int; pub fn ovrHmd_Detect() -> c_int;
pub fn ovrHmd_Create(index: c_int) -> *Hmd; pub fn ovrHmd_Create(index: c_int) -> *mut Hmd;
pub fn ovrHmd_Destroy(hmd: *Hmd); pub fn ovrHmd_Destroy(hmd: *mut Hmd);
pub fn ovrHmd_CreateDebug(hmd_type: c_int) -> *Hmd; pub fn ovrHmd_CreateDebug(hmd_type: c_int) -> *mut Hmd;
pub fn ovrHmd_GetLastError(hmd: *Hmd) -> *c_char; pub fn ovrHmd_GetLastError(hmd: *mut Hmd) -> *const c_char;
pub fn ovrHmd_GetEnabledCaps(hmd: *Hmd) -> c_uint; pub fn ovrHmd_GetEnabledCaps(hmd: *mut Hmd) -> c_uint;
pub fn ovrHmd_SetEnabledCaps(hmd: *Hmd, flags: c_uint); pub fn ovrHmd_SetEnabledCaps(hmd: *mut Hmd, flags: c_uint);
pub fn ovrHmd_StartSensor(hmd: *Hmd, pub fn ovrHmd_StartSensor(hmd: *mut Hmd,
supported: c_uint, supported: c_uint,
required: c_uint) -> bool; required: c_uint) -> bool;
pub fn ovrHmd_StopSensor(hmd: *Hmd); pub fn ovrHmd_StopSensor(hmd: *mut Hmd);
pub fn ovrHmd_ResetSensor(hmd: *Hmd); pub fn ovrHmd_ResetSensor(hmd: *mut Hmd);
pub fn ovrHmd_GetSensorState(hmd: *Hmd, pub fn ovrHmd_GetSensorState(hmd: *mut Hmd,
absTime: c_double) -> SensorState; absTime: c_double) -> SensorState;
pub fn ovrHmd_GetSensorDesc(hmd: *Hmd, pub fn ovrHmd_GetSensorDesc(hmd: *mut Hmd,
sensor_desc: *SensorDesc) -> bool; sensor_desc: *mut SensorDesc) -> bool;
pub fn ovrHmd_GetDesc(hmd: *Hmd, pub fn ovrHmd_GetDesc(hmd: *mut Hmd,
size: *HmdDesc); size: *mut HmdDesc);
pub fn ovrHmd_GetFovTextureSize(hmd: *Hmd, pub fn ovrHmd_GetFovTextureSize(hmd: *mut Hmd,
eye: c_uint, eye: c_uint,
fov: FovPort, fov: FovPort,
pixels: c_float) -> Sizei; pixels: c_float) -> Sizei;
pub fn ovrHmd_ConfigureRendering(hmd: *Hmd, pub fn ovrHmd_ConfigureRendering(hmd: *mut Hmd,
apiConfig: *RenderApiConfig, apiConfig: *const RenderApiConfig,
distortionCaps: c_uint, distortionCaps: c_uint,
fov_in: *FovPort, fov_in: *const FovPort,
render_desc_out: *EyeRenderDesc) -> bool; render_desc_out: *mut EyeRenderDesc) -> bool;
pub fn ovrHmd_BeginFrame(hmd: *Hmd, pub fn ovrHmd_BeginFrame(hmd: *mut Hmd,
frame_index: c_uint) -> FrameTiming; frame_index: c_uint) -> FrameTiming;
pub fn ovrHmd_EndFrame(hmd: *Hmd); pub fn ovrHmd_EndFrame(hmd: *mut Hmd);
pub fn ovrHmd_BeginEyeRender(hmd: *Hmd, eye: c_uint) -> Posef; pub fn ovrHmd_BeginEyeRender(hmd: *mut Hmd, eye: c_uint) -> Posef;
pub fn ovrHmd_EndEyeRender(hmd: *Hmd, eye: c_uint, pub fn ovrHmd_EndEyeRender(hmd: *mut Hmd, eye: c_uint,
pose: Posef, texture: *Texture); pose: Posef, texture: *const Texture);
pub fn ovrMatrix4f_Projection(fov: FovPort, pub fn ovrMatrix4f_Projection(fov: FovPort,
znear: c_float, znear: c_float,
zfar: c_float, zfar: c_float,
right_handed: bool) -> Matrix4f; right_handed: bool) -> Matrix4f;
pub fn ovr_WaitTillTime(absTime: c_double) -> c_double;
pub fn ovr_GetTimeInSeconds() -> c_double;
} }
} }
#[repr(C)]
pub fn get_time() -> f64 {
unsafe{ ll::ovr_GetTimeInSeconds() as f64 }
}
pub fn wait_till_time(time: f64) -> f64 {
unsafe{ ll::ovr_WaitTillTime(time as c_double) as f64 }
}
pub enum HmdType { pub enum HmdType {
HmdNone = ll::Hmd_None, HmdNone,
HmdDK1 = ll::Hmd_DK1, HmdDK1,
HmdDKHD = ll::Hmd_DKHD, HmdDKHD,
HmdCrystalCoveProto = ll::Hmd_CrystalCoveProto, HmdCrystalCoveProto,
HmdDK2 = ll::Hmd_DK2, HmdDK2,
HmdOther = ll::Hmd_Other HmdOther
} }
impl HmdType { impl HmdType {
fn from_ll(c: c_int) -> HmdType { fn from_ll(c: c_int) -> HmdType {
match c { match c {
ll::Hmd_None => {HmdNone} ll::Hmd_None => HmdNone,
ll::Hmd_DK1 => {HmdDK1} ll::Hmd_DK1 => HmdDK1,
ll::Hmd_DKHD => {HmdDKHD} ll::Hmd_DKHD => HmdDKHD,
ll::Hmd_CrystalCoveProto => {HmdCrystalCoveProto} ll::Hmd_CrystalCoveProto => HmdCrystalCoveProto,
ll::Hmd_DK2 => {HmdDK2} ll::Hmd_DK2 => HmdDK2,
_ => {HmdOther} _ => HmdOther
}
}
fn to_ll(&self) -> c_int {
match *self {
HmdNone => ll::Hmd_None,
HmdDK1 => ll::Hmd_DK1,
HmdDKHD => ll::Hmd_DKHD,
HmdCrystalCoveProto => ll::Hmd_CrystalCoveProto,
HmdDK2 => ll::Hmd_DK2,
HmdOther => ll::Hmd_Other
} }
} }
} }
@ -339,7 +362,7 @@ impl Ovr {
pub fn create_hmd_debug(&self, hmd_type: HmdType) -> Option<Hmd> { pub fn create_hmd_debug(&self, hmd_type: HmdType) -> Option<Hmd> {
unsafe { unsafe {
let ptr = ll::ovrHmd_CreateDebug(hmd_type as c_int); let ptr = ll::ovrHmd_CreateDebug(hmd_type.to_ll());
if !ptr.is_null() { if !ptr.is_null() {
Some(Hmd{ptr:ptr}) Some(Hmd{ptr:ptr})
} else { } else {
@ -356,7 +379,7 @@ impl Drop for Ovr {
} }
pub struct Hmd { pub struct Hmd {
ptr: *ll::Hmd ptr: *mut ll::Hmd
} }
impl Drop for Hmd { impl Drop for Hmd {
@ -419,13 +442,13 @@ impl Hmd {
pub fn get_sensor_description(&self) -> Option<SensorDescription> { pub fn get_sensor_description(&self) -> Option<SensorDescription> {
unsafe { unsafe {
let c_desc = ll::SensorDesc { let mut c_desc = ll::SensorDesc {
vendor_id: 0, vendor_id: 0,
product_id: 0, product_id: 0,
serial_number: [0,.. 24] serial_number: [0,.. 24]
}; };
if !ll::ovrHmd_GetSensorDesc(self.ptr, &c_desc as *ll::SensorDesc) { if !ll::ovrHmd_GetSensorDesc(self.ptr, &mut c_desc as *mut ll::SensorDesc) {
None None
} else { } else {
Some(SensorDescription::from_ll(c_desc)) Some(SensorDescription::from_ll(c_desc))
@ -435,8 +458,8 @@ impl Hmd {
pub fn get_description(&self) -> HmdDescription { pub fn get_description(&self) -> HmdDescription {
unsafe { unsafe {
let c_desc = Default::default(); let mut c_desc = Default::default();
ll::ovrHmd_GetDesc(self.ptr, &c_desc); ll::ovrHmd_GetDesc(self.ptr, &mut c_desc);
HmdDescription::from_ll(c_desc) HmdDescription::from_ll(c_desc)
} }
} }
@ -458,15 +481,14 @@ impl Hmd {
cap: DistortionCapabilities, cap: DistortionCapabilities,
eye_fov: PerEye<FovPort>) -> Option<PerEye<EyeRenderDescriptor>> { eye_fov: PerEye<FovPort>) -> Option<PerEye<EyeRenderDescriptor>> {
unsafe { unsafe {
let out: PerEye<ll::EyeRenderDesc> let mut out: PerEye<ll::EyeRenderDesc> = PerEye::new(Default::default(),
= PerEye::new(Default::default(), Default::default());
Default::default());
let was_started = ll::ovrHmd_ConfigureRendering( let was_started = ll::ovrHmd_ConfigureRendering(
self.ptr, self.ptr,
&api_config.to_render_config(), &api_config.to_render_config(),
cap.flags, cap.flags,
eye_fov.map(|_, d| d.to_ll()).ptr(), eye_fov.map(|_, d| d.to_ll()).ptr(),
out.ptr() out.mut_ptr()
); );
if was_started { if was_started {
@ -885,8 +907,8 @@ impl<T> PerEye<T> {
) )
} }
pub unsafe fn ptr(&self) -> *T { pub unsafe fn ptr(&self) -> *const T {
&self.left as *T &self.left as *const T
} }
pub unsafe fn mut_ptr(&mut self) -> *mut T { pub unsafe fn mut_ptr(&mut self) -> *mut T {
@ -978,8 +1000,8 @@ impl EyeRenderDescriptor {
pub struct RenderGLConfig { pub struct RenderGLConfig {
pub size: ll::Sizei, pub size: ll::Sizei,
pub multisample: int, pub multisample: int,
pub display: Option<*c_void>, pub display: Option<*const c_void>,
pub window: Option<*c_void> pub window: Option<*const c_void>
} }
pub trait ToRenderConfig { pub trait ToRenderConfig {