|
| 1 | +use ash::vk; |
| 2 | +use std::{ |
| 3 | + ffi::{c_char, CStr}, |
| 4 | + time::Instant, |
| 5 | +}; |
| 6 | + |
| 7 | +#[repr(C)] |
| 8 | +#[derive(Clone, Copy)] |
| 9 | +pub struct AlvrFov { |
| 10 | + /// Negative, radians |
| 11 | + pub left: f32, |
| 12 | + /// Positive, radians |
| 13 | + pub right: f32, |
| 14 | + /// Positive, radians |
| 15 | + pub up: f32, |
| 16 | + /// Negative, radians |
| 17 | + pub down: f32, |
| 18 | +} |
| 19 | + |
| 20 | +#[repr(C)] |
| 21 | +#[derive(Clone, Copy)] |
| 22 | +pub struct AlvrQuat { |
| 23 | + pub x: f32, |
| 24 | + pub y: f32, |
| 25 | + pub z: f32, |
| 26 | + pub w: f32, |
| 27 | +} |
| 28 | +impl Default for AlvrQuat { |
| 29 | + fn default() -> Self { |
| 30 | + Self { |
| 31 | + x: 0.0, |
| 32 | + y: 0.0, |
| 33 | + z: 0.0, |
| 34 | + w: 1.0, |
| 35 | + } |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +#[repr(C)] |
| 40 | +#[derive(Clone, Copy, Default)] |
| 41 | +pub struct AlvrPose { |
| 42 | + orientation: AlvrQuat, |
| 43 | + position: [f32; 3], |
| 44 | +} |
| 45 | + |
| 46 | +#[repr(C)] |
| 47 | +#[derive(Clone, Copy)] |
| 48 | +pub struct AlvrSpaceRelation { |
| 49 | + pub pose: AlvrPose, |
| 50 | + pub linear_velocity: [f32; 3], |
| 51 | + pub angular_velocity: [f32; 3], |
| 52 | + pub has_velocity: bool, |
| 53 | +} |
| 54 | + |
| 55 | +#[repr(C)] |
| 56 | +#[derive(Clone, Copy)] |
| 57 | +pub struct AlvrJoint { |
| 58 | + relation: AlvrSpaceRelation, |
| 59 | + radius: f32, |
| 60 | +} |
| 61 | + |
| 62 | +#[repr(C)] |
| 63 | +#[derive(Clone, Copy)] |
| 64 | +pub struct AlvrJointSet { |
| 65 | + values: [AlvrJoint; 26], |
| 66 | + global_hand_relation: AlvrSpaceRelation, |
| 67 | + is_active: bool, |
| 68 | +} |
| 69 | + |
| 70 | +#[repr(C)] |
| 71 | +#[derive(Clone, Copy)] |
| 72 | +pub union AlvrInputValue { |
| 73 | + pub bool_: bool, |
| 74 | + pub float_: f32, |
| 75 | +} |
| 76 | + |
| 77 | +// the profile is implied |
| 78 | +#[repr(C)] |
| 79 | +#[derive(Clone, Copy)] |
| 80 | +pub struct AlvrInput { |
| 81 | + pub id: u64, |
| 82 | + pub value: AlvrInputValue, |
| 83 | +} |
| 84 | + |
| 85 | +#[repr(u8)] |
| 86 | +#[derive(Clone, Copy)] |
| 87 | +pub enum AlvrOutput { |
| 88 | + Haptics { |
| 89 | + frequency: f32, |
| 90 | + amplitude: f32, |
| 91 | + duration_ns: u64, |
| 92 | + }, |
| 93 | +} |
| 94 | + |
| 95 | +#[repr(C)] |
| 96 | +#[derive(Clone, Copy)] |
| 97 | +pub struct AlvrBatteryValue { |
| 98 | + pub device_id: u64, |
| 99 | + /// range [0, 1] |
| 100 | + pub value: f32, |
| 101 | +} |
| 102 | + |
| 103 | +#[repr(C)] |
| 104 | +pub enum AlvrEvent { |
| 105 | + Battery(AlvrBatteryValue), |
| 106 | + Bounds([f32; 2]), |
| 107 | + Restart, |
| 108 | + Shutdown, |
| 109 | +} |
| 110 | + |
| 111 | +#[repr(C)] |
| 112 | +#[derive(Clone, Copy)] |
| 113 | +pub struct AlvrTargetConfig { |
| 114 | + target_width: u32, |
| 115 | + target_height: u32, |
| 116 | +} |
| 117 | + |
| 118 | +#[repr(C)] |
| 119 | +#[derive(Clone, Copy)] |
| 120 | +pub struct AlvrDeviceConfig { |
| 121 | + device_id: u64, |
| 122 | + interaction_profile_id: u64, |
| 123 | +} |
| 124 | + |
| 125 | +// Get ALVR server time. The libalvr user should provide timestamps in the provided time frame of |
| 126 | +// reference in the following functions |
| 127 | +#[no_mangle] |
| 128 | +pub unsafe extern "C" fn alvr_get_time_ns() -> u64 { |
| 129 | + Instant::now().elapsed().as_nanos() as u64 |
| 130 | +} |
| 131 | + |
| 132 | +// The libalvr user is responsible of interpreting values and calling functions using |
| 133 | +// device/input/output identifiers obtained using this function |
| 134 | +#[no_mangle] |
| 135 | +pub unsafe extern "C" fn alvr_path_to_id(path_string: *const c_char) -> u64 { |
| 136 | + alvr_common::hash_string(CStr::from_ptr(path_string).to_str().unwrap()) |
| 137 | +} |
| 138 | + |
| 139 | +#[no_mangle] |
| 140 | +pub unsafe extern "C" fn alvr_initialize(out_target_config: *mut AlvrTargetConfig) { |
| 141 | + todo!() |
| 142 | +} |
| 143 | + |
| 144 | +#[no_mangle] |
| 145 | +pub unsafe extern "C" fn alvr_poll_event(out_event: *mut AlvrEvent) -> bool { |
| 146 | + todo!() |
| 147 | +} |
| 148 | + |
| 149 | +#[no_mangle] |
| 150 | +pub unsafe extern "C" fn alvr_shutdown() { |
| 151 | + todo!() |
| 152 | +} |
| 153 | + |
| 154 | +// Device API: |
| 155 | + |
| 156 | +// Use the two-call pattern to first get the array length then the array data. |
| 157 | +#[no_mangle] |
| 158 | +pub unsafe extern "C" fn alvr_get_devices(out_device_configs: *mut AlvrDeviceConfig) -> u64 { |
| 159 | + todo!() |
| 160 | +} |
| 161 | + |
| 162 | +// After this call, previous button and tracking data is discarded |
| 163 | +#[no_mangle] |
| 164 | +pub unsafe extern "C" fn alvr_update_inputs(device_id: u64) { |
| 165 | + todo!() |
| 166 | +} |
| 167 | + |
| 168 | +// Use the two-call pattern to first get the array length then the array data. |
| 169 | +// Data is updated after a call to alvr_update_inputs. |
| 170 | +#[no_mangle] |
| 171 | +pub unsafe extern "C" fn alvr_get_inputs( |
| 172 | + device_id: u64, |
| 173 | + out_inputs_arr: *mut AlvrInput, |
| 174 | + out_timestamp_ns: u64, |
| 175 | +) -> u64 { |
| 176 | + todo!() |
| 177 | +} |
| 178 | + |
| 179 | +// pose_id is something like /user/hand/left/input/grip/pose |
| 180 | +#[no_mangle] |
| 181 | +pub unsafe extern "C" fn alvr_get_tracked_pose( |
| 182 | + pose_id: u64, |
| 183 | + timestamp_ns: u64, |
| 184 | + out_relation: *mut AlvrSpaceRelation, |
| 185 | +) { |
| 186 | + todo!() |
| 187 | +} |
| 188 | + |
| 189 | +#[no_mangle] |
| 190 | +pub unsafe extern "C" fn alvr_get_hand_tracking( |
| 191 | + device_id: u64, |
| 192 | + timestamp_ns: u64, |
| 193 | + out_joint_set: *mut AlvrJointSet, |
| 194 | +) { |
| 195 | + todo!() |
| 196 | +} |
| 197 | + |
| 198 | +// Currently only haptics is supported |
| 199 | +#[no_mangle] |
| 200 | +pub unsafe extern "C" fn alvr_set_output(output_id: u64, value: *const AlvrOutput) { |
| 201 | + todo!() |
| 202 | +} |
| 203 | + |
| 204 | +#[no_mangle] |
| 205 | +pub unsafe extern "C" fn alvr_view_poses( |
| 206 | + out_head_relation: *mut AlvrSpaceRelation, |
| 207 | + out_fov_arr: *mut AlvrFov, // 2 elements |
| 208 | + out_relative_pose_arr: *mut AlvrPose, // 2 elements |
| 209 | +) { |
| 210 | + todo!() |
| 211 | +} |
| 212 | + |
| 213 | +#[no_mangle] |
| 214 | +pub unsafe extern "C" fn alvr_destroy_device(device_id: u64) { |
| 215 | + todo!() |
| 216 | +} |
| 217 | + |
| 218 | +// Compositor target API: |
| 219 | + |
| 220 | +// This should reflect the client current framerate |
| 221 | +#[no_mangle] |
| 222 | +pub unsafe extern "C" fn alvr_get_framerate() -> f32 { |
| 223 | + todo!() |
| 224 | +} |
| 225 | + |
| 226 | +#[no_mangle] |
| 227 | +pub unsafe extern "C" fn alvr_pre_vulkan() { |
| 228 | + todo!() |
| 229 | +} |
| 230 | + |
| 231 | +#[no_mangle] |
| 232 | +pub unsafe extern "C" fn alvr_post_vulkan() { |
| 233 | + todo!() |
| 234 | +} |
| 235 | + |
| 236 | +#[no_mangle] |
| 237 | +pub unsafe extern "C" fn alvr_create_vk_target_swapchain( |
| 238 | + width: u32, |
| 239 | + height: u32, |
| 240 | + color_format: vk::Format, |
| 241 | + color_space: vk::ColorSpaceKHR, |
| 242 | + image_usage: vk::ImageUsageFlags, |
| 243 | + present_mode: vk::PresentModeKHR, |
| 244 | + image_count: u64, |
| 245 | +) { |
| 246 | + todo!() |
| 247 | +} |
| 248 | + |
| 249 | +#[no_mangle] |
| 250 | +pub unsafe extern "C" fn alvr_acquire_image(out_swapchain_index: u64) -> vk::Result { |
| 251 | + todo!() |
| 252 | +} |
| 253 | + |
| 254 | +#[no_mangle] |
| 255 | +pub unsafe extern "C" fn alvr_present( |
| 256 | + queue: vk::Queue, |
| 257 | + swapchain_index: u64, |
| 258 | + timeline_semaphore_value: u64, |
| 259 | + timestamp_ns: u64, |
| 260 | +) -> vk::Result { |
| 261 | + todo!() |
| 262 | +} |
| 263 | + |
| 264 | +#[no_mangle] |
| 265 | +pub unsafe extern "C" fn alvr_destroy_vk_target_swapchain() { |
| 266 | + todo!() |
| 267 | +} |
0 commit comments