ovr_sys/lib.rs
1//! This crate provides raw unsafe bindings to LibOVR, the Oculus Rift runtime library.
2//!
3//! **The currently targeted version of LibOVR is 1.15.0**
4//!
5//! Good API documentation is provided here, transformed from the original doxygen documentation.
6//! More high level documentation can be found on [the Oculus developer web site](https://developer.oculus.com).
7//! Example code has been translated from C to mostly equivalent Rust (TODO: except in the DirectX module).
8//!
9//! The bindings are generated directly from the LibOVR headers, and some conventions have been
10//! followed when translating from the C code.
11//!
12//! * Each enum has been translated into a type definition (defined to be `i32`) and a collection of
13//! constants. This preserves the ability to easily use them as bitflags.
14//! * Alignment requirements on structs have been implemented using dummy zero-sized array fields.
15//! When initialising these fields, the value `[]` will suffice.
16//! * Where the layout of structs differs between 32-bit and 64-bit platforms due to dummy padding
17//! fields, conditional compilation is used. For this reason it is recommended to not construct the
18//! affected structs in a typical fashion as this may result in code that compiles on one but not both
19//! architectures (due to missing/spurious padding field).
20//!
21//! A reasonable approach is to use `..` struct initialisation syntax, like so:
22//!
23//! ```no_run
24//! # use ovr_sys::*;
25//! # use ::std::mem;
26//! # unsafe {
27//! let init_params = ovrInitParams {
28//! Flags: ovrInit_RequestVersion,
29//! RequestedMinorVersion: OVR_MINOR_VERSION,
30//! LogCallback: None,
31//! UserData: 0,
32//! ConnectionTimeoutMS: 0,
33//! .. mem::uninitialized()
34//! };
35//! # drop(init_params);
36//! # }
37//! ```
38//!
39//! Like all unsafe code uses of `::std::mem::uninitialized()` should be scrutinised for mistakes.
40//! * Function-like C macros have been translated into functions with the same name.
41//!
42//! Optional features are provided in sub-modules. These features are `audio`, `directx`, `opengl` and `vulkan`.
43//! These sub-modules will only be present if the corresponding feature has been enabled in the
44//! Cargo manifest. `opengl` is enabled by default.
45
46#![allow(non_camel_case_types, non_upper_case_globals, non_snake_case)]
47
48extern crate libc;
49
50#[cfg(all(feature = "directx", windows))]
51extern crate winapi;
52
53#[cfg(feature = "vulkan")]
54extern crate vks;
55
56use libc::{
57 c_char,
58 c_int,
59 c_uint,
60 c_uint as c_unsigned,
61 c_short,
62 c_longlong,
63 c_void
64};
65
66use ::std::fmt;
67
68/// LibOVR functions for performing OpenGL interop.
69#[cfg(feature = "opengl")]
70pub mod opengl;
71/// LibOVR functions for performing DirectX interop.
72#[cfg(all(feature = "directx", windows))]
73pub mod directx;
74/// LibOVR functions for performing Vulkan interop.
75#[cfg(all(feature = "vulkan"))]
76pub mod vulkan;
77/// LibOVR functions associated with audio functionality, including identifying audio devices and
78/// converting audio data into haptics data.
79#[cfg(all(feature = "audio", windows))]
80pub mod audio;
81
82pub const OVR_PRODUCT_VERSION: u32 = 1;
83pub const OVR_MAJOR_VERSION: u32 = 1;
84pub const OVR_MINOR_VERSION: u32 = 15;
85pub const OVR_BUILD_VERSION: u32 = 0;
86
87pub const OVR_KEY_USER: &'static [u8] = b"User\0"; // string
88
89pub const OVR_KEY_NAME: &'static [u8] = b"Name\0"; // string
90
91pub const OVR_KEY_GENDER: &'static [u8] = b"Gender\0"; // string = b"Male", = b"Female", or = b"Unknown"
92pub const OVR_DEFAULT_GENDER: &'static [u8] = b"Unknown\0";
93
94pub const OVR_KEY_PLAYER_HEIGHT: &'static [u8] = b"PlayerHeight\0"; // float meters
95pub const OVR_DEFAULT_PLAYER_HEIGHT: f32 = 1.778;
96
97pub const OVR_KEY_EYE_HEIGHT: &'static [u8] = b"EyeHeight\0"; // float meters
98pub const OVR_DEFAULT_EYE_HEIGHT: f32 = 1.675;
99
100pub const OVR_KEY_NECK_TO_EYE_DISTANCE: &'static [u8] = b"NeckEyeDistance\0"; // float[2] meters
101pub const OVR_DEFAULT_NECK_TO_EYE_HORIZONTAL: f32 = 0.0805;
102pub const OVR_DEFAULT_NECK_TO_EYE_VERTICAL: f32 = 0.075;
103
104pub const OVR_KEY_EYE_TO_NOSE_DISTANCE: &'static [u8] = b"EyeToNoseDist\0"; // float[2] meters
105
106pub const OVR_PERF_HUD_MODE: &'static [u8] = b"PerfHudMode\0"; // int, allowed values are defined in enum ovrPerfHudMode
107
108pub const OVR_LAYER_HUD_MODE: &'static [u8] = b"LayerHudMode\0"; // int, allowed values are defined in enum ovrLayerHudMode
109pub const OVR_LAYER_HUD_CURRENT_LAYER: &'static [u8] = b"LayerHudCurrentLayer\0"; // int, The layer to show
110pub const OVR_LAYER_HUD_SHOW_ALL_LAYERS: &'static [u8] = b"LayerHudShowAll\0"; // bool, Hide other layers when the hud is enabled
111
112pub const OVR_DEBUG_HUD_STEREO_MODE: &'static [u8] = b"DebugHudStereoMode\0"; // int, allowed values are defined in enum ovrDebugHudStereoMode
113pub const OVR_DEBUG_HUD_STEREO_GUIDE_INFO_ENABLE: &'static [u8] = b"DebugHudStereoGuideInfoEnable\0"; // bool
114pub const OVR_DEBUG_HUD_STEREO_GUIDE_SIZE: &'static [u8] = b"DebugHudStereoGuideSize2f\0"; // float[2]
115pub const OVR_DEBUG_HUD_STEREO_GUIDE_POSITION: &'static [u8] = b"DebugHudStereoGuidePosition3f\0"; // float[3]
116pub const OVR_DEBUG_HUD_STEREO_GUIDE_YAWPITCHROLL: &'static [u8] = b"DebugHudStereoGuideYawPitchRoll3f\0"; // float[3]
117pub const OVR_DEBUG_HUD_STEREO_GUIDE_COLOR: &'static [u8] = b"DebugHudStereoGuideColor4f\0"; // float[4]
118
119/// API call results are represented at the highest level by a single `ovrResult`.
120pub type ovrResult = i32;
121
122/// Indicates if an `ovrResult` indicates success.
123///
124/// Some functions return additional successful values other than `ovrSuccess` and
125/// require usage of this macro to indicate successs.
126///
127#[inline]
128pub fn OVR_SUCCESS(r: ovrResult) -> bool {
129 r >= 0
130}
131
132/// Indicates if an `ovrResult` indicates an unqualified success.
133///
134/// This is useful for indicating that the code intentionally wants to
135/// check for `result == ovrSuccess` as opposed to `OVR_SUCCESS()`, which
136/// checks for `result >= ovrSuccess`.
137///
138#[inline]
139pub fn OVR_UNQUALIFIED_SUCCESS(r: ovrResult) -> bool {
140 r == ovrSuccess
141}
142
143/// Indicates if an `ovrResult` indicates failure.
144///
145#[inline]
146pub fn OVR_FAILURE(r: ovrResult) -> bool {
147 !OVR_SUCCESS(r)
148}
149
150// Success is a value greater or equal to 0, while all error types are negative values.
151/// This is a general success result. Use `OVR_SUCCESS` to test for success.
152pub type ovrSuccessType = i32;
153pub const ovrSuccess: ovrSuccessType = 0;
154
155// Public success types
156/// Success is a value greater or equal to 0, while all error types are negative values.
157pub type ovrSuccessTypes = i32;
158/// Returned from a call to SubmitFrame. The call succeeded, but what the app
159/// rendered will not be visible on the HMD. Ideally the app should continue
160/// calling SubmitFrame, but not do any rendering. When the result becomes
161/// `ovrSuccess`, rendering should continue as usual.
162pub const ovrSuccess_NotVisible: ovrSuccessTypes = 1000;
163/// Boundary is invalid due to sensor change or was not setup.
164pub const ovrSuccess_BoundaryInvalid: ovrSuccessTypes = 1001;
165/// Device is not available for the requested operation.
166pub const ovrSuccess_DeviceUnavailable: ovrSuccessTypes = 1002;
167
168/// Public error types
169pub type ovrErrorType = i32;
170/* General errors */
171/// Failure to allocate memory.
172pub const ovrError_MemoryAllocationFailure: ovrErrorType = -1000;
173/// Invalid `ovrSession` parameter provided.
174pub const ovrError_InvalidSession: ovrErrorType = -1002;
175/// The operation timed out.
176pub const ovrError_Timeout: ovrErrorType = -1003;
177/// The system or component has not been initialized.
178pub const ovrError_NotInitialized: ovrErrorType = -1004;
179/// Invalid parameter provided. See error info or log for details.
180pub const ovrError_InvalidParameter: ovrErrorType = -1005;
181/// Generic service error. See error info or log for details.
182pub const ovrError_ServiceError: ovrErrorType = -1006;
183/// The given HMD doesn't exist.
184pub const ovrError_NoHmd: ovrErrorType = -1007;
185/// Function call is not supported on this hardware/software
186pub const ovrError_Unsupported: ovrErrorType = -1009;
187/// Specified device type isn't available.
188pub const ovrError_DeviceUnavailable: ovrErrorType = -1010;
189/// The headset was in an invalid orientation for the requested operation (e.g. vertically oriented during `ovr_RecenterPose`).
190pub const ovrError_InvalidHeadsetOrientation: ovrErrorType = -1011;
191/// The client failed to call `ovr_Destroy` on an active session before calling `ovr_Shutdown`. Or the client crashed.
192pub const ovrError_ClientSkippedDestroy: ovrErrorType = -1012;
193/// The client failed to call `ovr_Shutdown` or the client crashed.
194pub const ovrError_ClientSkippedShutdown: ovrErrorType = -1013;
195/// The service watchdog discovered a deadlock.
196pub const ovrError_ServiceDeadlockDetected: ovrErrorType = -1014;
197/// Function call is invalid for object's current state
198pub const ovrError_InvalidOperation: ovrErrorType = -1015;
199
200/* Audio error range, reserved for Audio errors. */
201/// Failure to find the specified audio device.
202pub const ovrError_AudioDeviceNotFound: ovrErrorType = -2001;
203/// Generic COM error.
204pub const ovrError_AudioComError: ovrErrorType = -2002;
205
206/* Initialization errors. */
207/// Generic initialization error.
208pub const ovrError_Initialize: ovrErrorType = -3000;
209/// Couldn't load LibOVRRT.
210pub const ovrError_LibLoad: ovrErrorType = -3001;
211/// LibOVRRT version incompatibility.
212pub const ovrError_LibVersion: ovrErrorType = -3002;
213/// Couldn't connect to the OVR Service.
214pub const ovrError_ServiceConnection: ovrErrorType = -3003;
215/// OVR Service version incompatibility.
216pub const ovrError_ServiceVersion: ovrErrorType = -3004;
217/// The operating system version is incompatible.
218pub const ovrError_IncompatibleOS: ovrErrorType = -3005;
219/// Unable to initialize the HMD display.
220pub const ovrError_DisplayInit: ovrErrorType = -3006;
221/// Unable to start the server. Is it already running?
222pub const ovrError_ServerStart: ovrErrorType = -3007;
223/// Attempting to re-initialize with a different version.
224pub const ovrError_Reinitialization: ovrErrorType = -3008;
225/// Chosen rendering adapters between client and service do not match
226pub const ovrError_MismatchedAdapters: ovrErrorType = -3009;
227/// Calling application has leaked resources
228pub const ovrError_LeakingResources: ovrErrorType = -3010;
229/// Client version too old to connect to service
230pub const ovrError_ClientVersion: ovrErrorType = -3011;
231/// The operating system is out of date.
232pub const ovrError_OutOfDateOS: ovrErrorType = -3012;
233/// The graphics driver is out of date.
234pub const ovrError_OutOfDateGfxDriver: ovrErrorType = -3013;
235/// The graphics hardware is not supported
236pub const ovrError_IncompatibleGPU: ovrErrorType = -3014;
237/// No valid VR display system found.
238pub const ovrError_NoValidVRDisplaySystem: ovrErrorType = -3015;
239/// Feature or API is obsolete and no longer supported.
240pub const ovrError_Obsolete: ovrErrorType = -3016;
241/// No supported VR display system found, but disabled or driverless adapter found.
242pub const ovrError_DisabledOrDefaultAdapter: ovrErrorType = -3017;
243/// The system is using hybrid graphics (Optimus, etc...), which is not support.
244pub const ovrError_HybridGraphicsNotSupported: ovrErrorType = -3018;
245/// Initialization of the DisplayManager failed.
246pub const ovrError_DisplayManagerInit: ovrErrorType = -3019;
247/// Failed to get the interface for an attached tracker
248pub const ovrError_TrackerDriverInit: ovrErrorType = -3020;
249/// LibOVRRT signature check failure.
250pub const ovrError_LibSignCheck: ovrErrorType = -3021;
251/// LibOVRRT path failure.
252pub const ovrError_LibPath: ovrErrorType = -3022;
253/// LibOVRRT symbol resolution failure.
254pub const ovrError_LibSymbols: ovrErrorType = -3023;
255/// Failed to connect to the service because remote connections to the service are not allowed.
256pub const ovrError_RemoteSession: ovrErrorType = -3024;
257
258/* Rendering errors */
259/// In the event of a system-wide graphics reset or cable unplug this is returned to the app.
260pub const ovrError_DisplayLost: ovrErrorType = -6000;
261/// `ovr_CommitTextureSwapChain` was called too many times on a texture swapchain without calling submit to use the chain.
262pub const ovrError_TextureSwapChainFull: ovrErrorType = -6001;
263/// The `ovrTextureSwapChain` is in an incomplete or inconsistent state. Ensure `ovr_CommitTextureSwapChain` was called at least once first.
264pub const ovrError_TextureSwapChainInvalid: ovrErrorType = -6002;
265/// Graphics device has been reset (TDR, etc...)
266pub const ovrError_GraphicsDeviceReset: ovrErrorType = -6003;
267/// HMD removed from the display adapter
268pub const ovrError_DisplayRemoved: ovrErrorType = -6004;
269///Content protection is not available for the display
270pub const ovrError_ContentProtectionNotAvailable: ovrErrorType = -6005;
271/// Application declared itself as an invisible type and is not allowed to submit frames.
272pub const ovrError_ApplicationInvisible: ovrErrorType = -6006;
273/// The given request is disallowed under the current conditions.
274pub const ovrError_Disallowed: ovrErrorType = -6007;
275/// Display portion of HMD is plugged into an incompatible port (ex: IGP)
276pub const ovrError_DisplayPluggedIncorrectly: ovrErrorType = -6008;
277
278/* Fatal errors */
279/// A runtime exception occurred. The application is required to shutdown LibOVR and re-initialize it before this error state will be cleared.
280pub const ovrError_RuntimeException: ovrErrorType = -7000;
281
282/* Calibration errors */
283/// Result of a missing calibration block
284pub const ovrError_NoCalibration: ovrErrorType = -9000;
285/// Result of an old calibration block
286pub const ovrError_OldVersion: ovrErrorType = -9001;
287/// Result of a bad calibration block due to lengths
288pub const ovrError_MisformattedBlock: ovrErrorType = -9002;
289
290/* Other errors */
291
292
293
294/// Provides information about the last error.
295///
296/// see [`ovr_GetLastErrorInfo`](fn.ovr_GetLastErrorInfo.html)
297#[repr(C)]
298#[derive(Copy)]
299pub struct ovrErrorInfo {
300 /// The result from the last API call that generated an error `ovrResult`.
301 pub Result: ovrResult,
302 /// A UTF8-encoded null-terminated English string describing the problem. The format of this string is subject to change in future versions.
303 pub ErrorString: [c_char; 512],
304}
305impl Clone for ovrErrorInfo {
306 fn clone(&self) -> ovrErrorInfo {
307 *self
308 }
309}
310impl fmt::Debug for ovrErrorInfo {
311 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
312 use ::std::ffi::CStr;
313 let string = unsafe{CStr::from_ptr(&self.ErrorString as *const c_char)}.to_str().unwrap();
314 fmt.debug_struct("ovrErrorInfo")
315 .field("Result", &self.Result)
316 .field("ErrorString", &string)
317 .finish()
318 }
319}
320//-----------------------------------------------------------------------------------
321// ***** ovrBool
322
323/// Boolean type
324pub type ovrBool = c_char;
325/// `ovrBool` value of false.
326pub const ovrFalse: ovrBool = 0;
327/// `ovrBool` value of true.
328pub const ovrTrue: ovrBool = 1;
329
330
331//-----------------------------------------------------------------------------------
332// ***** Simple Math Structures
333
334/// A RGBA color with normalized `f32` components.
335#[repr(C)]
336#[derive(Debug, Copy, Clone)]
337pub struct ovrColorf {
338 pub _align: [u32; 0],
339 pub r: f32,
340 pub g: f32,
341 pub b: f32,
342 pub a: f32,
343}
344
345/// A 2D vector with integer components.
346#[repr(C)]
347#[derive(Debug, Copy, Clone)]
348pub struct ovrVector2i {
349 pub _align: [u32; 0],
350 pub x: c_int,
351 pub y: c_int,
352}
353
354/// A 2D size with integer components.
355#[repr(C)]
356#[derive(Debug, Copy, Clone)]
357pub struct ovrSizei {
358 pub _align: [u32; 0],
359 pub w: c_int,
360 pub h: c_int,
361}
362
363/// A 2D rectangle with a position and size.
364/// All components are integers.
365#[repr(C)]
366#[derive(Debug, Copy, Clone)]
367pub struct ovrRecti {
368 pub _align: [u32; 0],
369 pub Pos: ovrVector2i,
370 pub Size: ovrSizei,
371}
372
373/// A quaternion rotation.
374#[repr(C)]
375#[derive(Debug, Copy, Clone)]
376pub struct ovrQuatf {
377 pub _align: [u32; 0],
378 pub x: f32,
379 pub y: f32,
380 pub z: f32,
381 pub w: f32,
382}
383
384/// A 2D vector with `f32` components.
385#[repr(C)]
386#[derive(Debug, Copy, Clone)]
387pub struct ovrVector2f {
388 pub _align: [u32; 0],
389 pub x: f32,
390 pub y: f32,
391}
392
393/// A 3D vector with `f32` components.
394#[repr(C)]
395#[derive(Debug, Copy, Clone)]
396pub struct ovrVector3f {
397 pub _align: [u32; 0],
398 pub x: f32,
399 pub y: f32,
400 pub z: f32,
401}
402
403/// A 4x4 matrix with `f32` elements.
404#[repr(C)]
405#[derive(Debug, Copy, Clone)]
406pub struct ovrMatrix4f {
407 pub _align: [u32; 0],
408 M: [[f32; 4]; 4],
409}
410
411
412/// Position and orientation together.
413#[repr(C)]
414#[derive(Debug, Copy, Clone)]
415pub struct ovrPosef {
416 pub _align: [u32; 0],
417 pub Orientation: ovrQuatf,
418 pub Position: ovrVector3f,
419}
420
421/// A full pose (rigid body) configuration with first and second derivatives.
422///
423/// Body refers to any object for which `ovrPoseStatef` is providing data.
424/// It can be the HMD, Touch controller, sensor or something else. The context
425/// depends on the usage of the struct.
426#[repr(C)]
427#[derive(Debug, Copy, Clone)]
428pub struct ovrPoseStatef {
429 pub _align: [u64; 0],
430 /// Position and orientation.
431 pub ThePose: ovrPosef,
432 /// Angular velocity in radians per second.
433 pub AngularVelocity: ovrVector3f,
434 /// Velocity in meters per second.
435 pub LinearVelocity: ovrVector3f,
436 /// Angular acceleration in radians per second per second.
437 pub AngularAcceleration: ovrVector3f,
438 /// Acceleration in meters per second per second.
439 pub LinearAcceleration: ovrVector3f,
440 /// \internal struct pad.
441 pub _pad0: [u8; 4],
442 /// Absolute time that this pose refers to. see `ovr_GetTimeInSeconds`
443 pub TimeInSeconds: f64,
444}
445
446/// Describes the up, down, left, and right angles of the field of view.
447///
448/// Field Of View (FOV) tangent of the angle units.
449///
450/// **Note**: For a standard 90 degree vertical FOV, we would
451/// have: { UpTan = tan(90 degrees / 2), DownTan = tan(90 degrees / 2) }.
452#[repr(C)]
453#[derive(Debug, Copy, Clone)]
454pub struct ovrFovPort {
455 pub _align: [u32; 0],
456 /// The tangent of the angle between the viewing vector and the top edge of the field of view.
457 pub UpTan: f32,
458 /// The tangent of the angle between the viewing vector and the bottom edge of the field of view.
459 pub DownTan: f32,
460 /// The tangent of the angle between the viewing vector and the left edge of the field of view.
461 pub LeftTan: f32,
462 /// The tangent of the angle between the viewing vector and the right edge of the field of view.
463 pub RightTan: f32,
464}
465
466
467//-----------------------------------------------------------------------------------
468// ***** HMD Types
469
470/// Enumerates all HMD types that we support.
471///
472/// The currently released developer kits are `ovrHmd_DK1` and `ovrHmd_DK2`. The other enumerations are for internal use only.
473pub type ovrHmdType = i32;
474pub const ovrHmd_None: ovrHmdType = 0;
475pub const ovrHmd_DK1: ovrHmdType = 3;
476pub const ovrHmd_DKHD: ovrHmdType = 4;
477pub const ovrHmd_DK2: ovrHmdType = 6;
478pub const ovrHmd_CB: ovrHmdType = 8;
479pub const ovrHmd_Other: ovrHmdType = 9;
480pub const ovrHmd_E3_2015: ovrHmdType = 10;
481pub const ovrHmd_ES06: ovrHmdType = 11;
482pub const ovrHmd_ES09: ovrHmdType = 12;
483pub const ovrHmd_ES11: ovrHmdType = 13;
484pub const ovrHmd_CV1: ovrHmdType = 14;
485
486/// HMD capability bits reported by device.
487pub type ovrHmdCaps = i32;
488// Read-only flags
489/// <B>(read only)</B> Specifies that the HMD is a virtual debug device.
490pub const ovrHmdCap_DebugDevice: ovrHmdCaps = 0x0010;
491/// Tracking capability bits reported by the device.
492/// Used with `ovr_GetTrackingCaps`.
493pub type ovrTrackingCaps = i32;
494/// Supports orientation tracking (IMU).
495pub const ovrTrackingCap_Orientation: ovrTrackingCaps = 0x0010;
496/// Supports yaw drift correction via a magnetometer or other means.
497pub const ovrTrackingCap_MagYawCorrection: ovrTrackingCaps = 0x0020;
498/// Supports positional tracking.
499pub const ovrTrackingCap_Position: ovrTrackingCaps = 0x0040;
500/// Specifies which eye is being used for rendering.
501/// This type explicitly does not include a third "NoStereo" monoscopic option, as such is
502/// not required for an HMD-centered API.
503pub type ovrEyeType = i32;
504/// The left eye, from the viewer's perspective.
505pub const ovrEye_Left: ovrEyeType = 0;
506/// The right eye, from the viewer's perspective.
507pub const ovrEye_Right: ovrEyeType = 1;
508/// \internal Count of enumerated elements.
509pub const ovrEye_Count: ovrEyeType = 2;
510/// Specifies the coordinate system `ovrTrackingState` returns tracking poses in.
511/// Used with `ovr_SetTrackingOriginType()`
512pub type ovrTrackingOrigin = i32;
513/// Tracking system origin reported at eye (HMD) height
514///
515/// Prefer using this origin when your application requires
516/// matching user's current physical head pose to a virtual head pose
517/// without any regards to a the height of the floor. Cockpit-based,
518/// or 3rd-person experiences are ideal candidates.
519/// When used, all poses in `ovrTrackingState` are reported as an offset
520/// transform from the profile calibrated or recentered HMD pose.
521/// It is recommended that apps using this origin type call `ovr_RecenterTrackingOrigin`
522/// prior to starting the VR experience, but notify the user before doing so
523/// to make sure the user is in a comfortable pose, facing a comfortable
524/// direction.
525pub const ovrTrackingOrigin_EyeLevel: ovrTrackingOrigin = 0;
526/// Tracking system origin reported at floor height
527///
528/// Prefer using this origin when your application requires the
529/// physical floor height to match the virtual floor height, such as
530/// standing experiences.
531/// When used, all poses in `ovrTrackingState` are reported as an offset
532/// transform from the profile calibrated floor pose. Calling `ovr_RecenterTrackingOrigin`
533/// will recenter the X & Z axes as well as yaw, but the Y-axis (i.e. height) will continue
534/// to be reported using the floor height as the origin for all poses.
535pub const ovrTrackingOrigin_FloorLevel: ovrTrackingOrigin = 1;
536/// \internal Count of enumerated elements.
537#[doc(hidden)]
538pub const ovrTrackingOrigin_Count: ovrTrackingOrigin = 2;
539/// Identifies a graphics device in a platform-specific way.
540/// For Windows this is a LUID type.
541#[repr(C)]
542#[derive(Debug, Copy, Clone)]
543pub struct ovrGraphicsLuid {
544 pub _align: [isize; 0],
545 /// Public definition reserves space for graphics API-specific implementation
546 pub Reserved: [c_char; 8],
547}
548
549
550/// This is a complete descriptor of the HMD.
551#[repr(C)]
552#[derive(Copy)]
553#[cfg(target_pointer_width = "32")]
554pub struct ovrHmdDesc {
555 pub _align: [isize; 0],
556 /// The type of HMD.
557 pub Type: ovrHmdType,
558 /// UTF8-encoded product identification string (e.g. "Oculus Rift DK1").
559 pub ProductName: [c_char; 64],
560 /// UTF8-encoded HMD manufacturer identification string.
561 pub Manufacturer: [c_char; 64],
562 /// HID (USB) vendor identifier of the device.
563 pub VendorId: c_short,
564 /// HID (USB) product identifier of the device.
565 pub ProductId: c_short,
566 /// HMD serial number.
567 pub SerialNumber: [c_char; 24],
568 /// HMD firmware major version.
569 pub FirmwareMajor: c_short,
570 /// HMD firmware minor version.
571 pub FirmwareMinor: c_short,
572 /// Capability bits described by `ovrHmdCaps` which the HMD currently supports.
573 pub AvailableHmdCaps: c_uint,
574 /// Capability bits described by `ovrHmdCaps` which are default for the current Hmd.
575 pub DefaultHmdCaps: c_uint,
576 /// Capability bits described by `ovrTrackingCaps` which the system currently supports.
577 pub AvailableTrackingCaps: c_uint,
578 /// Capability bits described by `ovrTrackingCaps` which are default for the current system.
579 pub DefaultTrackingCaps: c_uint,
580 /// Defines the recommended FOVs for the HMD.
581 pub DefaultEyeFov: [ovrFovPort; ovrEye_Count as usize],
582 /// Defines the maximum FOVs for the HMD.
583 pub MaxEyeFov: [ovrFovPort; ovrEye_Count as usize],
584 /// Resolution of the full HMD screen (both eyes) in pixels.
585 pub Resolution: ovrSizei,
586 /// Nominal refresh rate of the display in cycles per second at the time of HMD creation.
587 pub DisplayRefreshRate: f32,
588}
589impl Clone for ovrHmdDesc {
590 fn clone(&self) -> ovrHmdDesc {
591 *self
592 }
593}
594/// This is a complete descriptor of the HMD.
595#[repr(C)]
596#[derive(Copy)]
597#[cfg(target_pointer_width = "64")]
598pub struct ovrHmdDesc {
599 pub _align: [isize; 0],
600 /// The type of HMD.
601 pub Type: ovrHmdType,
602 /// \internal struct paddding.
603 pub _pad0: [u8; 4],
604 /// UTF8-encoded product identification string (e.g. "Oculus Rift DK1").
605 pub ProductName: [c_char; 64],
606 /// UTF8-encoded HMD manufacturer identification string.
607 pub Manufacturer: [c_char; 64],
608 /// HID (USB) vendor identifier of the device.
609 pub VendorId: c_short,
610 /// HID (USB) product identifier of the device.
611 pub ProductId: c_short,
612 /// HMD serial number.
613 pub SerialNumber: [c_char; 24],
614 /// HMD firmware major version.
615 pub FirmwareMajor: c_short,
616 /// HMD firmware minor version.
617 pub FirmwareMinor: c_short,
618 /// Capability bits described by `ovrHmdCaps` which the HMD currently supports.
619 pub AvailableHmdCaps: c_uint,
620 /// Capability bits described by `ovrHmdCaps` which are default for the current Hmd.
621 pub DefaultHmdCaps: c_uint,
622 /// Capability bits described by `ovrTrackingCaps` which the system currently supports.
623 pub AvailableTrackingCaps: c_uint,
624 /// Capability bits described by `ovrTrackingCaps` which are default for the current system.
625 pub DefaultTrackingCaps: c_uint,
626 /// Defines the recommended FOVs for the HMD.
627 pub DefaultEyeFov: [ovrFovPort; ovrEye_Count as usize],
628 /// Defines the maximum FOVs for the HMD.
629 pub MaxEyeFov: [ovrFovPort; ovrEye_Count as usize],
630 /// Resolution of the full HMD screen (both eyes) in pixels.
631 pub Resolution: ovrSizei,
632 /// Nominal refresh rate of the display in cycles per second at the time of HMD creation.
633 pub DisplayRefreshRate: f32,
634 /// \internal struct paddding.
635 pub _pad1: [u8; 4],
636}
637
638#[cfg(windows)]
639pub type ovrProcessId = u32;
640#[cfg(not(windows))]
641pub type ovrProcessId = c_int;
642
643#[doc(hidden)]
644pub enum ovrHmdStruct {}
645/// Used as an opaque pointer to an OVR session.
646pub type ovrSession = *mut ovrHmdStruct;
647/// Bit flags describing the current status of sensor tracking.
648///
649/// The values must be the same as in enum StatusBits
650///
651/// see [`ovrTrackingState`](struct.ovrTrackingState.html)
652///
653pub type ovrStatusBits = i32;
654/// Orientation is currently tracked (connected and in use).
655pub const ovrStatus_OrientationTracked: ovrStatusBits = 0x0001;
656/// Position is currently tracked (false if out of range).
657pub const ovrStatus_PositionTracked: ovrStatusBits = 0x0002;
658/// Specifies the description of a single sensor.
659///
660/// see [`ovr_GetTrackerDesc`](fn.ovr_GetTrackerDesc.html)
661///
662#[repr(C)]
663#[derive(Debug, Copy, Clone)]
664pub struct ovrTrackerDesc {
665 pub _align: [isize; 0],
666 /// Sensor frustum horizontal field-of-view (if present).
667 pub FrustumHFovInRadians: f32,
668 /// Sensor frustum vertical field-of-view (if present).
669 pub FrustumVFovInRadians: f32,
670 /// Sensor frustum near Z (if present).
671 pub FrustumNearZInMeters: f32,
672 /// Sensor frustum far Z (if present).
673 pub FrustumFarZInMeters: f32,
674}
675
676
677/// Specifies sensor flags.
678///
679/// see [`ovrTrackerPose`](struct.ovrTrackerPose.html)
680///
681pub type ovrTrackerFlags = i32;
682/// The sensor is present, else the sensor is absent or offline.
683pub const ovrTracker_Connected: ovrTrackerFlags = 0x0020;
684/// The sensor has a valid pose, else the pose is unavailable. This will only be set if `ovrTracker_Connected` is set.
685pub const ovrTracker_PoseTracked: ovrTrackerFlags = 0x0004;
686/// Specifies the pose for a single sensor.
687#[repr(C)]
688#[derive(Debug, Copy, Clone)]
689pub struct ovrTrackerPose {
690 pub _align: [u64; 0],
691 /// `ovrTrackerFlags`.
692 pub TrackerFlags: c_uint,
693 /// The sensor's pose. This pose includes sensor tilt (roll and pitch). For a leveled coordinate system use LeveledPose.
694 pub Pose: ovrPosef,
695 /// The sensor's leveled pose, aligned with gravity. This value includes position and yaw of the sensor, but not roll and pitch. It can be used as a reference point to render real-world objects in the correct location.
696 pub LeveledPose: ovrPosef,
697 /// \internal struct pad.
698 pub _pad0: [u8; 4],
699}
700
701
702/// Tracking state at a given absolute time (describes predicted HMD pose, etc.).
703/// Returned by `ovr_GetTrackingState`.
704///
705/// see [`ovr_GetTrackingState`](fn.ovr_GetTrackingState.html)
706///
707#[repr(C)]
708#[derive(Debug, Copy, Clone)]
709pub struct ovrTrackingState {
710 pub _align: [u64; 0],
711 /// Predicted head pose (and derivatives) at the requested absolute time.
712 pub HeadPose: ovrPoseStatef,
713
714 /// HeadPose tracking status described by `ovrStatusBits`.
715 pub StatusFlags: c_uint,
716
717 /// The most recent calculated pose for each hand when hand controller tracking is present.
718 /// HandPoses[`ovrHand_Left` as usize] refers to the left hand and HandPoses[`ovrHand_Right` as usize] to the right hand.
719 /// These values can be combined with `ovrInputState` for complete hand controller information.
720 pub HandPoses: [ovrPoseStatef; 2],
721
722 /// HandPoses status flags described by `ovrStatusBits`.
723 /// Only `ovrStatus_OrientationTracked` and `ovrStatus_PositionTracked` are reported.
724 pub HandStatusFlags: [c_uint; 2],
725
726 /// The pose of the origin captured during calibration.
727 /// Like all other poses here, this is expressed in the space set by `ovr_RecenterTrackingOrigin`,
728 /// or `ovr_SpecifyTrackingOrigin` and so will change every time either of those functions are
729 /// called. This pose can be used to calculate where the calibrated origin lands in the new
730 /// recentered space. If an application never calls `ovr_RecenterTrackingOrigin` or
731 /// `ovr_SpecifyTrackingOrigin`, expect this value to be the identity pose and as such will point
732 /// respective origin based on `ovrTrackingOrigin` requested when calling `ovr_GetTrackingState`.
733 pub CalibratedOrigin: ovrPosef,
734
735}
736
737
738
739/// Rendering information for each eye. Computed by `ovr_GetRenderDesc()` based on the
740/// specified FOV. Note that the rendering viewport is not included
741/// here as it can be specified separately and modified per frame by
742/// passing different Viewport values in the layer structure.
743///
744/// see [`ovr_GetRenderDesc`](fn.ovr_GetRenderDesc.html)
745///
746#[repr(C)]
747#[derive(Debug, Copy, Clone)]
748pub struct ovrEyeRenderDesc {
749 pub _align: [u32; 0],
750 /// The eye index to which this instance corresponds.
751 pub Eye: ovrEyeType,
752 /// The field of view.
753 pub Fov: ovrFovPort,
754 /// Distortion viewport.
755 pub DistortedViewport: ovrRecti,
756 /// How many display pixels will fit in tan(angle) = 1.
757 pub PixelsPerTanAngleAtCenter: ovrVector2f,
758 /// Translation of each eye, in meters.
759 pub HmdToEyeOffset: ovrVector3f,
760}
761
762
763/// Projection information for `ovrLayerEyeFovDepth`.
764///
765/// Use the utility function `ovrTimewarpProjectionDesc_FromProjection` to
766/// generate this structure from the application's projection matrix.
767///
768/// see `ovrLayerEyeFovDepth`, `ovrTimewarpProjectionDesc_FromProjection`
769///
770#[repr(C)]
771#[derive(Debug, Copy, Clone)]
772pub struct ovrTimewarpProjectionDesc {
773 pub _align: [u32; 0],
774 /// Projection matrix element [2][2].
775 pub Projection22: f32,
776 /// Projection matrix element [2][3].
777 pub Projection23: f32,
778 /// Projection matrix element [3][2].
779 pub Projection32: f32,
780}
781
782
783/// Contains the data necessary to properly calculate position info for various layer types.
784///
785/// * HmdToEyeOffset is the same value pair provided in `ovrEyeRenderDesc`.
786/// * HmdSpaceToWorldScaleInMeters is used to scale player motion into in-application units.
787/// In other words, it is how big an in-application unit is in the player's physical meters.
788/// For example, if the application uses inches as its units then HmdSpaceToWorldScaleInMeters would be 0.0254.
789/// Note that if you are scaling the player in size, this must also scale. So if your application
790/// units are inches, but you're shrinking the player to half their normal size, then
791/// HmdSpaceToWorldScaleInMeters would be 0.0254*2.0.
792///
793/// see [`ovrEyeRenderDesc`](struct.ovrEyeRenderDesc.html), [`ovr_SubmitFrame`](fn.ovr_SubmitFrame.html)
794///
795#[repr(C)]
796#[derive(Debug, Copy, Clone)]
797pub struct ovrViewScaleDesc {
798 pub _align: [u32; 0],
799 /// Translation of each eye.
800 pub HmdToEyeOffset: [ovrVector3f; ovrEye_Count as usize],
801 /// Ratio of viewer units to meter units.
802 pub HmdSpaceToWorldScaleInMeters: f32,
803}
804
805
806//-----------------------------------------------------------------------------------
807// ***** Platform-independent Rendering Configuration
808
809/// The type of texture resource.
810///
811/// see [`ovrTextureSwapChainDesc`](struct.ovrTextureSwapChainDesc.html)
812///
813pub type ovrTextureType = i32;
814/// 2D textures.
815pub const ovrTexture_2D: ovrTextureType = 0;
816/// External 2D texture. Not used on PC
817pub const ovrTexture_2D_External: ovrTextureType = 1;
818/// Cube maps. Not currently supported on PC.
819pub const ovrTexture_Cube: ovrTextureType = 2;
820pub const ovrTexture_Count: ovrTextureType = 3;
821/// The bindings required for texture swap chain.
822///
823/// All texture swap chains are automatically bindable as shader
824/// input resources since the Oculus runtime needs this to read them.
825///
826/// see [`ovrTextureSwapChainDesc`](struct.ovrTextureSwapChainDesc.html)
827///
828pub type ovrTextureBindFlags = i32;
829pub const ovrTextureBind_None: ovrTextureBindFlags = 0;
830/// The application can write into the chain with pixel shader
831pub const ovrTextureBind_DX_RenderTarget: ovrTextureBindFlags = 0x0001;
832/// The application can write to the chain with compute shader
833pub const ovrTextureBind_DX_UnorderedAccess: ovrTextureBindFlags = 0x0002;
834/// The chain buffers can be bound as depth and/or stencil buffers
835pub const ovrTextureBind_DX_DepthStencil: ovrTextureBindFlags = 0x0004;
836/// The format of a texture.
837///
838/// see [`ovrTextureSwapChainDesc`](struct.ovrTextureSwapChainDesc.html)
839///
840pub type ovrTextureFormat = i32;
841pub const OVR_FORMAT_UNKNOWN: ovrTextureFormat = 0;
842/// Not currently supported on PC. Would require a DirectX 11.1 device.
843pub const OVR_FORMAT_B5G6R5_UNORM: ovrTextureFormat = 1;
844/// Not currently supported on PC. Would require a DirectX 11.1 device.
845pub const OVR_FORMAT_B5G5R5A1_UNORM: ovrTextureFormat = 2;
846/// Not currently supported on PC. Would require a DirectX 11.1 device.
847pub const OVR_FORMAT_B4G4R4A4_UNORM: ovrTextureFormat = 3;
848pub const OVR_FORMAT_R8G8B8A8_UNORM: ovrTextureFormat = 4;
849pub const OVR_FORMAT_R8G8B8A8_UNORM_SRGB: ovrTextureFormat = 5;
850pub const OVR_FORMAT_B8G8R8A8_UNORM: ovrTextureFormat = 6;
851/// Not supported for OpenGL applications
852pub const OVR_FORMAT_B8G8R8A8_UNORM_SRGB: ovrTextureFormat = 7;
853/// Not supported for OpenGL applications
854pub const OVR_FORMAT_B8G8R8X8_UNORM: ovrTextureFormat = 8;
855/// Not supported for OpenGL applications
856pub const OVR_FORMAT_B8G8R8X8_UNORM_SRGB: ovrTextureFormat = 9;
857pub const OVR_FORMAT_R16G16B16A16_FLOAT: ovrTextureFormat = 10;
858/// Introduced in v1.10
859pub const OVR_FORMAT_R11G11B10_FLOAT: ovrTextureFormat = 25;
860
861// Depth formats
862pub const OVR_FORMAT_D16_UNORM: ovrTextureFormat = 11;
863pub const OVR_FORMAT_D24_UNORM_S8_UINT: ovrTextureFormat = 12;
864pub const OVR_FORMAT_D32_FLOAT: ovrTextureFormat = 13;
865pub const OVR_FORMAT_D32_FLOAT_S8X24_UINT: ovrTextureFormat = 14;
866
867// Added in 1.5 compressed formats can be used for static layers
868pub const OVR_FORMAT_BC1_UNORM: ovrTextureFormat = 15;
869pub const OVR_FORMAT_BC1_UNORM_SRGB: ovrTextureFormat = 16;
870pub const OVR_FORMAT_BC2_UNORM: ovrTextureFormat = 17;
871pub const OVR_FORMAT_BC2_UNORM_SRGB: ovrTextureFormat = 18;
872pub const OVR_FORMAT_BC3_UNORM: ovrTextureFormat = 19;
873pub const OVR_FORMAT_BC3_UNORM_SRGB: ovrTextureFormat = 20;
874pub const OVR_FORMAT_BC6H_UF16: ovrTextureFormat = 21;
875pub const OVR_FORMAT_BC6H_SF16: ovrTextureFormat = 22;
876pub const OVR_FORMAT_BC7_UNORM: ovrTextureFormat = 23;
877pub const OVR_FORMAT_BC7_UNORM_SRGB: ovrTextureFormat = 24;
878/// Misc flags overriding particular behaviors of a texture swap chain
879///
880/// see [`ovrTextureSwapChainDesc`](struct.ovrTextureSwapChainDesc.html)
881///
882pub type ovrTextureMiscFlags = i32;
883pub const ovrTextureMisc_None: ovrTextureMiscFlags = 0;
884/// DX only: The underlying texture is created with a TYPELESS equivalent of the
885/// format specified in the texture desc. The SDK will still access the
886/// texture using the format specified in the texture desc, but the app can
887/// create views with different formats if this is specified.
888pub const ovrTextureMisc_DX_Typeless: ovrTextureMiscFlags = 0x0001;
889/// DX only: Allow generation of the mip chain on the GPU via the GenerateMips
890/// call. This flag requires that RenderTarget binding also be specified.
891pub const ovrTextureMisc_AllowGenerateMips: ovrTextureMiscFlags = 0x0002;
892/// Texture swap chain contains protected content, and requires
893/// HDCP connection in order to display to HMD. Also prevents
894/// mirroring or other redirection of any frame containing this contents
895pub const ovrTextureMisc_ProtectedContent: ovrTextureMiscFlags = 0x0004;
896/// Description used to create a texture swap chain.
897///
898/// see [`ovr_CreateTextureSwapChainDX`](directx/fn.ovr_CreateTextureSwapChainDX.html), [`ovr_CreateTextureSwapChainGL`](opengl/fn.ovr_CreateTextureSwapChainGL.html), [`ovr_CreateTextureSwapChainVk`](opengl/fn.ovr_CreateTextureSwapChainVk.html)
899///
900#[repr(C)]
901#[derive(Debug, Copy, Clone)]
902pub struct ovrTextureSwapChainDesc {
903 pub Type: ovrTextureType,
904 pub Format: ovrTextureFormat,
905 /// Only supported with `ovrTexture_2D`. Not supported on PC at this time.
906 pub ArraySize: c_int,
907 pub Width: c_int,
908 pub Height: c_int,
909 pub MipLevels: c_int,
910 /// Current only supported on depth textures
911 pub SampleCount: c_int,
912 /// Not buffered in a chain. For images that don't change
913 pub StaticImage: ovrBool,
914 /// `ovrTextureFlags`
915 pub MiscFlags: c_uint,
916 /// `ovrTextureBindFlags`. Not used for GL.
917 pub BindFlags: c_uint,
918}
919
920/// Description used to create a mirror texture.
921///
922/// see [`ovr_CreateMirrorTextureDX`](directx/fn.ovr_CreateMirrorTextureDX.html), [`ovr_CreateMirrorTextureVk`](opengl/fn.ovr_CreateMirrorTextureVk.html), [`ovr_CreateMirrorTextureVk`](opengl/fn.ovr_CreateMirrorTextureVk.html)
923///
924#[repr(C)]
925#[derive(Debug, Copy, Clone)]
926pub struct ovrMirrorTextureDesc {
927 pub Format: ovrTextureFormat,
928 pub Width: c_int,
929 pub Height: c_int,
930 /// `ovrTextureFlags`
931 pub MiscFlags: c_uint,
932}
933#[doc(hidden)]
934pub enum ovrTextureSwapChainData {}
935pub type ovrTextureSwapChain = *mut ovrTextureSwapChainData;
936#[doc(hidden)]
937pub enum ovrMirrorTextureData {}
938pub type ovrMirrorTexture = *mut ovrMirrorTextureData;
939
940//-----------------------------------------------------------------------------------
941
942/// Describes button input types.
943/// Button inputs are combined; that is they will be reported as pressed if they are
944/// pressed on either one of the two devices.
945/// The `ovrButton_Up`/Down/Left/Right map to both XBox D-Pad and directional buttons.
946/// The `ovrButton_Enter` and `ovrButton_Return` map to Start and Back controller buttons, respectively.
947pub type ovrButton = i32;
948/// A button on XBox controllers and right Touch controller. Select button on Oculus Remote.
949pub const ovrButton_A: ovrButton = 0x00000001;
950/// B button on XBox controllers and right Touch controller. Back button on Oculus Remote.
951pub const ovrButton_B: ovrButton = 0x00000002;
952/// Right thumbstick on XBox controllers and Touch controllers. Not present on Oculus Remote.
953pub const ovrButton_RThumb: ovrButton = 0x00000004;
954/// Right shoulder button on XBox controllers. Not present on Touch controllers or Oculus Remote.
955pub const ovrButton_RShoulder: ovrButton = 0x00000008;
956
957/// X button on XBox controllers and left Touch controller. Not present on Oculus Remote.
958pub const ovrButton_X: ovrButton = 0x00000100;
959/// Y button on XBox controllers and left Touch controller. Not present on Oculus Remote.
960pub const ovrButton_Y: ovrButton = 0x00000200;
961/// Left thumbstick on XBox controllers and Touch controllers. Not present on Oculus Remote.
962pub const ovrButton_LThumb: ovrButton = 0x00000400;
963/// Left shoulder button on XBox controllers. Not present on Touch controllers or Oculus Remote.
964pub const ovrButton_LShoulder: ovrButton = 0x00000800;
965
966/// Up button on XBox controllers and Oculus Remote. Not present on Touch controllers.
967pub const ovrButton_Up: ovrButton = 0x00010000;
968/// Down button on XBox controllers and Oculus Remote. Not present on Touch controllers.
969pub const ovrButton_Down: ovrButton = 0x00020000;
970/// Left button on XBox controllers and Oculus Remote. Not present on Touch controllers.
971pub const ovrButton_Left: ovrButton = 0x00040000;
972/// Right button on XBox controllers and Oculus Remote. Not present on Touch controllers.
973pub const ovrButton_Right: ovrButton = 0x00080000;
974/// Start on XBox 360 controller. Menu on XBox One controller and Left Touch controller. Should be referred to as the Menu button in user-facing documentation.
975pub const ovrButton_Enter: ovrButton = 0x00100000;
976/// Back on Xbox 360 controller. View button on XBox One controller. Not present on Touch controllers or Oculus Remote.
977pub const ovrButton_Back: ovrButton = 0x00200000;
978/// Volume button on Oculus Remote. Not present on XBox or Touch controllers.
979pub const ovrButton_VolUp: ovrButton = 0x00400000;
980/// Volume button on Oculus Remote. Not present on XBox or Touch controllers.
981pub const ovrButton_VolDown: ovrButton = 0x00800000;
982/// Home button on XBox controllers. Oculus button on Touch controllers and Oculus Remote.
983pub const ovrButton_Home: ovrButton = 0x01000000;
984
985/// Bit mask of all buttons that are for private usage by Oculus
986pub const ovrButton_Private: ovrButton = ovrButton_VolUp | ovrButton_VolDown | ovrButton_Home;
987
988/// Bit mask of all buttons on the right Touch controller
989pub const ovrButton_RMask: ovrButton = ovrButton_A | ovrButton_B | ovrButton_RThumb | ovrButton_RShoulder;
990
991/// Bit mask of all buttons on the left Touch controller
992pub const ovrButton_LMask: ovrButton = ovrButton_X | ovrButton_Y | ovrButton_LThumb | ovrButton_LShoulder |
993 ovrButton_Enter;
994/// Describes touch input types.
995/// These values map to capacitive touch values reported `ovrInputState`::Touch.
996/// Some of these values are mapped to button bits for consistency.
997pub type ovrTouch = i32;
998pub const ovrTouch_A: ovrTouch = ovrButton_A;
999pub const ovrTouch_B: ovrTouch = ovrButton_B;
1000pub const ovrTouch_RThumb: ovrTouch = ovrButton_RThumb;
1001pub const ovrTouch_RThumbRest: ovrTouch = 0x00000008;
1002pub const ovrTouch_RIndexTrigger: ovrTouch = 0x00000010;
1003
1004/// Bit mask of all the button touches on the right controller
1005pub const ovrTouch_RButtonMask: ovrTouch = ovrTouch_A | ovrTouch_B | ovrTouch_RThumb | ovrTouch_RThumbRest | ovrTouch_RIndexTrigger;
1006
1007pub const ovrTouch_X: ovrTouch = ovrButton_X;
1008pub const ovrTouch_Y: ovrTouch = ovrButton_Y;
1009pub const ovrTouch_LThumb: ovrTouch = ovrButton_LThumb;
1010pub const ovrTouch_LThumbRest: ovrTouch = 0x00000800;
1011pub const ovrTouch_LIndexTrigger: ovrTouch = 0x00001000;
1012
1013/// Bit mask of all the button touches on the left controller
1014pub const ovrTouch_LButtonMask: ovrTouch = ovrTouch_X | ovrTouch_Y | ovrTouch_LThumb | ovrTouch_LThumbRest | ovrTouch_LIndexTrigger;
1015
1016/// Finger pose state
1017/// Derived internally based on distance, proximity to sensors and filtering.
1018pub const ovrTouch_RIndexPointing: ovrTouch = 0x00000020;
1019pub const ovrTouch_RThumbUp: ovrTouch = 0x00000040;
1020pub const ovrTouch_LIndexPointing: ovrTouch = 0x00002000;
1021pub const ovrTouch_LThumbUp: ovrTouch = 0x00004000;
1022
1023/// Bit mask of all right controller poses
1024pub const ovrTouch_RPoseMask: ovrTouch = ovrTouch_RIndexPointing | ovrTouch_RThumbUp;
1025
1026/// Bit mask of all left controller poses
1027pub const ovrTouch_LPoseMask: ovrTouch = ovrTouch_LIndexPointing | ovrTouch_LThumbUp;
1028/// Describes the Touch Haptics engine.
1029/// Currently, those values will NOT change during a session.
1030#[repr(C)]
1031#[derive(Debug, Copy, Clone)]
1032pub struct ovrTouchHapticsDesc {
1033 pub _align: [isize; 0],
1034 /// Haptics engine frequency/sample-rate, sample time in seconds equals 1.0/sampleRateHz
1035 pub SampleRateHz: c_int,
1036 /// Size of each Haptics sample, sample value range is `[0, 2^(Bytes*8)-1]`
1037 pub SampleSizeInBytes: c_int,
1038
1039 /// Queue size that would guarantee Haptics engine would not starve for data
1040 /// Make sure size doesn't drop below it for best results
1041 pub QueueMinSizeToAvoidStarvation: c_int,
1042
1043 /// Minimum, Maximum and Optimal number of samples that can be sent to Haptics through `ovr_SubmitControllerVibration`
1044 pub SubmitMinSamples: c_int,
1045 pub SubmitMaxSamples: c_int,
1046 pub SubmitOptimalSamples: c_int,
1047}
1048
1049/// Specifies which controller is connected; multiple can be connected at once.
1050pub type ovrControllerType = i32;
1051pub const ovrControllerType_None: ovrControllerType = 0x00;
1052pub const ovrControllerType_LTouch: ovrControllerType = 0x01;
1053pub const ovrControllerType_RTouch: ovrControllerType = 0x02;
1054pub const ovrControllerType_Touch: ovrControllerType = 0x03;
1055pub const ovrControllerType_Remote: ovrControllerType = 0x04;
1056pub const ovrControllerType_XBox: ovrControllerType = 0x10;
1057/// Operate on or query whichever controller is active.
1058pub const ovrControllerType_Active: ovrControllerType = 0xff;
1059/// Haptics buffer submit mode
1060pub type ovrHapticsBufferSubmitMode = i32;
1061/// Enqueue buffer for later playback
1062pub const ovrHapticsBufferSubmit_Enqueue: ovrHapticsBufferSubmitMode = 0;
1063/// Haptics buffer descriptor, contains amplitude samples used for Touch vibration
1064#[repr(C)]
1065#[derive(Debug, Copy, Clone)]
1066pub struct ovrHapticsBuffer {
1067 /// Samples stored in opaque format
1068 pub Samples: *const c_void,
1069 /// Number of samples
1070 pub SamplesCount: c_int,
1071 /// How samples are submitted to the hardware
1072 pub SubmitMode: ovrHapticsBufferSubmitMode,
1073}
1074
1075/// State of the Haptics playback for Touch vibration
1076#[repr(C)]
1077#[derive(Debug, Copy, Clone)]
1078pub struct ovrHapticsPlaybackState {
1079 /// Remaining space available to queue more samples
1080 pub RemainingQueueSpace: c_int,
1081
1082 /// Number of samples currently queued
1083 pub SamplesQueued: c_int,
1084}
1085
1086/// Position tracked devices
1087pub type ovrTrackedDeviceType = i32;
1088pub const ovrTrackedDevice_HMD: ovrTrackedDeviceType = 0x0001;
1089pub const ovrTrackedDevice_LTouch: ovrTrackedDeviceType = 0x0002;
1090pub const ovrTrackedDevice_RTouch: ovrTrackedDeviceType = 0x0004;
1091pub const ovrTrackedDevice_Touch: ovrTrackedDeviceType = 0x0006;
1092pub const ovrTrackedDevice_All: ovrTrackedDeviceType = 0xFFFF;
1093/// Boundary types that specified while using the boundary system
1094pub type ovrBoundaryType = i32;
1095/// Outer boundary - closely represents user setup walls
1096pub const ovrBoundary_Outer: ovrBoundaryType = 0x0001;
1097
1098/// Play area - safe rectangular area inside outer boundary which can optionally be used to restrict user interactions and motion.
1099pub const ovrBoundary_PlayArea: ovrBoundaryType = 0x0100;
1100/// Boundary system look and feel
1101#[repr(C)]
1102#[derive(Debug, Copy, Clone)]
1103pub struct ovrBoundaryLookAndFeel {
1104 /// Boundary color (alpha channel is ignored)
1105 pub Color: ovrColorf,
1106}
1107
1108/// Provides boundary test information
1109#[repr(C)]
1110#[derive(Debug, Copy, Clone)]
1111pub struct ovrBoundaryTestResult {
1112 /// True if the boundary system is being triggered. Note that due to fade in/out effects this may not exactly match visibility.
1113 pub IsTriggering: ovrBool,
1114
1115 /// Distance to the closest play area or outer boundary surface.
1116 pub ClosestDistance: f32,
1117
1118 /// Closest point on the boundary surface.
1119 pub ClosestPoint: ovrVector3f,
1120
1121 /// Unit surface normal of the closest boundary surface.
1122 pub ClosestPointNormal: ovrVector3f,
1123}
1124
1125/// Provides names for the left and right hand array indexes.
1126///
1127/// see [`ovrInputState`](struct.ovrInputState.html), [`ovrTrackingState`](struct.ovrTrackingState.html)
1128///
1129pub type ovrHandType = i32;
1130pub const ovrHand_Left: ovrHandType = 0;
1131pub const ovrHand_Right: ovrHandType = 1;
1132pub const ovrHand_Count: ovrHandType = 2;
1133/// `ovrInputState` describes the complete controller input state, including Oculus Touch,
1134/// and XBox gamepad. If multiple inputs are connected and used at the same time,
1135/// their inputs are combined.
1136#[repr(C)]
1137#[derive(Debug, Copy, Clone)]
1138pub struct ovrInputState {
1139 /// System type when the controller state was last updated.
1140 pub TimeInSeconds: f64,
1141
1142 /// Values for buttons described by `ovrButton`.
1143 pub Buttons: c_uint,
1144
1145 /// Touch values for buttons and sensors as described by `ovrTouch`.
1146 pub Touches: c_uint,
1147
1148 /// Left and right finger trigger values (`ovrHand_Left` and `ovrHand_Right`), in the range 0.0 to 1.0f.
1149 /// Returns 0 if the value would otherwise be less than 0.1176, for `ovrControllerType_XBox`.
1150 /// This has been formally named simply "Trigger". We retain the name IndexTrigger for backwards code compatibility.
1151 /// User-facing documentation should refer to it as the Trigger.
1152 pub IndexTrigger: [f32; ovrHand_Count as usize],
1153
1154 /// Left and right hand trigger values (`ovrHand_Left` and `ovrHand_Right`), in the range 0.0 to 1.0f.
1155 /// This has been formally named "Grip Button". We retain the name HandTrigger for backwards code compatibility.
1156 /// User-facing documentation should refer to it as the Grip Button or simply Grip.
1157 pub HandTrigger: [f32; ovrHand_Count as usize],
1158
1159 /// Horizontal and vertical thumbstick axis values (`ovrHand_Left` and `ovrHand_Right`), in the range -1.0f to 1.0f.
1160 /// Returns a deadzone (value 0) per each axis if the value on that axis would otherwise have been between -.2746 to +.2746, for `ovrControllerType_XBox`
1161 pub Thumbstick: [ovrVector2f; ovrHand_Count as usize],
1162
1163 /// The type of the controller this state is for.
1164 pub ControllerType: ovrControllerType,
1165
1166 /// Left and right finger trigger values (`ovrHand_Left` and `ovrHand_Right`), in the range 0.0 to 1.0f.
1167 /// Does not apply a deadzone. Only touch applies a filter.
1168 /// This has been formally named simply "Trigger". We retain the name IndexTrigger for backwards code compatibility.
1169 /// User-facing documentation should refer to it as the Trigger.
1170 /// Added in 1.7
1171 pub IndexTriggerNoDeadzone: [f32; ovrHand_Count as usize],
1172
1173 /// Left and right hand trigger values (`ovrHand_Left` and `ovrHand_Right`), in the range 0.0 to 1.0f.
1174 /// Does not apply a deadzone. Only touch applies a filter.
1175 /// This has been formally named "Grip Button". We retain the name HandTrigger for backwards code compatibility.
1176 /// User-facing documentation should refer to it as the Grip Button or simply Grip.
1177 /// Added in 1.7
1178 pub HandTriggerNoDeadzone: [f32; ovrHand_Count as usize],
1179
1180 /// Horizontal and vertical thumbstick axis values (`ovrHand_Left` and `ovrHand_Right`), in the range -1.0f to 1.0f
1181 /// Does not apply a deadzone or filter.
1182 /// Added in 1.7
1183 pub ThumbstickNoDeadzone: [ovrVector2f; ovrHand_Count as usize],
1184
1185 /// Left and right finger trigger values (`ovrHand_Left` and `ovrHand_Right`), in range 0.0 to 1.0f.
1186 /// No deadzone or filter
1187 /// This has been formally named "Grip Button". We retain the name HandTrigger for backwards code
1188 /// compatibility.
1189 /// User-facing documentation should refer to it as the Grip Button or simply Grip.
1190 pub IndexTriggerRaw: [f32; ovrHand_Count as usize],
1191
1192 /// Left and right hand trigger values (`ovrHand_Left` and `ovrHand_Right`), in the range 0.0 to 1.0f.
1193 /// No deadzone or filter
1194 /// This has been formally named "Grip Button". We retain the name HandTrigger for backwards code
1195 /// compatibility.
1196 /// User-facing documentation should refer to it as the Grip Button or simply Grip.
1197 pub HandTriggerRaw: [f32; ovrHand_Count as usize],
1198
1199 /// Horizontal and vertical thumbstick axis values (`ovrHand_Left` and `ovrHand_Right`), in the range
1200 /// -1.0f to 1.0f
1201 /// No deadzone or filter
1202 pub ThumbstickRaw: [ovrVector2f; ovrHand_Count as usize]
1203}
1204
1205
1206
1207//-----------------------------------------------------------------------------------
1208// ***** Initialize structures
1209
1210/// Initialization flags.
1211///
1212/// see [`ovrInitParams`](struct.ovrInitParams.html), [`ovr_Initialize`](fn.ovr_Initialize.html)
1213///
1214pub type ovrInitFlags = i32;
1215/// When a debug library is requested, a slower debugging version of the library will
1216/// run which can be used to help solve problems in the library and debug application code.
1217pub const ovrInit_Debug: ovrInitFlags = 0x00000001;
1218/// When a version is requested, the LibOVR runtime respects the RequestedMinorVersion
1219/// field and verifies that the RequestedMinorVersion is supported. Normally when you
1220/// specify this flag you simply use `OVR_MINOR_VERSION` for `ovrInitParams`::RequestedMinorVersion,
1221/// though you could use a lower version than `OVR_MINOR_VERSION` to specify previous
1222/// version behavior.
1223pub const ovrInit_RequestVersion: ovrInitFlags = 0x00000004;
1224
1225/// These bits are writable by user code.
1226pub const ovrinit_WritableBits: ovrInitFlags = 0x00ffffff;
1227/// Logging levels
1228///
1229/// see [`ovrInitParams`](struct.ovrInitParams.html), [`ovrLogCallback`](type.ovrLogCallback.html)
1230///
1231pub type ovrLogLevel = i32;
1232/// Debug-level log event.
1233pub const ovrLogLevel_Debug: ovrLogLevel = 0;
1234/// Info-level log event.
1235pub const ovrLogLevel_Info: ovrLogLevel = 1;
1236/// Error-level log event.
1237pub const ovrLogLevel_Error: ovrLogLevel = 2;
1238/// Signature of the logging callback function pointer type.
1239///
1240/// `userData` is an arbitrary value specified by the user of `ovrInitParams`.
1241/// `level` is one of the `ovrLogLevel` constants.
1242/// `message` is a UTF8-encoded null-terminated string.
1243/// see [`ovrInitParams`](struct.ovrInitParams.html), [`ovrLogLevel`](type.ovrLogLevel.html), [`ovr_Initialize`](fn.ovr_Initialize.html)
1244///
1245
1246pub type ovrLogCallback = Option<extern "C" fn(usize, c_int, *const c_char)>;
1247
1248/// Parameters for `ovr_Initialize`.
1249///
1250/// see [`ovr_Initialize`](fn.ovr_Initialize.html)
1251///
1252#[repr(C)]
1253#[derive(Debug, Copy, Clone)]
1254#[cfg(target_pointer_width = "32")]
1255pub struct ovrInitParams {
1256 pub _align: [u64; 0],
1257 /// Flags from `ovrInitFlags` to override default behavior.
1258 /// Use 0 for the defaults.
1259 pub Flags: ovrInitFlags,
1260
1261 /// Requests a specific minor version of the LibOVR runtime.
1262 /// Flags must include `ovrInit_RequestVersion` or this will be ignored and `OVR_MINOR_VERSION`
1263 /// will be used. If you are directly calling the LibOVRRT version of `ovr_Initialize`
1264 /// in the LibOVRRT DLL then this must be valid and include `ovrInit_RequestVersion`.
1265 pub RequestedMinorVersion: u32,
1266
1267 /// User-supplied log callback function, which may be called at any time
1268 /// asynchronously from multiple threads until `ovr_Shutdown` completes.
1269 /// Use NULL to specify no log callback.
1270 pub LogCallback: ovrLogCallback,
1271
1272 /// User-supplied data which is passed as-is to LogCallback. Typically this
1273 /// is used to store an application-specific pointer which is read in the
1274 /// callback function.
1275 pub UserData: usize,
1276
1277 /// Relative number of milliseconds to wait for a connection to the server
1278 /// before failing. Use 0 for the default timeout.
1279 pub ConnectionTimeoutMS: u32,
1280
1281}
1282
1283/// Parameters for `ovr_Initialize`.
1284///
1285/// see [`ovr_Initialize`](fn.ovr_Initialize.html)
1286///
1287#[repr(C)]
1288#[derive(Debug, Copy, Clone)]
1289#[cfg(target_pointer_width = "64")]
1290pub struct ovrInitParams {
1291 pub _align: [u64; 0],
1292 /// Flags from `ovrInitFlags` to override default behavior.
1293 /// Use 0 for the defaults.
1294 pub Flags: ovrInitFlags,
1295
1296 /// Requests a specific minor version of the LibOVR runtime.
1297 /// Flags must include `ovrInit_RequestVersion` or this will be ignored and `OVR_MINOR_VERSION`
1298 /// will be used. If you are directly calling the LibOVRRT version of `ovr_Initialize`
1299 /// in the LibOVRRT DLL then this must be valid and include `ovrInit_RequestVersion`.
1300 pub RequestedMinorVersion: u32,
1301
1302 /// User-supplied log callback function, which may be called at any time
1303 /// asynchronously from multiple threads until `ovr_Shutdown` completes.
1304 /// Use NULL to specify no log callback.
1305 pub LogCallback: ovrLogCallback,
1306
1307 /// User-supplied data which is passed as-is to LogCallback. Typically this
1308 /// is used to store an application-specific pointer which is read in the
1309 /// callback function.
1310 pub UserData: usize,
1311
1312 /// Relative number of milliseconds to wait for a connection to the server
1313 /// before failing. Use 0 for the default timeout.
1314 pub ConnectionTimeoutMS: u32,
1315
1316 /// \internal
1317 pub _pad0: [u8; 4],
1318
1319}
1320
1321extern "C" {
1322
1323 // -----------------------------------------------------------------------------------
1324 // ***** API Interfaces
1325
1326 /// Initializes LibOVR
1327 ///
1328 /// Initialize LibOVR for application usage. This includes finding and loading the LibOVRRT
1329 /// shared library. No LibOVR API functions, other than `ovr_GetLastErrorInfo` and `ovr_Detect`, can
1330 /// be called unless `ovr_Initialize` succeeds. A successful call to `ovr_Initialize` must be eventually
1331 /// followed by a call to `ovr_Shutdown`. `ovr_Initialize` calls are idempotent.
1332 /// Calling `ovr_Initialize` twice does not require two matching calls to `ovr_Shutdown`.
1333 /// If already initialized, the return value is `ovr_Success`.
1334 ///
1335 /// LibOVRRT shared library search order:
1336 ///
1337 /// * Current working directory (often the same as the application directory).
1338 /// * Module directory (usually the same as the application directory,
1339 /// but not if the module is a separate shared library).
1340 /// * Application directory
1341 /// * Development directory (only if `OVR_ENABLE_DEVELOPER_SEARCH` is enabled,
1342 /// which is off by default).
1343 /// * Standard OS shared library search location(s) (OS-specific).
1344 ///
1345 /// `params` Specifies custom initialization options. May be NULL to indicate default options when
1346 /// using the CAPI shim. If you are directly calling the LibOVRRT version of `ovr_Initialize`
1347 /// in the LibOVRRT DLL then this must be valid and include ovrInit_RequestVersion.
1348 ///
1349 /// Returns an `ovrResult` indicating success or failure. In the case of failure, use
1350 /// `ovr_GetLastErrorInfo` to get more information. Example failed results include:
1351 ///
1352 /// * `ovrError_Initialize`: Generic initialization error.
1353 /// * `ovrError_LibLoad`: Couldn't load LibOVRRT.
1354 /// * `ovrError_LibVersion`: LibOVRRT version incompatibility.
1355 /// * `ovrError_ServiceConnection`: Couldn't connect to the OVR Service.
1356 /// * `ovrError_ServiceVersion`: OVR Service version incompatibility.
1357 /// * `ovrError_IncompatibleOS`: The operating system version is incompatible.
1358 /// * `ovrError_DisplayInit`: Unable to initialize the HMD display.
1359 /// * `ovrError_ServerStart`: Unable to start the server. Is it already running?
1360 /// * `ovrError_Reinitialization`: Attempted to re-initialize with a different version.
1361 ///
1362 /// **Example code**
1363 ///
1364 /// ```no_run
1365 /// # extern crate libc;
1366 /// # extern crate ovr_sys;
1367 /// # use ovr_sys::*;
1368 /// # use ::std::ffi::CStr;
1369 /// # use libc::c_char;
1370 /// # use ::std::mem;
1371 /// # fn main() {
1372 /// # unsafe fn foo() -> Result<(), String> {
1373 /// let init_params = ovrInitParams {
1374 /// Flags: ovrInit_RequestVersion,
1375 /// RequestedMinorVersion: OVR_MINOR_VERSION,
1376 /// LogCallback: None,
1377 /// UserData: 0,
1378 /// ConnectionTimeoutMS: 0,
1379 /// .. mem::uninitialized()
1380 /// };
1381 /// let result = ovr_Initialize(&init_params as *const _);
1382 /// if OVR_FAILURE(result) {
1383 /// let mut error_info: ovrErrorInfo = mem::zeroed();
1384 /// ovr_GetLastErrorInfo(&mut error_info as *mut _);
1385 /// let error_string = CStr::from_ptr(&error_info.ErrorString as *const c_char)
1386 /// .to_str().unwrap();
1387 /// return Err(format!("ovr_Initialize failed: {}", error_string));
1388 /// }
1389 /// # Ok(())
1390 /// # }
1391 /// # unsafe{drop(foo())};
1392 /// # }
1393 /// ```
1394 ///
1395 /// see [`ovr_Shutdown`](fn.ovr_Shutdown.html)
1396 ///
1397 pub fn ovr_Initialize(params: *const ovrInitParams) -> ovrResult;
1398 /// Shuts down LibOVR
1399 ///
1400 /// A successful call to `ovr_Initialize` must be eventually matched by a call to `ovr_Shutdown`.
1401 /// After calling `ovr_Shutdown`, no LibOVR functions can be called except `ovr_GetLastErrorInfo`
1402 /// or another `ovr_Initialize`. `ovr_Shutdown` invalidates all pointers, references, and created objects
1403 /// previously returned by LibOVR functions. The LibOVRRT shared library can be unloaded by
1404 /// `ovr_Shutdown`.
1405 ///
1406 /// see [`ovr_Initialize`](fn.ovr_Initialize.html)
1407 ///
1408 pub fn ovr_Shutdown();
1409 /// Returns information about the most recent failed return value by the
1410 /// current thread for this library.
1411 ///
1412 /// This function itself can never generate an error.
1413 /// The last error is never cleared by LibOVR, but will be overwritten by new errors.
1414 /// Do not use this call to determine if there was an error in the last API
1415 /// call as successful API calls don't clear the last `ovrErrorInfo`.
1416 /// To avoid any inconsistency, `ovr_GetLastErrorInfo` should be called immediately
1417 /// after an API function that returned a failed `ovrResult`, with no other API
1418 /// functions called in the interim.
1419 ///
1420 /// **out** `errorInfo` The last `ovrErrorInfo` for the current thread.
1421 ///
1422 /// see [`ovrErrorInfo`](struct.ovrErrorInfo.html)
1423 ///
1424 pub fn ovr_GetLastErrorInfo(errorInfo: *mut ovrErrorInfo);
1425 /// Returns the version string representing the LibOVRRT version.
1426 ///
1427 /// The returned string pointer is valid until the next call to `ovr_Shutdown`.
1428 ///
1429 /// Note that the returned version string doesn't necessarily match the current
1430 /// `OVR_MAJOR_VERSION`, etc., as the returned string refers to the LibOVRRT shared
1431 /// library version and not the locally compiled interface version.
1432 ///
1433 /// The format of this string is subject to change in future versions and its contents
1434 /// should not be interpreted.
1435 ///
1436 /// Returns a UTF8-encoded null-terminated version string.
1437 ///
1438 pub fn ovr_GetVersionString() -> *const c_char;
1439 /// Writes a message string to the LibOVR tracing mechanism (if enabled).
1440 ///
1441 /// This message will be passed back to the application via the `ovrLogCallback` if
1442 /// it was registered.
1443 ///
1444 /// `level` One of the `ovrLogLevel` constants.
1445 ///
1446 /// `message` A UTF8-encoded null-terminated string.
1447 ///
1448 /// Returns the strlen of the message or a negative value if the message is too large.
1449 ///
1450 /// see [`ovrLogLevel`](type.ovrLogLevel.html), [`ovrLogCallback`](type.ovrLogCallback.html)
1451 ///
1452 pub fn ovr_TraceMessage(level: c_int, message: *const c_char) -> c_int;
1453 /// Identify client application info.
1454 ///
1455 /// The string is one or more newline-delimited lines of optional info
1456 /// indicating engine name, engine version, engine plugin name, engine plugin
1457 /// version, engine editor. The order of the lines is not relevant. Individual
1458 /// lines are optional. A newline is not necessary at the end of the last line.
1459 ///
1460 /// Call after `ovr_Initialize` and before the first call to `ovr_Create`.
1461 ///
1462 /// Each value is limited to 20 characters. Key names such as 'EngineName:', 'EngineVersion:' do not count towards this limit.
1463 ///
1464 /// `identity` Specifies one or more newline-delimited lines of optional info:
1465 ///
1466 /// ```text
1467 /// EngineName: %s\n
1468 /// EngineVersion: %s\n
1469 /// EnginePluginName: %s\n
1470 /// EnginePluginVersion: %s\n
1471 /// EngineEditor: <boolean> ('true' or 'false')\n
1472 /// ```
1473 ///
1474 /// **Example code**
1475 ///
1476 /// ```no_run
1477 /// # use ovr_sys::*;
1478 /// # use ::std::ffi::CStr;
1479 /// # unsafe {
1480 /// let identity = b"EngineName: Unity\n\
1481 /// EngineVersion: 5.3.3\n\
1482 /// EnginePluginName: `OVRPlugin`\n\
1483 /// EnginePluginVersion: 1.2.0\n\
1484 /// EngineEditor: true\0";
1485 /// ovr_IdentifyClient(CStr::from_bytes_with_nul_unchecked(identity).as_ptr());
1486 /// # }
1487 /// ```
1488 ///
1489 pub fn ovr_IdentifyClient(identity: *const c_char) -> ovrResult;
1490
1491
1492 //-------------------------------------------------------------------------------------
1493 // @name HMD Management
1494 //
1495 // Handles the enumeration, creation, destruction, and properties of an HMD (head-mounted display).
1496 //@{
1497
1498
1499 /// Returns information about the current HMD.
1500 ///
1501 /// `ovr_Initialize` must have first been called in order for this to succeed, otherwise `ovrHmdDesc`::Type
1502 /// will be reported as `ovrHmd_None`.
1503 ///
1504 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`, else NULL in which
1505 /// case this function detects whether an HMD is present and returns its info if so.
1506 ///
1507 /// Returns an ovrHmdDesc. If the hmd is NULL and `ovrHmdDesc::Type` is `ovrHmd_None` then
1508 /// no HMD is present.
1509 ///
1510 pub fn ovr_GetHmdDesc(session: ovrSession) -> ovrHmdDesc;
1511 /// Returns the number of attached trackers.
1512 ///
1513 /// The number of trackers may change at any time, so this function should be called before use
1514 /// as opposed to once on startup.
1515 ///
1516 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
1517 ///
1518 pub fn ovr_GetTrackerCount(session: ovrSession) -> c_uint;
1519 /// Returns a given attached tracker description.
1520 ///
1521 /// `ovr_Initialize` must have first been called in order for this to succeed, otherwise the returned
1522 /// trackerDescArray will be zero-initialized. The data returned by this function can change at runtime.
1523 ///
1524 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
1525 ///
1526 /// `trackerDescIndex` Specifies a tracker index. The valid indexes are in the range of 0 to
1527 /// the tracker count returned by `ovr_GetTrackerCount`.
1528 ///
1529 /// Returns `ovrTrackerDesc`. An empty `ovrTrackerDesc` will be returned if `trackerDescIndex` is out of range.
1530 ///
1531 /// see [`ovrTrackerDesc`](struct.ovrTrackerDesc.html), [`ovr_GetTrackerCount`](fn.ovr_GetTrackerCount.html)
1532 ///
1533 pub fn ovr_GetTrackerDesc(session: ovrSession, trackerDescIndex: c_uint) -> ovrTrackerDesc;
1534 /// Creates a handle to a VR session.
1535 ///
1536 /// Upon success the returned `ovrSession` must be eventually freed with `ovr_Destroy` when it is no longer needed.
1537 ///
1538 /// A second call to `ovr_Create` will result in an error return value if the previous session has not been destroyed.
1539 ///
1540 /// **out** `pSession` Provides a pointer to an `ovrSession` which will be written to upon success.
1541 ///
1542 /// **out** `luid` Provides a system specific graphics adapter identifier that locates which
1543 /// graphics adapter has the HMD attached. This must match the adapter used by the application
1544 /// or no rendering output will be possible. This is important for stability on multi-adapter systems. An
1545 /// application that simply chooses the default adapter will not run reliably on multi-adapter systems.
1546 ///
1547 /// Returns an `ovrResult` indicating success or failure. Upon failure
1548 /// the returned `ovrSession` will be NULL.
1549 ///
1550 /// *Example code*
1551 ///
1552 /// ```no_run
1553 /// # use ovr_sys::*;
1554 /// # use ::std::mem;
1555 /// # unsafe {
1556 /// let mut session: ovrSession = mem::uninitialized();
1557 /// let mut luid: ovrGraphicsLuid = mem::uninitialized();
1558 /// let result = ovr_Create(&mut session as *mut _, &mut luid as *mut _);
1559 /// if OVR_FAILURE(result) {
1560 /// // handle error
1561 /// }
1562 /// # }
1563 /// ```
1564 ///
1565 /// see [`ovr_Destroy`](fn.ovr_Destroy.html)
1566 ///
1567 pub fn ovr_Create(pSession: *mut ovrSession, pLuid: *mut ovrGraphicsLuid) -> ovrResult;
1568 /// Destroys the session.
1569 ///
1570 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
1571 ///
1572 /// see [`ovr_Create`](fn.ovr_Create.html)
1573 ///
1574 pub fn ovr_Destroy(session: ovrSession);
1575
1576}
1577
1578/// Specifies status information for the current session.
1579///
1580/// see [`ovr_GetSessionStatus`](fn.ovr_GetSessionStatus.html)
1581///
1582#[repr(C)]
1583#[derive(Debug, Copy, Clone)]
1584pub struct ovrSessionStatus {
1585 /// True if the process has VR focus and thus is visible in the HMD.
1586 pub IsVisible: ovrBool,
1587 /// True if an HMD is present.
1588 pub HmdPresent: ovrBool,
1589 /// True if the HMD is on the user's head.
1590 pub HmdMounted: ovrBool,
1591 /// True if the session is in a display-lost state. See `ovr_SubmitFrame`.
1592 pub DisplayLost: ovrBool,
1593 /// True if the application should initiate shutdown.
1594 pub ShouldQuit: ovrBool,
1595 /// True if UX has requested re-centering. Must call `ovr_ClearShouldRecenterFlag`, `ovr_RecenterTrackingOrigin` or `ovr_SpecifyTrackingOrigin`.
1596 pub ShouldRecenter: ovrBool,
1597}
1598
1599extern "C" {
1600
1601 /// Returns status information for the application.
1602 ///
1603 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
1604 ///
1605 /// **out** `sessionStatus` Provides an `ovrSessionStatus` that is filled in.
1606 ///
1607 /// Returns an `ovrResult` indicating success or failure. In the case of
1608 /// failure, use `ovr_GetLastErrorInfo` to get more information.
1609 /// Return values include but aren't limited to:
1610 /// * `ovrSuccess`: Completed successfully.
1611 /// * `ovrError_ServiceConnection`: The service connection was lost and the application
1612 /// must destroy the session.
1613 ///
1614 pub fn ovr_GetSessionStatus(session: ovrSession, sessionStatus: *mut ovrSessionStatus) -> ovrResult;
1615
1616
1617 //@}
1618
1619
1620
1621 //-------------------------------------------------------------------------------------
1622 // @name Tracking
1623 //
1624 // Tracking functions handle the position, orientation, and movement of the HMD in space.
1625 //
1626 // All tracking interface functions are thread-safe, allowing tracking state to be sampled
1627 // from different threads.
1628 //
1629 //@{
1630
1631
1632
1633 /// Sets the tracking origin type
1634 ///
1635 /// When the tracking origin is changed, all of the calls that either provide
1636 /// or accept `ovrPosef` will use the new tracking origin provided.
1637 ///
1638 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
1639 ///
1640 /// `origin` Specifies an `ovrTrackingOrigin` to be used for all `ovrPosef`
1641 ///
1642 /// Returns an `ovrResult` indicating success or failure. In the case of failure, use
1643 /// `ovr_GetLastErrorInfo` to get more information.
1644 ///
1645 /// see [`ovrTrackingOrigin`](type.ovrTrackingOrigin.html), [`ovr_GetTrackingOriginType`](fn.ovr_GetTrackingOriginType.html)
1646 pub fn ovr_SetTrackingOriginType(session: ovrSession, origin: ovrTrackingOrigin) -> ovrResult;
1647 /// Gets the tracking origin state
1648 ///
1649 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
1650 ///
1651 /// Returns the `ovrTrackingOrigin` that was either set by default, or previous set by the application.
1652 ///
1653 /// see [`ovrTrackingOrigin`](type.ovrTrackingOrigin.html), [`ovr_SetTrackingOriginType`](fn.ovr_SetTrackingOriginType.html)
1654 pub fn ovr_GetTrackingOriginType(session: ovrSession) -> ovrTrackingOrigin;
1655 /// Re-centers the sensor position and orientation.
1656 ///
1657 /// This resets the (x,y,z) positional components and the yaw orientation component of the
1658 /// tracking space for the HMD and controllers using the HMD's current tracking pose.
1659 /// If the caller requires some tweaks on top of the HMD's current tracking pose, consider using
1660 /// `ovr_SpecifyTrackingOrigin` instead.
1661 ///
1662 /// The Roll and pitch orientation components are always determined by gravity and cannot
1663 /// be redefined. All future tracking will report values relative to this new reference position.
1664 /// If you are using `ovrTrackerPoses` then you will need to call `ovr_GetTrackerPose` after
1665 /// this, because the sensor position(s) will change as a result of this.
1666 ///
1667 /// The headset cannot be facing vertically upward or downward but rather must be roughly
1668 /// level otherwise this function will fail with `ovrError_InvalidHeadsetOrientation`.
1669 ///
1670 /// For more info, see the notes on each `ovrTrackingOrigin` enumeration to understand how
1671 /// recenter will vary slightly in its behavior based on the current `ovrTrackingOrigin` setting.
1672 ///
1673 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
1674 ///
1675 /// Returns an `ovrResult` indicating success or failure. In the case of failure, use
1676 /// `ovr_GetLastErrorInfo` to get more information. Return values include but aren't limited to:
1677 /// * `ovrSuccess`: Completed successfully.
1678 /// * `ovrError_InvalidHeadsetOrientation`: The headset was facing an invalid direction when
1679 /// attempting recentering, such as facing vertically.
1680 ///
1681 /// see [`ovrTrackingOrigin`](type.ovrTrackingOrigin.html), [`ovr_GetTrackerPose`](fn.ovr_GetTrackerPose.html), [`ovr_SpecifyTrackingOrigin`](fn.ovr_SpecifyTrackingOrigin.html)
1682 ///
1683 pub fn ovr_RecenterTrackingOrigin(session: ovrSession) -> ovrResult;
1684 /// Allows manually tweaking the sensor position and orientation.
1685 ///
1686 /// This function is similar to `ovr_RecenterTrackingOrigin` in that it modifies the
1687 /// (x,y,z) positional components and the yaw orientation component of the tracking space for
1688 /// the HMD and controllers.
1689 ///
1690 /// While `ovr_RecenterTrackingOrigin` resets the tracking origin in reference to the HMD's
1691 /// current pose, `ovr_SpecifyTrackingOrigin` allows the caller to explicitly specify a transform
1692 /// for the tracking origin. This transform is expected to be an offset to the most recent
1693 /// recentered origin, so calling this function repeatedly with the same originPose will keep
1694 /// nudging the recentered origin in that direction.
1695 ///
1696 /// There are several use cases for this function. For example, if the application decides to
1697 /// limit the yaw, or translation of the recentered pose instead of directly using the HMD pose
1698 /// the application can query the current tracking state via `ovr_GetTrackingState`, and apply
1699 /// some limitations to the HMD pose because feeding this pose back into this function.
1700 /// Similarly, this can be used to "adjust the seating position" incrementally in apps that
1701 /// feature seated experiences such as cockpit-based games.
1702 ///
1703 /// This function can emulate `ovr_RecenterTrackingOrigin` as such:
1704 ///
1705 /// ```no_run
1706 /// # use ovr_sys::*;
1707 /// # unsafe {
1708 /// # let session = ::std::mem::zeroed();
1709 /// let ts = ovr_GetTrackingState(session, 0.0, ovrFalse);
1710 /// ovr_SpecifyTrackingOrigin(session, ts.HeadPose.ThePose);
1711 /// # }
1712 /// ```
1713 ///
1714 /// The roll and pitch orientation components are determined by gravity and cannot be redefined.
1715 /// If you are using ovrTrackerPoses then you will need to call `ovr_GetTrackerPose` after
1716 /// this, because the sensor position(s) will change as a result of this.
1717 ///
1718 /// For more info, see the notes on each ovrTrackingOrigin enumeration to understand how
1719 /// recenter will vary slightly in its behavior based on the current ovrTrackingOrigin setting.
1720 ///
1721 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
1722 ///
1723 /// `originPose` Specifies a pose that will be used to transform the current tracking
1724 /// origin.
1725 ///
1726 /// Returns an `ovrResult` indicating success or failure. In the case of failure, use
1727 /// `ovr_GetLastErrorInfo` to get more information. Return values include but aren't limited
1728 /// to:
1729 ///
1730 /// * `ovrSuccess`: Completed successfully.
1731 /// * `ovrError_InvalidParameter`: The heading direction in `originPose` was invalid,
1732 /// such as facing vertically. This can happen if the caller is directly feeding the pose
1733 /// of a position-tracked device such as an HMD or controller into this function.
1734 ///
1735 /// see [`ovrTrackingOrigin`](type.ovrTrackingOrigin.html), [`ovr_GetTrackerPose`](fn.ovr_GetTrackerPose.html), [`ovr_RecenterTrackingOrigin`](fn.ovr_RecenterTrackingOrigin.html)
1736 ///
1737 pub fn ovr_SpecifyTrackingOrigin(session: ovrSession, originPose: ovrPosef) -> ovrResult;
1738 /// Clears the ShouldRecenter status bit in `ovrSessionStatus`.
1739 ///
1740 /// Clears the ShouldRecenter status bit in `ovrSessionStatus`, allowing further recenter
1741 /// requests to be detected. Since this is automatically done by `ovr_RecenterTrackingOrigin` and `ovr_SpecifyTrackingOrigin`,
1742 /// this is only needs to be called when application is doing its own re-centering.
1743 pub fn ovr_ClearShouldRecenterFlag(session: ovrSession);
1744 /// Returns tracking state reading based on the specified absolute system time.
1745 ///
1746 /// Pass an absTime value of 0.0 to request the most recent sensor reading. In this case
1747 /// both PredictedPose and SamplePose will have the same value.
1748 ///
1749 /// This may also be used for more refined timing of front buffer rendering logic, and so on.
1750 ///
1751 /// This may be called by multiple threads.
1752 ///
1753 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
1754 ///
1755 /// `absTime` Specifies the absolute future time to predict the return
1756 /// `ovrTrackingState` value. Use 0 to request the most recent tracking state.
1757 ///
1758 /// `latencyMarker` Specifies that this call is the point in time where
1759 /// the "App-to-Mid-Photon" latency timer starts from. If a given `ovrLayer`
1760 /// provides "SensorSampleTime", that will override the value stored here.
1761 ///
1762 /// Returns the `ovrTrackingState` that is predicted for the given absTime.
1763 ///
1764 /// see [`ovrTrackingState`](struct.ovrTrackingState.html), [`ovr_GetEyePoses`](fn.ovr_GetEyePoses.html), [`ovr_GetTimeInSeconds`](fn.ovr_GetTimeInSeconds.html)
1765 ///
1766 pub fn ovr_GetTrackingState(session: ovrSession, absTime: f64, latencyMarker: ovrBool) -> ovrTrackingState;
1767 /// Returns an array of poses, where each pose matches a device type provided by the `deviceTypes`
1768 /// array parameter.
1769 ///
1770 /// **in** `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
1771 ///
1772 /// **in** `deviceTypes` Array of device types to query for their poses.
1773 ///
1774 /// **in** `deviceCount` Number of queried poses. This number must match the length of the
1775 /// `outDevicePoses` and `deviceTypes` array.
1776 ///
1777 /// **in** `absTime` Specifies the absolute future time to predict the return
1778 /// `ovrTrackingState` value. Use 0 to request the most recent tracking state.
1779 ///
1780 /// **out** `outDevicePoses` Array of poses, one for each device type in `deviceTypes` arrays.
1781 ///
1782 /// Returns an `ovrResult` for which `OVR_SUCCESS(result)` is false upon error and
1783 /// true upon success.
1784 ///
1785 pub fn ovr_GetDevicePoses(session: ovrSession, deviceTypes: *const ovrTrackedDeviceType, deviceCount: c_int, absTime: f64, outDevicePoses: *mut ovrPoseStatef) -> ovrResult;
1786 /// Returns the `ovrTrackerPose` for the given attached tracker.
1787 ///
1788 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
1789 ///
1790 /// `trackerPoseIndex` Index of the tracker being requested.
1791 ///
1792 /// Returns the requested `ovrTrackerPose`. An empty `ovrTrackerPose` will be returned if trackerPoseIndex is out of range.
1793 ///
1794 /// see [`ovr_GetTrackerCount`](fn.ovr_GetTrackerCount.html)
1795 ///
1796 pub fn ovr_GetTrackerPose(session: ovrSession, trackerPoseIndex: c_uint) -> ovrTrackerPose;
1797 /// Returns the most recent input state for controllers, without positional tracking info.
1798 ///
1799 /// **out** `inputState` Input state that will be filled in.
1800 ///
1801 /// `ovrControllerType` Specifies which controller the input will be returned for.
1802 ///
1803 /// Returns `ovrSuccess` if the new state was successfully obtained.
1804 ///
1805 /// see [`ovrControllerType`](type.ovrControllerType.html)
1806 ///
1807 pub fn ovr_GetInputState(session: ovrSession, controllerType: ovrControllerType, inputState: *mut ovrInputState) -> ovrResult;
1808 /// Returns controller types connected to the system OR'ed together.
1809 ///
1810 /// Returns a bitmask of `ovrControllerTypes` connected to the system.
1811 ///
1812 /// see [`ovrControllerType`](type.ovrControllerType.html)
1813 ///
1814 pub fn ovr_GetConnectedControllerTypes(session: ovrSession) -> c_uint;
1815 /// Gets information about Haptics engine for the specified Touch controller.
1816 ///
1817 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
1818 ///
1819 /// `controllerType` The controller to retrieve the information from.
1820 ///
1821 /// Returns an `ovrTouchHapticsDesc`.
1822 ///
1823 pub fn ovr_GetTouchHapticsDesc(session: ovrSession, controllerType: ovrControllerType) -> ovrTouchHapticsDesc;
1824 /// Sets constant vibration (with specified frequency and amplitude) to a controller.
1825 ///
1826 /// Note: `ovr_SetControllerVibration` cannot be used interchangeably with `ovr_SubmitControllerVibration`.
1827 ///
1828 /// This method should be called periodically, vibration lasts for a maximum of 2.5 seconds.
1829 ///
1830 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
1831 ///
1832 /// `controllerType` The controller to set the vibration to.
1833 ///
1834 /// `frequency` Vibration frequency. Supported values are: 0.0 (disabled), 0.5 and 1.0. Non valid values will be clamped.
1835 /// `amplitude` Vibration amplitude in the `[0.0, 1.0]` range.
1836 ///
1837 /// Returns an `ovrResult` for which `OVR_SUCCESS(result)` is false upon error and true
1838 /// upon success. Return values include but aren't limited to:
1839 /// * `ovrSuccess`: The call succeeded and a result was returned.
1840 /// * `ovrSuccess_DeviceUnavailable`: The call succeeded but the device referred to by controllerType is not available.
1841 ///
1842 pub fn ovr_SetControllerVibration(session: ovrSession, controllerType: ovrControllerType, frequency: f32, amplitude: f32) -> ovrResult;
1843 /// Submits a Haptics buffer (used for vibration) to Touch (only) controllers.
1844 ///
1845 /// Note: `ovr_SubmitControllerVibration` cannot be used interchangeably with `ovr_SetControllerVibration`.
1846 ///
1847 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
1848 ///
1849 /// `controllerType` Controller where the Haptics buffer will be played.
1850 ///
1851 /// `buffer` Haptics buffer containing amplitude samples to be played.
1852 ///
1853 /// Returns an `ovrResult` for which `OVR_SUCCESS(result)` is false upon error and true
1854 /// upon success. Return values include but aren't limited to:
1855 /// * `ovrSuccess`: The call succeeded and a result was returned.
1856 /// * `ovrSuccess_DeviceUnavailable`: The call succeeded but the device referred to by controllerType is not available.
1857 ///
1858 /// see [`ovrHapticsBuffer`](struct.ovrHapticsBuffer.html)
1859 ///
1860 pub fn ovr_SubmitControllerVibration(session: ovrSession, controllerType: ovrControllerType, buffer: *const ovrHapticsBuffer) -> ovrResult;
1861 /// Gets the Haptics engine playback state of a specific Touch controller.
1862 ///
1863 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
1864 ///
1865 /// `controllerType` Controller where the Haptics buffer wil be played.
1866 ///
1867 /// `outState` State of the haptics engine.
1868 ///
1869 /// Returns an `ovrResult` for which `OVR_SUCCESS(result)` is false upon error and true
1870 /// upon success. Return values include but aren't limited to:
1871 /// * `ovrSuccess`: The call succeeded and a result was returned.
1872 /// * `ovrSuccess_DeviceUnavailable`: The call succeeded but the device referred to by controllerType is not available.
1873 ///
1874 /// see [`ovrHapticsPlaybackState`](struct.ovrHapticsPlaybackState.html)
1875 ///
1876 pub fn ovr_GetControllerVibrationState(session: ovrSession, controllerType: ovrControllerType, outState: *mut ovrHapticsPlaybackState) -> ovrResult;
1877 /// Tests collision/proximity of position tracked devices (e.g. HMD and/or Touch) against the Boundary System.
1878 /// Note: this method is similar to `ovr_BoundaryTestPoint` but can be more precise as it may take into account device acceleration/momentum.
1879 ///
1880 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
1881 ///
1882 /// `deviceBitmask` Bitmask of one or more tracked devices to test.
1883 ///
1884 /// `boundaryType` Must be either `ovrBoundary_Outer` or `ovrBoundary_PlayArea`.
1885 ///
1886 /// **out** `outTestResult` Result of collision/proximity test, contains information such as distance and closest point.
1887 /// Returns an `ovrResult` for which `OVR_SUCCESS(result)` is false upon error and true
1888 /// upon success. Return values include but aren't limited to:
1889 /// * `ovrSuccess`: The call succeeded and a result was returned.
1890 /// * `ovrSuccess_BoundaryInvalid`: The call succeeded but the result is not a valid boundary due to not being set up.
1891 /// * `ovrSuccess_DeviceUnavailable`: The call succeeded but the device referred to by deviceBitmask is not available.
1892 ///
1893 /// see [`ovrBoundaryTestResult`](struct.ovrBoundaryTestResult.html)
1894 ///
1895 pub fn ovr_TestBoundary(session: ovrSession, deviceBitmask: ovrTrackedDeviceType, boundaryType: ovrBoundaryType, outTestResult: *mut ovrBoundaryTestResult) -> ovrResult;
1896 /// Tests collision/proximity of a 3D point against the Boundary System.
1897 ///
1898 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
1899 ///
1900 /// `point` 3D point to test.
1901 ///
1902 /// `singleBoundaryType` Must be either `ovrBoundary_Outer` or `ovrBoundary_PlayArea` to test against
1903 /// **out** `outTestResult` Result of collision/proximity test, contains information such as distance and closest point.
1904 /// Returns an `ovrResult` for which `OVR_SUCCESS(result)` is false upon error and true
1905 /// upon success. Return values include but aren't limited to:
1906 /// * `ovrSuccess`: The call succeeded and a result was returned.
1907 /// * `ovrSuccess_BoundaryInvalid`: The call succeeded but the result is not a valid boundary due to not being set up.
1908 ///
1909 /// see [`ovrBoundaryTestResult`](struct.ovrBoundaryTestResult.html)
1910 ///
1911 pub fn ovr_TestBoundaryPoint(session: ovrSession, point: *const ovrVector3f, singleBoundaryType: ovrBoundaryType, outTestResult: *mut ovrBoundaryTestResult) -> ovrResult;
1912 /// Sets the look and feel of the Boundary System.
1913 ///
1914 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
1915 ///
1916 /// `lookAndFeel` Look and feel parameters.
1917 ///
1918 /// Returns `ovrSuccess` upon success.
1919 ///
1920 /// see [`ovrBoundaryLookAndFeel`](struct.ovrBoundaryLookAndFeel.html)
1921 ///
1922 pub fn ovr_SetBoundaryLookAndFeel(session: ovrSession, lookAndFeel: *const ovrBoundaryLookAndFeel) -> ovrResult;
1923 /// Resets the look and feel of the Boundary System to its default state.
1924 ///
1925 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
1926 ///
1927 /// Returns `ovrSuccess` upon success.
1928 ///
1929 /// see [`ovrBoundaryLookAndFeel`](struct.ovrBoundaryLookAndFeel.html)
1930 ///
1931 pub fn ovr_ResetBoundaryLookAndFeel(session: ovrSession) -> ovrResult;
1932 /// Gets the geometry of the Boundary System's "play area" or "outer boundary" as 3D floor points.
1933 ///
1934 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
1935 ///
1936 /// `boundaryType` Must be either `ovrBoundary_Outer` or `ovrBoundary_PlayArea`.
1937 ///
1938 /// **out** `outFloorPoints` Array of 3D points (in clockwise order) defining the boundary at floor height (can be NULL to retrieve only the number of points).
1939 /// **out** `outFloorPointsCount` Number of 3D points returned in the array.
1940 ///
1941 /// Returns an `ovrResult` for which `OVR_SUCCESS(result)` is false upon error and true
1942 /// upon success. Return values include but aren't limited to:
1943 /// * `ovrSuccess`: The call succeeded and a result was returned.
1944 /// * `ovrSuccess_BoundaryInvalid`: The call succeeded but the result is not a valid boundary due to not being set up.
1945 ///
1946 pub fn ovr_GetBoundaryGeometry(session: ovrSession, boundaryType: ovrBoundaryType, outFloorPoints: *mut ovrVector3f, outFloorPointsCount: *mut c_int) -> ovrResult;
1947 /// Gets the dimension of the Boundary System's "play area" or "outer boundary".
1948 ///
1949 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
1950 ///
1951 /// `boundaryType` Must be either `ovrBoundary_Outer` or `ovrBoundary_PlayArea`.
1952 ///
1953 /// **out** `dimensions` Dimensions of the axis aligned bounding box that encloses the area in meters (width, height and length).
1954 ///
1955 /// Returns an `ovrResult` for which `OVR_SUCCESS(result)` is false upon error and true
1956 /// upon success. Return values include but aren't limited to:
1957 /// * `ovrSuccess`: The call succeeded and a result was returned.
1958 /// * `ovrSuccess_BoundaryInvalid`: The call succeeded but the result is not a valid boundary due to not being set up.
1959 ///
1960 pub fn ovr_GetBoundaryDimensions(session: ovrSession, boundaryType: ovrBoundaryType, outDimensions: *mut ovrVector3f) -> ovrResult;
1961 /// Returns if the boundary is currently visible.
1962 /// Note: visibility is false if the user has turned off boundaries, otherwise, it's true if the app has requested
1963 /// boundaries to be visible or if any tracked device is currently triggering it. This may not exactly match rendering
1964 /// due to fade-in and fade-out effects.
1965 ///
1966 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
1967 ///
1968 /// **out** `outIsVisible` `ovrTrue`, if the boundary is visible.
1969 ///
1970 /// Returns an `ovrResult` for which `OVR_SUCCESS(result)` is false upon error and true
1971 /// upon success. Return values include but aren't limited to:
1972 /// * `ovrSuccess`: Result was successful and a result was returned.
1973 /// * `ovrSuccess_BoundaryInvalid`: The call succeeded but the result is not a valid boundary due to not being set up.
1974 ///
1975 pub fn ovr_GetBoundaryVisible(session: ovrSession, outIsVisible: *mut ovrBool) -> ovrResult;
1976 /// Requests boundary to be visible.
1977 ///
1978 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
1979 /// `visible` forces the outer boundary to be visible. An application can't force it to be invisible, but can cancel its request by passing false.
1980
1981 /// Returns `ovrSuccess` upon success.
1982 ///
1983 pub fn ovr_RequestBoundaryVisible(session: ovrSession, visible: ovrBool) -> ovrResult;
1984
1985}
1986
1987//-------------------------------------------------------------------------------------
1988// @name Layers
1989//
1990//@{
1991
1992
1993/// Specifies the maximum number of layers supported by `ovr_SubmitFrame`.
1994///
1995/// /see `ovr_SubmitFrame`
1996///
1997/// Describes layer types that can be passed to `ovr_SubmitFrame`.
1998pub const ovrMaxLayerCount: u32 = 16;
1999/// Each layer type has an associated struct, such as `ovrLayerEyeFov`.
2000///
2001/// see [`ovrLayerHeader`](struct.ovrLayerHeader.html)
2002///
2003pub type ovrLayerType = i32;
2004/// Layer is disabled.
2005pub const ovrLayerType_Disabled: ovrLayerType = 0;
2006/// Described by `ovrLayerEyeFov`.
2007pub const ovrLayerType_EyeFov: ovrLayerType = 1;
2008/// Described by `ovrLayerQuad`. Previously called `ovrLayerType_QuadInWorld`.
2009pub const ovrLayerType_Quad: ovrLayerType = 3;
2010// enum 4 used to be ovrLayerType_QuadHeadLocked. Instead, use ovrLayerType_Quad with ovrLayerFlag_HeadLocked.
2011/// Described by `ovrLayerEyeMatrix`.
2012pub const ovrLayerType_EyeMatrix: ovrLayerType = 5;
2013/// Identifies flags used by `ovrLayerHeader` and which are passed to `ovr_SubmitFrame`.
2014///
2015/// see [`ovrLayerHeader`](struct.ovrLayerHeader.html)
2016///
2017pub type ovrLayerFlags = i32;
2018/// `ovrLayerFlag_HighQuality` enables 4x anisotropic sampling during the composition of the layer.
2019///
2020/// The benefits are mostly visible at the periphery for high-frequency & high-contrast visuals.
2021///
2022/// For best results consider combining this flag with an `ovrTextureSwapChain` that has mipmaps and
2023/// instead of using arbitrary sized textures, prefer texture sizes that are powers-of-two.
2024///
2025/// Actual rendered viewport and doesn't necessarily have to fill the whole texture.
2026pub const ovrLayerFlag_HighQuality: ovrLayerFlags = 0x01;
2027/// `ovrLayerFlag_TextureOriginAtBottomLeft`: the opposite is TopLeft.
2028/// Generally this is false for D3D, true for OpenGL.
2029pub const ovrLayerFlag_TextureOriginAtBottomLeft: ovrLayerFlags = 0x02;
2030/// Mark this surface as "headlocked", which means it is specified
2031/// relative to the HMD and moves with it, rather than being specified
2032/// relative to sensor/torso space and remaining still while the head moves.
2033///
2034/// What used to be `ovrLayerType_QuadHeadLocked` is now `ovrLayerType_Quad` plus this flag.
2035///
2036/// However the flag can be applied to any layer type to achieve a similar effect.
2037pub const ovrLayerFlag_HeadLocked: ovrLayerFlags = 0x04;
2038/// Defines properties shared by all `ovrLayer` structs, such as `ovrLayerEyeFov`.
2039///
2040/// `ovrLayerHeader` is used as a base member in these larger structs.
2041///
2042/// This struct cannot be used by itself except for the case that Type is `ovrLayerType_Disabled`.
2043///
2044/// see [`ovrLayerType`](type.ovrLayerType.html), [`ovrLayerFlags`](type.ovrLayerFlags.html)
2045///
2046#[repr(C)]
2047#[derive(Debug, Copy, Clone)]
2048pub struct ovrLayerHeader {
2049 pub _align: [isize; 0],
2050 /// Described by `ovrLayerType`.
2051 pub Type: ovrLayerType,
2052 /// Described by `ovrLayerFlags`.
2053 pub Flags: c_unsigned,
2054}
2055
2056
2057/// Describes a layer that specifies a monoscopic or stereoscopic view.
2058///
2059/// This is the kind of layer that's typically used as layer 0 to `ovr_SubmitFrame`,
2060/// as it is the kind of layer used to render a 3D stereoscopic view.
2061///
2062/// Three options exist with respect to mono/stereo texture usage:
2063/// * `ColorTexture[0]` and `ColorTexture[1]` contain the left and right stereo renderings, respectively.
2064/// `Viewport[0]` and `Viewport[1]` refer to `ColorTexture[0]` and `ColorTexture[1]`, respectively.
2065/// * `ColorTexture[0]` contains both the left and right renderings, `ColorTexture[1]` is NULL,
2066/// and `Viewport[0]` and `Viewport[1]` refer to sub-rects with `ColorTexture[0]`.
2067/// * `ColorTexture[0]` contains a single monoscopic rendering, and `Viewport[0]` and
2068/// `Viewport[1]` both refer to that rendering.
2069///
2070/// see [`ovrTextureSwapChain`](type.ovrTextureSwapChain.html), [`ovr_SubmitFrame`](fn.ovr_SubmitFrame.html)
2071///
2072#[repr(C)]
2073#[derive(Debug, Copy, Clone)]
2074pub struct ovrLayerEyeFov {
2075 pub _align: [isize; 0],
2076 /// Header.Type must be `ovrLayerType_EyeFov`.
2077 pub Header: ovrLayerHeader,
2078
2079 /// `ovrTextureSwapChains` for the left and right eye respectively.
2080 ///
2081 /// The second one of which can be NULL for cases described above.
2082 pub ColorTexture: [ovrTextureSwapChain; ovrEye_Count as usize],
2083
2084 /// Specifies the ColorTexture sub-rect UV coordinates.
2085 ///
2086 /// Both `Viewport[0]` and `Viewport[1]` must be valid.
2087 pub Viewport: [ovrRecti; ovrEye_Count as usize],
2088
2089 /// The viewport field of view.
2090 pub Fov: [ovrFovPort; ovrEye_Count as usize],
2091
2092 /// Specifies the position and orientation of each eye view, with the position specified in meters.
2093 ///
2094 /// RenderPose will typically be the value returned from `ovr_CalcEyePoses`,
2095 /// but can be different in special cases if a different head pose is used for rendering.
2096 pub RenderPose: [ovrPosef; ovrEye_Count as usize],
2097
2098 /// Specifies the timestamp when the source `ovrPosef` (used in calculating RenderPose)
2099 /// was sampled from the SDK. Typically retrieved by calling `ovr_GetTimeInSeconds`
2100 /// around the instant the application calls `ovr_GetTrackingState`
2101 /// The main purpose for this is to accurately track app tracking latency.
2102 pub SensorSampleTime: f64,
2103
2104}
2105
2106
2107
2108
2109/// Describes a layer that specifies a monoscopic or stereoscopic view.
2110///
2111/// This uses a direct 3x4 matrix to map from view space to the UV coordinates.
2112///
2113/// It is essentially the same thing as `ovrLayerEyeFov` but using a much
2114/// lower level. This is mainly to provide compatibility with specific apps.
2115///
2116/// Unless the application really requires this flexibility, it is usually better
2117/// to use `ovrLayerEyeFov`.
2118///
2119/// Three options exist with respect to mono/stereo texture usage:
2120/// * `ColorTexture[0]` and `ColorTexture[1]` contain the left and right stereo renderings, respectively.
2121/// `Viewport[0]` and `Viewport[1]` refer to `ColorTexture[0]` and `ColorTexture[1]`, respectively.
2122/// * `ColorTexture[0]` contains both the left and right renderings, `ColorTexture[1]` is NULL,
2123/// and `Viewport[0]` and `Viewport[1]` refer to sub-rects with `ColorTexture[0]`.
2124/// * `ColorTexture[0]` contains a single monoscopic rendering, and `Viewport[0]` and
2125/// `Viewport[1]` both refer to that rendering.
2126///
2127/// see [`ovrTextureSwapChain`](type.ovrTextureSwapChain.html), [`ovr_SubmitFrame`](fn.ovr_SubmitFrame.html)
2128///
2129#[repr(C)]
2130#[derive(Debug, Copy, Clone)]
2131pub struct ovrLayerEyeMatrix {
2132 pub _align: [isize; 0],
2133 /// Header.Type must be `ovrLayerType_EyeMatrix`.
2134 pub Header: ovrLayerHeader,
2135
2136 /// `ovrTextureSwapChains` for the left and right eye respectively.
2137 ///
2138 /// The second one of which can be NULL for cases described above.
2139 pub ColorTexture: [ovrTextureSwapChain; ovrEye_Count as usize],
2140
2141 /// Specifies the ColorTexture sub-rect UV coordinates.
2142 ///
2143 /// Both `Viewport[0]` and `Viewport[1]` must be valid.
2144 pub Viewport: [ovrRecti; ovrEye_Count as usize],
2145
2146 /// Specifies the position and orientation of each eye view, with the position specified in meters.
2147 ///
2148 /// RenderPose will typically be the value returned from `ovr_CalcEyePoses`,
2149 /// but can be different in special cases if a different head pose is used for rendering.
2150 pub RenderPose: [ovrPosef; ovrEye_Count as usize],
2151
2152 /// Specifies the mapping from a view-space vector
2153 /// to a UV coordinate on the textures given above.
2154 ///
2155 /// P = (x,y,z,1)*Matrix
2156 /// TexU = P.x/P.z
2157 /// TexV = P.y/P.z
2158 pub Matrix: [ovrMatrix4f; ovrEye_Count as usize],
2159
2160 /// Specifies the timestamp when the source `ovrPosef` (used in calculating RenderPose)
2161 /// was sampled from the SDK. Typically retrieved by calling `ovr_GetTimeInSeconds`
2162 /// around the instant the application calls `ovr_GetTrackingState`
2163 /// The main purpose for this is to accurately track app tracking latency.
2164 pub SensorSampleTime: f64,
2165
2166}
2167
2168
2169
2170
2171
2172/// Describes a layer of Quad type, which is a single quad in world or viewer space.
2173///
2174/// It is used for `ovrLayerType_Quad`. This type of layer represents a single
2175/// object placed in the world and not a stereo view of the world itself.
2176///
2177/// A typical use of `ovrLayerType_Quad` is to draw a television screen in a room
2178/// that for some reason is more convenient to draw as a layer than as part of the main
2179/// view in layer 0. For example, it could implement a 3D popup GUI that is drawn at a
2180/// higher resolution than layer 0 to improve fidelity of the GUI.
2181///
2182/// Quad layers are visible from both sides; they are not back-face culled.
2183///
2184/// see [`ovrTextureSwapChain`](type.ovrTextureSwapChain.html), [`ovr_SubmitFrame`](fn.ovr_SubmitFrame.html)
2185///
2186#[repr(C)]
2187#[derive(Debug, Copy, Clone)]
2188pub struct ovrLayerQuad {
2189 pub _align: [isize; 0],
2190 /// Header.Type must be `ovrLayerType_Quad`.
2191 pub Header: ovrLayerHeader,
2192
2193 /// Contains a single image, never with any stereo view.
2194 pub ColorTexture: ovrTextureSwapChain,
2195
2196 /// Specifies the ColorTexture sub-rect UV coordinates.
2197 pub Viewport: ovrRecti,
2198
2199 /// Specifies the orientation and position of the center point of a Quad layer type.
2200 ///
2201 /// The supplied direction is the vector perpendicular to the quad.
2202 ///
2203 /// The position is in real-world meters (not the application's virtual world,
2204 /// the physical world the user is in) and is relative to the "zero" position
2205 /// set by `ovr_RecenterTrackingOrigin` unless the `ovrLayerFlag_HeadLocked` flag is used.
2206 pub QuadPoseCenter: ovrPosef,
2207
2208 /// Width and height (respectively) of the quad in meters.
2209 pub QuadSize: ovrVector2f,
2210
2211}
2212
2213
2214
2215
2216/// Union that combines `ovrLayer` types in a way that allows them
2217/// to be used in a polymorphic way.
2218/*typedef union ovrLayer_Union_
2219{
2220 pub Header: ovrLayerHeader,
2221 pub EyeFov: ovrLayerEyeFov,
2222 pub Quad: ovrLayerQuad,
2223}*/
2224
2225
2226//@}
2227
2228// @name SDK Distortion Rendering
2229//
2230// All of rendering functions including the configure and frame functions
2231// are not thread safe. It is OK to use ConfigureRendering on one thread and handle
2232// frames on another thread, but explicit synchronization must be done since
2233// functions that depend on configured state are not reentrant.
2234//
2235// These functions support rendering of distortion by the SDK.
2236//
2237//@{
2238
2239extern "C" {
2240
2241 /// TextureSwapChain creation is rendering API-specific.
2242 ///
2243 /// `ovr_CreateTextureSwapChainDX`, `ovr_CreateTextureSwapChainGL` and `ovr_CreateTextureSwapChainVk` can be found in the
2244 /// rendering API-specific headers, such as OVR_CAPI_D3D.h and `OVR_CAPI_GL`.h
2245
2246 /// Gets the number of buffers in an `ovrTextureSwapChain`.
2247 ///
2248 /// **in** `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
2249 ///
2250 /// **in** `chain` Specifies the `ovrTextureSwapChain` for which the length should be retrieved.
2251 ///
2252 /// **out** `out_Length` Returns the number of buffers in the specified chain.
2253 ///
2254 /// Returns an `ovrResult` for which `OVR_SUCCESS(result)` is false upon error.
2255 ///
2256 /// see [`ovr_CreateTextureSwapChainDX`](directx/fn.ovr_CreateTextureSwapChainDX.html), [`ovr_CreateTextureSwapChainGL`](opengl/fn.ovr_CreateTextureSwapChainGL.html), [`ovr_CreateTextureSwapChainVk`](opengl/fn.ovr_CreateTextureSwapChainVk.html)
2257 ///
2258 pub fn ovr_GetTextureSwapChainLength(session: ovrSession, chain: ovrTextureSwapChain, out_Length: *mut c_int) -> ovrResult;
2259 /// Gets the current index in an `ovrTextureSwapChain`.
2260 ///
2261 /// **in** `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
2262 ///
2263 /// **in** `chain` Specifies the `ovrTextureSwapChain` for which the index should be retrieved.
2264 ///
2265 /// **out** `out_Index` Returns the current (free) index in specified chain.
2266 ///
2267 /// Returns an `ovrResult` for which `OVR_SUCCESS(result)` is false upon error.
2268 ///
2269 /// see [`ovr_CreateTextureSwapChainDX`](directx/fn.ovr_CreateTextureSwapChainDX.html), [`ovr_CreateTextureSwapChainGL`](opengl/fn.ovr_CreateTextureSwapChainGL.html), [`ovr_CreateTextureSwapChainVk`](opengl/fn.ovr_CreateTextureSwapChainVk.html)
2270 ///
2271 pub fn ovr_GetTextureSwapChainCurrentIndex(session: ovrSession, chain: ovrTextureSwapChain, out_Index: *mut c_int) -> ovrResult;
2272 /// Gets the description of the buffers in an `ovrTextureSwapChain`
2273 ///
2274 /// **in** `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
2275 ///
2276 /// **in** `chain` Specifies the `ovrTextureSwapChain` for which the description should be retrieved.
2277 ///
2278 /// **out** `out_Desc` Returns the description of the specified chain.
2279 ///
2280 /// Returns an `ovrResult` for which `OVR_SUCCESS(result)` is false upon error.
2281 ///
2282 /// see [`ovr_CreateTextureSwapChainDX`](directx/fn.ovr_CreateTextureSwapChainDX.html), [`ovr_CreateTextureSwapChainGL`](opengl/fn.ovr_CreateTextureSwapChainGL.html), [`ovr_CreateTextureSwapChainVk`](opengl/fn.ovr_CreateTextureSwapChainVk.html)
2283 ///
2284 pub fn ovr_GetTextureSwapChainDesc(session: ovrSession, chain: ovrTextureSwapChain, out_Desc: *mut ovrTextureSwapChainDesc) -> ovrResult;
2285 /// Commits any pending changes to an `ovrTextureSwapChain`, and advances its current index
2286 ///
2287 /// **in** `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
2288 ///
2289 /// **in** `chain` Specifies the `ovrTextureSwapChain` to commit.
2290 ///
2291 /// **Note**: When Commit is called, the texture at the current index is considered ready for use by the
2292 /// runtime, and further writes to it should be avoided. The swap chain's current index is advanced,
2293 /// providing there's room in the chain. The next time the SDK dereferences this texture swap chain,
2294 /// it will synchronize with the app's graphics context and pick up the submitted index, opening up
2295 /// room in the swap chain for further commits.
2296 ///
2297 /// Returns an `ovrResult` for which `OVR_SUCCESS(result)` is false upon error.
2298 /// Failures include but aren't limited to:
2299 ///
2300 /// * `ovrError_TextureSwapChainFull`: `ovr_CommitTextureSwapChain` was called too many times on a texture swapchain without calling submit to use the chain.
2301 ///
2302 /// see [`ovr_CreateTextureSwapChainDX`](directx/fn.ovr_CreateTextureSwapChainDX.html), [`ovr_CreateTextureSwapChainGL`](opengl/fn.ovr_CreateTextureSwapChainGL.html), [`ovr_CreateTextureSwapChainVk`](opengl/fn.ovr_CreateTextureSwapChainVk.html)
2303 ///
2304 pub fn ovr_CommitTextureSwapChain(session: ovrSession, chain: ovrTextureSwapChain) -> ovrResult;
2305 /// Destroys an `ovrTextureSwapChain` and frees all the resources associated with it.
2306 ///
2307 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
2308 ///
2309 /// `chain` Specifies the `ovrTextureSwapChain` to destroy. If it is NULL then this function has no effect.
2310 ///
2311 /// see [`ovr_CreateTextureSwapChainDX`](directx/fn.ovr_CreateTextureSwapChainDX.html), [`ovr_CreateTextureSwapChainGL`](opengl/fn.ovr_CreateTextureSwapChainGL.html), [`ovr_CreateTextureSwapChainVk`](opengl/fn.ovr_CreateTextureSwapChainVk.html)
2312 ///
2313 pub fn ovr_DestroyTextureSwapChain(session: ovrSession, chain: ovrTextureSwapChain);
2314 /// MirrorTexture creation is rendering API-specific.
2315 ///
2316 /// `ovr_CreateMirrorTextureDX` and `ovr_CreateMirrorTextureGL` can be found in the
2317 /// rendering API-specific headers, such as OVR_CAPI_D3D.h and OVR_CAPI_GL.h
2318
2319 /// Destroys a mirror texture previously created by one of the mirror texture creation functions.
2320 ///
2321 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
2322 ///
2323 /// `mirrorTexture` Specifies the `ovrTexture` to destroy. If it is NULL then this function has no effect.
2324 ///
2325 /// see [`ovr_CreateMirrorTextureDX`](directx/fn.ovr_CreateMirrorTextureDX.html), [`ovr_CreateMirrorTextureGL`](opengl/fn.ovr_CreateMirrorTextureGL.html), [`ovr_CreateMirrorTextureVk`](opengl/fn.ovr_CreateMirrorTextureVk.html)
2326 ///
2327 pub fn ovr_DestroyMirrorTexture(session: ovrSession, mirrorTexture: ovrMirrorTexture);
2328 /// Calculates the recommended viewport size for rendering a given eye within the HMD
2329 /// with a given FOV cone.
2330 ///
2331 /// Higher FOV will generally require larger textures to maintain quality.
2332 ///
2333 /// Apps packing multiple eye views together on the same texture should ensure there are
2334 /// at least 8 pixels of padding between them to prevent texture filtering and chromatic
2335 /// aberration causing images to leak between the two eye views.
2336 ///
2337 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
2338 ///
2339 /// `eye` Specifies which eye (left or right) to calculate for.
2340 ///
2341 /// `fov` Specifies the `ovrFovPort` to use.
2342 ///
2343 /// `pixelsPerDisplayPixel` Specifies the ratio of the number of render target pixels
2344 /// to display pixels at the center of distortion. 1.0 is the default value. Lower
2345 /// values can improve performance, higher values give improved quality.
2346 ///
2347 /// *Example code*
2348 ///
2349 /// ```no_run
2350 /// # use ovr_sys::*;
2351 /// # unsafe {
2352 /// # let session = ::std::mem::zeroed();
2353 /// let hmd_desc = ovr_GetHmdDesc(session);
2354 /// let eye_size_left = ovr_GetFovTextureSize(session, ovrEye_Left, hmd_desc.DefaultEyeFov[ovrEye_Left as usize], 1.0);
2355 /// let eye_size_right = ovr_GetFovTextureSize(session, ovrEye_Right, hmd_desc.DefaultEyeFov[ovrEye_Right as usize], 1.0);
2356 /// # drop((eye_size_left, eye_size_right));
2357 /// # }
2358 /// ```
2359 ///
2360 /// Returns the texture width and height size.
2361 ///
2362 pub fn ovr_GetFovTextureSize(session: ovrSession, eye: ovrEyeType, fov: ovrFovPort, pixelsPerDisplayPixel: f32) -> ovrSizei;
2363 /// Computes the distortion viewport, view adjust, and other rendering parameters for
2364 /// the specified eye.
2365 ///
2366 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
2367 ///
2368 /// `eyeType` Specifies which eye (left or right) for which to perform calculations.
2369 ///
2370 /// `fov` Specifies the `ovrFovPort` to use.
2371 ///
2372 /// Returns the computed `ovrEyeRenderDesc` for the given eyeType and field of view.
2373 ///
2374 /// see [`ovrEyeRenderDesc`](struct.ovrEyeRenderDesc.html)
2375 ///
2376 pub fn ovr_GetRenderDesc(session: ovrSession, eyeType: ovrEyeType, fov: ovrFovPort) -> ovrEyeRenderDesc;
2377 /// Submits layers for distortion and display.
2378 ///
2379 /// `ovr_SubmitFrame` triggers distortion and processing which might happen asynchronously.
2380 ///
2381 /// The function will return when there is room in the submission queue and surfaces
2382 /// are available. Distortion might or might not have completed.
2383 ///
2384 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
2385 ///
2386 /// `frameIndex` Specifies the targeted application frame index, or 0 to refer to one frame
2387 /// after the last time `ovr_SubmitFrame` was called.
2388 ///
2389 /// `viewScaleDesc` Provides additional information needed only if layerPtrList contains
2390 /// an `ovrLayerType_Quad`. If NULL, a default version is used based on the current configuration and a 1.0 world scale.
2391 ///
2392 /// `layerPtrList` Specifies a list of `ovrLayer` pointers, which can include NULL entries to
2393 /// indicate that any previously shown layer at that index is to not be displayed.
2394 ///
2395 /// Each layer header must be a part of a layer structure such as `ovrLayerEyeFov` or `ovrLayerQuad`,
2396 /// with Header.Type identifying its type. A NULL layerPtrList entry in the array indicates the
2397 /// absence of the given layer.
2398 ///
2399 /// `layerCount` Indicates the number of valid elements in layerPtrList. The maximum
2400 /// supported layerCount is not currently specified, but may be specified in a future version.
2401 ///
2402 /// - Layers are drawn in the order they are specified in the array, regardless of the layer type.
2403 ///
2404 /// - Layers are not remembered between successive calls to `ovr_SubmitFrame`. A layer must be
2405 /// specified in every call to `ovr_SubmitFrame` or it won't be displayed.
2406 ///
2407 /// - If a layerPtrList entry that was specified in a previous call to `ovr_SubmitFrame` is
2408 /// passed as NULL or is of type `ovrLayerType_Disabled`, that layer is no longer displayed.
2409 ///
2410 /// - A layerPtrList entry can be of any layer type and multiple entries of the same layer type
2411 /// are allowed. No layerPtrList entry may be duplicated (i.e. the same pointer as an earlier entry).
2412 ///
2413 /// *Example code*
2414 ///
2415 /// ```no_run
2416 /// # use ovr_sys::*;
2417 /// # use ::std::ptr;
2418 /// # unsafe {
2419 /// # fn foo() -> ovrLayerEyeFov { panic!() }
2420 /// # fn bar() -> ovrLayerQuad { panic!() }
2421 /// # let (session, frame_index) = ::std::mem::zeroed();
2422 /// // In initialisation
2423 /// let layer0: ovrLayerEyeFov = foo();
2424 /// let layer1: ovrLayerQuad = bar();
2425 /// // In frame loop
2426 /// let layers = [&layer0.Header as *const _, &layer1.Header as *const _];
2427 /// let result = ovr_SubmitFrame(session, frame_index, ptr::null(), layers.as_ptr(), 2);
2428 /// # drop(result);
2429 /// # }
2430 /// ```
2431 ///
2432 /// Returns an `ovrResult` for which `OVR_SUCCESS(result)` is false upon error and true
2433 /// upon success. Return values include but aren't limited to:
2434 ///
2435 /// * `ovrSuccess`: rendering completed successfully.
2436 /// * `ovrSuccess_NotVisible`: rendering completed successfully but was not displayed on the HMD,
2437 /// usually because another application currently has ownership of the HMD. Applications receiving
2438 /// this result should stop rendering new content, but continue to call `ovr_SubmitFrame` periodically
2439 /// until it returns a value other than `ovrSuccess_NotVisible`.
2440 /// * `ovrError_DisplayLost`: The session has become invalid (such as due to a device removal)
2441 /// and the shared resources need to be released (`ovr_DestroyTextureSwapChain`), the session needs to
2442 /// destroyed (`ovr_Destroy`) and recreated (`ovr_Create`), and new resources need to be created
2443 /// (`ovr_CreateTextureSwapChainXXX`). The application's existing private graphics resources do not
2444 /// need to be recreated unless the new `ovr_Create` call returns a different GraphicsLuid.
2445 /// * `ovrError_TextureSwapChainInvalid`: The `ovrTextureSwapChain` is in an incomplete or inconsistent state.
2446 /// Ensure `ovr_CommitTextureSwapChain` was called at least once first.
2447 ///
2448 /// see [`ovr_GetPredictedDisplayTime`](fn.ovr_GetPredictedDisplayTime.html), [`ovrViewScaleDesc`](struct.ovrViewScaleDesc.html), [`ovrLayerHeader`](struct.ovrLayerHeader.html)
2449 ///
2450 pub fn ovr_SubmitFrame(session: ovrSession, frameIndex: c_longlong, viewScaleDesc: *const ovrViewScaleDesc, layerPtrList: *const *const ovrLayerHeader, layerCount: c_uint) -> ovrResult;
2451
2452}
2453
2454//-------------------------------------------------------------------------------------
2455// @name Frame Timing
2456//
2457//@{
2458
2459///
2460/// Contains the performance stats for a given SDK compositor frame
2461///
2462/// All of the c_int fields can be reset via the `ovr_ResetPerfStats` call.
2463///
2464#[repr(C)]
2465#[derive(Debug, Copy, Clone)]
2466pub struct ovrPerfStatsPerCompositorFrame {
2467 pub _align: [u32; 0],
2468 ///
2469 /// Vsync Frame Index - increments with each HMD vertical synchronization signal (i.e. vsync or refresh rate)
2470 /// If the compositor drops a frame, expect this value to increment more than 1 at a time.
2471 ///
2472 pub HmdVsyncIndex: c_int,
2473
2474 ///
2475 /// Application stats
2476 ///
2477
2478 /// Index that increments with each successive `ovr_SubmitFrame` call
2479 pub AppFrameIndex: c_int,
2480
2481 /// If the app fails to call `ovr_SubmitFrame` on time, then expect this value to increment with each missed frame
2482 pub AppDroppedFrameCount: c_int,
2483
2484 /// Motion-to-photon latency for the application
2485 /// This value is calculated by either using the SensorSampleTime provided for the `ovrLayerEyeFov` or if that
2486 /// is not available, then the call to `ovr_GetTrackingState` which has latencyMarker set to `ovrTrue`
2487 pub AppMotionToPhotonLatency: f32,
2488
2489 /// Amount of queue-ahead in seconds provided to the app based on performance and overlap of CPU & GPU utilization
2490 /// A value of 0.0 would mean the CPU & GPU workload is being completed in 1 frame's worth of time, while
2491 /// 11 ms (on the CV1) of queue ahead would indicate that the app's CPU workload for the next frame is
2492 /// overlapping the app's GPU workload for the current frame.
2493 pub AppQueueAheadTime: f32,
2494
2495 /// Amount of time in seconds spent on the CPU by the app's render-thread that calls `ovr_SubmitFrame`
2496 /// Measured as elapsed time between from when app regains control from `ovr_SubmitFrame` to the next time the app
2497 /// calls `ovr_SubmitFrame`.
2498 pub AppCpuElapsedTime: f32,
2499
2500 /// Amount of time in seconds spent on the GPU by the app
2501 /// Measured as elapsed time between each `ovr_SubmitFrame` call using GPU timing queries.
2502 pub AppGpuElapsedTime: f32,
2503
2504 ///
2505 /// SDK Compositor stats
2506 ///
2507
2508 /// Index that increments each time the SDK compositor completes a distortion and timewarp pass
2509 /// Since the compositor operates asynchronously, even if the app calls `ovr_SubmitFrame` too late,
2510 /// the compositor will kick off for each vsync.
2511 pub CompositorFrameIndex: c_int,
2512
2513 /// Increments each time the SDK compositor fails to complete in time
2514 /// This is not tied to the app's performance, but failure to complete can be tied to other factors
2515 /// such as OS capabilities, overall available hardware cycles to execute the compositor in time
2516 /// and other factors outside of the app's control.
2517 pub CompositorDroppedFrameCount: c_int,
2518
2519 /// Motion-to-photon latency of the SDK compositor in seconds
2520 /// This is the latency of timewarp which corrects the higher app latency as well as dropped app frames.
2521 pub CompositorLatency: f32,
2522
2523 /// The amount of time in seconds spent on the CPU by the SDK compositor. Unless the VR app is utilizing
2524 /// all of the CPU cores at their peak performance, there is a good chance the compositor CPU times
2525 /// will not affect the app's CPU performance in a major way.
2526 pub CompositorCpuElapsedTime: f32,
2527
2528 /// The amount of time in seconds spent on the GPU by the SDK compositor. Any time spent on the compositor
2529 /// will eat away from the available GPU time for the app.
2530 pub CompositorGpuElapsedTime: f32,
2531
2532 /// The amount of time in seconds spent from the point the CPU kicks off the compositor to the point in time
2533 /// the compositor completes the distortion & timewarp on the GPU. In the event the GPU time is not
2534 /// available, expect this value to be -1.0f
2535 pub CompositorCpuStartToGpuEndElapsedTime: f32,
2536
2537 /// The amount of time in seconds left after the compositor is done on the GPU to the associated V-Sync time.
2538 ///
2539 /// In the event the GPU time is not available, expect this value to be -1.0f
2540 pub CompositorGpuEndToVsyncElapsedTime: f32,
2541
2542 ///
2543 /// Async Spacewarp stats (ASW)
2544 ///
2545
2546 /// Will be true if ASW is active for the given frame such that the application is being forced
2547 /// into half the frame-rate while the compositor continues to run at full frame-rate.
2548 pub AswIsActive: ovrBool,
2549
2550 /// Increments each time ASW it activated where the app was forced in and out of
2551 /// half-rate rendering.
2552 pub AswActivatedToggleCount: c_int,
2553
2554 /// Accumulates the number of frames presented by the compositor which had extrapolated
2555 /// ASW frames presented.
2556 pub AswPresentedFrameCount: c_int,
2557
2558 /// Accumulates the number of frames that the compositor tried to present when ASW is
2559 /// active but failed.
2560 pub AswFailedFrameCount: c_int,
2561}
2562
2563///
2564/// Maximum number of frames of performance stats provided back to the caller of `ovr_GetPerfStats`
2565///
2566///
2567pub const ovrMaxProvidedFrameStats: u32 = 5;
2568/// This is a complete descriptor of the performance stats provided by the SDK
2569///
2570/// FrameStatsCount will have a maximum value set by `ovrMaxProvidedFrameStats`
2571/// If the application calls `ovr_GetPerfStats` at the native refresh rate of the HMD
2572/// then FrameStatsCount will be 1. If the app's workload happens to force
2573/// `ovr_GetPerfStats` to be called at a lower rate, then FrameStatsCount will be 2 or more.
2574///
2575/// If the app does not want to miss any performance data for any frame, it needs to
2576/// ensure that it is calling `ovr_SubmitFrame` and `ovr_GetPerfStats` at a rate that is at least:
2577/// "HMD_refresh_rate / `ovrMaxProvidedFrameStats`". On the Oculus Rift CV1 HMD, this will
2578/// be equal to 18 times per second.
2579///
2580/// If the app calls `ovr_SubmitFrame` at a rate less than 18 fps, then when calling
2581/// `ovr_GetPerfStats`, expect AnyFrameStatsDropped to become `ovrTrue` while FrameStatsCount
2582/// is equal to `ovrMaxProvidedFrameStats`.
2583///
2584/// The performance entries will be ordered in reverse chronological order such that the
2585/// first entry will be the most recent one.
2586///
2587/// AdaptiveGpuPerformanceScale is an edge-filtered value that a caller can use to adjust
2588/// the graphics quality of the application to keep the GPU utilization in check. The value
2589/// is calculated as: (desired_GPU_utilization / current_GPU_utilization)
2590/// As such, when this value is 1.0, the GPU is doing the right amount of work for the app.
2591///
2592/// Lower values mean the app needs to pull back on the GPU utilization.
2593///
2594/// If the app is going to directly drive render-target resolution using this value, then
2595/// be sure to take the square-root of the value before scaling the resolution with it.
2596///
2597/// Changing render target resolutions however is one of the many things an app can do
2598/// increase or decrease the amount of GPU utilization.
2599///
2600/// Since AdaptiveGpuPerformanceScale is edge-filtered and does not change rapidly
2601/// (i.e. reports non-1.0 values once every couple of seconds) the app can make the
2602/// necessary adjustments and then keep watching the value to see if it has been satisfied.
2603///
2604/// see [`ovr_GetPerfStats`](fn.ovr_GetPerfStats.html), [`ovrPerfStatsPerCompositorFrame`](struct.ovrPerfStatsPerCompositorFrame.html)
2605#[repr(C)]
2606#[derive(Debug, Copy, Clone)]
2607pub struct ovrPerfStats {
2608 pub _align: [u32; 0],
2609 /// `FrameStatsCount` will have a maximum value set by `ovrMaxProvidedFrameStats`
2610 /// If the application calls `ovr_GetPerfStats` at the native refresh rate of the HMD
2611 /// then `FrameStatsCount` will be 1. If the app's workload happens to force
2612 /// `ovr_GetPerfStats` to be called at a lower rate, then `FrameStatsCount` will be 2 or more.
2613 /// If the app does not want to miss any performance data for any frame, it needs to
2614 /// ensure that it is calling `ovr_SubmitFrame` and `ovr_GetPerfStats` at a rate that is at least:
2615 /// "HMD_refresh_rate / ovrMaxProvidedFrameStats". On the Oculus Rift CV1 HMD, this will
2616 /// be equal to 18 times per second.
2617 ///
2618 /// The performance entries will be ordered in reverse chronological order such that the
2619 /// first entry will be the most recent one.
2620 pub FrameStats: [ovrPerfStatsPerCompositorFrame; ovrMaxProvidedFrameStats as usize],
2621 pub FrameStatsCount: c_int,
2622 /// If the app calls `ovr_GetPerfStats` at less than 18 fps for CV1, then `AnyFrameStatsDropped`
2623 /// will be `ovrTrue` and `FrameStatsCount` will be equal to `ovrMaxProvidedFrameStats`.
2624 pub AnyFrameStatsDropped: ovrBool,
2625 /// `AdaptiveGpuPerformanceScale` is an edge-filtered value that a caller can use to adjust
2626 /// the graphics quality of the application to keep the GPU utilization in check. The value
2627 /// is calculated as: (desired_GPU_utilization / current_GPU_utilization)
2628 /// As such, when this value is 1.0, the GPU is doing the right amount of work for the app.
2629 /// Lower values mean the app needs to pull back on the GPU utilization.
2630 /// If the app is going to directly drive render-target resolution using this value, then
2631 /// be sure to take the square-root of the value before scaling the resolution with it.
2632 /// Changing render target resolutions however is one of the many things an app can do
2633 /// increase or decrease the amount of GPU utilization.
2634 /// Since `AdaptiveGpuPerformanceScale` is edge-filtered and does not change rapidly
2635 /// (i.e. reports non-1.0 values once every couple of seconds) the app can make the
2636 /// necessary adjustments and then keep watching the value to see if it has been satisfied.
2637 pub AdaptiveGpuPerformanceScale: f32,
2638
2639 /// Will be true if Async Spacewarp (ASW) is available for this system which is dependent on
2640 /// several factors such as choice of GPU, OS and debug overrides
2641 pub AswIsAvailable: ovrBool,
2642
2643 /// Contains the Process ID of the VR application the stats are being polled for
2644 /// If an app continues to grab perf stats even when it is not visible, then expect this
2645 /// value to point to the other VR app that has grabbed focus (i.e. became visible)
2646 pub VisibleProcessId: ovrProcessId,
2647}
2648
2649extern "C" {
2650
2651 /// Retrieves performance stats for the VR app as well as the SDK compositor.
2652 ///
2653 /// This function will return stats for the VR app that is currently visible in the HMD
2654 /// regardless of what VR app is actually calling this function.
2655 ///
2656 /// If the VR app is trying to make sure the stats returned belong to the same application,
2657 /// the caller can compare the `VisibleProcessId` with their own process ID. Normally this will
2658 /// be the case if the caller is only calling `ovr_GetPerfStats` when `ovr_GetSessionStatus` has
2659 /// IsVisible flag set to be true.
2660 ///
2661 /// If the VR app calling `ovr_GetPerfStats` is actually the one visible in the HMD,
2662 /// then new perf stats will only be populated after a new call to `ovr_SubmitFrame`.
2663 /// That means subsequent calls to `ovr_GetPerfStats` after the first one without calling
2664 /// `ovr_SubmitFrame` will receive a `FrameStatsCount` of zero.
2665 ///
2666 /// If the VR app is not visible, or was initially marked as `ovrInit_Invisible`, then each call
2667 /// to `ovr_GetPerfStats` will immediately fetch new perf stats from the compositor without
2668 /// a need for the `ovr_SubmitFrame` call.
2669 ///
2670 /// **in** `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
2671 ///
2672 /// **out** `outStats` Contains the performance stats for the application and SDK compositor
2673 ///
2674 /// Returns an `ovrResult` for which `OVR_SUCCESS(result)` is false upon error and true
2675 /// upon success.
2676 ///
2677 /// see [`ovrPerfStats`](struct.ovrPerfStats.html), [`ovrPerfStatsPerCompositorFrame`](struct.ovrPerfStatsPerCompositorFrame.html), [`ovr_ResetPerfStats`](fn.ovr_ResetPerfStats.html)
2678 ///
2679 pub fn ovr_GetPerfStats(session: ovrSession, outStats: *mut ovrPerfStats) -> ovrResult;
2680 /// Resets the accumulated stats reported in each `ovrPerfStatsPerCompositorFrame` back to zero.
2681 ///
2682 /// Only the integer values such as HmdVsyncIndex, AppDroppedFrameCount etc. will be reset
2683 /// as the other fields such as AppMotionToPhotonLatency are independent timing values updated
2684 /// per-frame.
2685 ///
2686 /// **in** `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
2687 ///
2688 /// Returns an `ovrResult` for which `OVR_SUCCESS(result)` is false upon error and true
2689 /// upon success.
2690 ///
2691 /// see [`ovrPerfStats`](struct.ovrPerfStats.html), [`ovrPerfStatsPerCompositorFrame`](struct.ovrPerfStatsPerCompositorFrame.html), [`ovr_GetPerfStats`](fn.ovr_GetPerfStats.html)
2692 ///
2693 pub fn ovr_ResetPerfStats(session: ovrSession) -> ovrResult;
2694 /// Gets the time of the specified frame midpoint.
2695 ///
2696 /// Predicts the time at which the given frame will be displayed. The predicted time
2697 /// is the middle of the time period during which the corresponding eye images will
2698 /// be displayed.
2699 ///
2700 /// The application should increment frameIndex for each successively targeted frame,
2701 /// and pass that index to any relevant OVR functions that need to apply to the frame
2702 /// identified by that index.
2703 ///
2704 /// This function is thread-safe and allows for multiple application threads to target
2705 /// their processing to the same displayed frame.
2706 ///
2707 /// In the even that prediction fails due to various reasons (e.g. the display being off
2708 /// or app has yet to present any frames), the return value will be current CPU time.
2709 ///
2710 /// **in** `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
2711 ///
2712 /// **in** `frameIndex` Identifies the frame the caller wishes to target.
2713 /// A value of zero returns the next frame index.
2714 ///
2715 /// Returns the absolute frame midpoint time for the given frameIndex.
2716 ///
2717 /// see [`ovr_GetTimeInSeconds`](fn.ovr_GetTimeInSeconds.html)
2718 ///
2719 pub fn ovr_GetPredictedDisplayTime(session: ovrSession, frameIndex: c_longlong) -> f64;
2720 /// Returns global, absolute high-resolution time in seconds.
2721 ///
2722 /// The time frame of reference for this function is not specified and should not be
2723 /// depended upon.
2724 ///
2725 /// Returns seconds as a floating point value.
2726 ///
2727 /// see [`ovrPoseStatef`](struct.ovrPoseStatef.html), `ovrFrameTiming`
2728 ///
2729 pub fn ovr_GetTimeInSeconds() -> f64;
2730
2731}
2732
2733/// Performance HUD enables the HMD user to see information critical to
2734/// the real-time operation of the VR application such as latency timing,
2735/// and CPU & GPU performance metrics
2736///
2737/// App can toggle performance HUD modes as such:
2738///
2739/// ```no_run
2740/// # use ovr_sys::*;
2741/// # use ::std::ffi::CStr;
2742/// # unsafe {
2743/// # let session = ::std::mem::zeroed();
2744/// let perf_hud_mode = ovrPerfHud_LatencyTiming;
2745/// ovr_SetInt(session, CStr::from_bytes_with_nul_unchecked(OVR_PERF_HUD_MODE).as_ptr(), perf_hud_mode);
2746/// # }
2747/// ```
2748///
2749pub type ovrPerfHudMode = i32;
2750/// Turns off the performance HUD
2751pub const ovrPerfHud_Off: ovrPerfHudMode = 0;
2752/// Shows performance summary and headroom
2753pub const ovrPerfHud_PerfSummary: ovrPerfHudMode = 1;
2754/// Shows latency related timing info
2755pub const ovrPerfHud_LatencyTiming: ovrPerfHudMode = 2;
2756/// Shows render timing info for application
2757pub const ovrPerfHud_AppRenderTiming: ovrPerfHudMode = 3;
2758/// Shows render timing info for OVR compositor
2759pub const ovrPerfHud_CompRenderTiming: ovrPerfHudMode = 4;
2760/// Shows SDK & HMD version Info
2761pub const ovrPerfHud_VersionInfo: ovrPerfHudMode = 5;
2762/// \internal Count of enumerated elements.
2763#[doc(hidden)]
2764pub const ovrPerfHud_Count: ovrPerfHudMode = 6;
2765/// Layer HUD enables the HMD user to see information about a layer
2766///
2767/// App can toggle layer HUD modes as such:
2768///
2769/// ```no_run
2770/// # use ovr_sys::*;
2771/// # use ::std::ffi::CStr;
2772/// # unsafe {
2773/// # let session = ::std::mem::zeroed();
2774/// let layer_hud_mode = ovrLayerHud_Info;
2775/// ovr_SetInt(session, CStr::from_bytes_with_nul_unchecked(OVR_LAYER_HUD_MODE).as_ptr(), layer_hud_mode);
2776/// # }
2777/// ```
2778///
2779pub type ovrLayerHudMode = i32;
2780/// Turns off the layer HUD
2781pub const ovrLayerHud_Off: ovrLayerHudMode = 0;
2782/// Shows info about a specific layer
2783pub const ovrLayerHud_Info: ovrLayerHudMode = 1;
2784//@}
2785
2786/// Debug HUD is provided to help developers gauge and debug the fidelity of their app's
2787/// stereo rendering characteristics. Using the provided quad and crosshair guides,
2788/// the developer can verify various aspects such as VR tracking units (e.g. meters),
2789/// stereo camera-parallax properties (e.g. making sure objects at infinity are rendered
2790/// with the proper separation), measuring VR geometry sizes and distances and more.
2791///
2792/// App can toggle the debug HUD modes as such:
2793///
2794/// ```no_run
2795/// # use ovr_sys::*;
2796/// # use ::std::ffi::CStr;
2797/// # unsafe {
2798/// # let session = ::std::mem::zeroed();
2799/// let debug_hud_mode = ovrDebugHudStereo_QuadWithCrosshair;
2800/// ovr_SetInt(session, CStr::from_bytes_with_nul_unchecked(OVR_DEBUG_HUD_STEREO_MODE).as_ptr(), debug_hud_mode);
2801/// # }
2802/// ```
2803///
2804/// The app can modify the visual properties of the stereo guide (i.e. quad, crosshair)
2805/// using the `ovr_SetFloatArray` function. For a list of tweakable properties,
2806/// see the `OVR_DEBUG_HUD_STEREO_GUIDE_*` keys in the OVR_CAPI_Keys.h header file.
2807pub type ovrDebugHudStereoMode = i32;
2808/// Turns off the Stereo Debug HUD
2809pub const ovrDebugHudStereo_Off: ovrDebugHudStereoMode = 0;
2810/// Renders Quad in world for Stereo Debugging
2811pub const ovrDebugHudStereo_Quad: ovrDebugHudStereoMode = 1;
2812/// Renders Quad+crosshair in world for Stereo Debugging
2813pub const ovrDebugHudStereo_QuadWithCrosshair: ovrDebugHudStereoMode = 2;
2814/// Renders screen-space crosshair at infinity for Stereo Debugging
2815pub const ovrDebugHudStereo_CrosshairAtInfinity: ovrDebugHudStereoMode = 3;
2816/// \internal Count of enumerated elements
2817#[doc(hidden)]
2818pub const ovrDebugHudStereo_Count: ovrDebugHudStereoMode = 4;
2819
2820// -----------------------------------------------------------------------------------
2821// @name Property Access
2822//
2823// These functions read and write OVR properties. Supported properties
2824// are defined in `OVR_CAPI_Keys`.h
2825//
2826extern "C" {
2827
2828 /// Reads a boolean property.
2829 ///
2830 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
2831 ///
2832 /// `propertyName` The name of the property, which needs to be valid for only the call.
2833 ///
2834 /// `defaultVal` specifes the value to return if the property couldn't be read.
2835 ///
2836 /// Returns the property interpreted as a boolean value. Returns defaultVal if
2837 /// the property doesn't exist.
2838 pub fn ovr_GetBool(session: ovrSession, propertyName: *const c_char, defaultVal: ovrBool) -> ovrBool;
2839 /// Writes or creates a boolean property.
2840 ///
2841 /// If the property wasn't previously a boolean property, it is changed to a boolean property.
2842 ///
2843 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
2844 ///
2845 /// `propertyName` The name of the property, which needs to be valid only for the call.
2846 ///
2847 /// `value` The value to write.
2848 ///
2849 /// Returns true if successful, otherwise false. A false result should only occur if the property
2850 /// name is empty or if the property is read-only.
2851 pub fn ovr_SetBool(session: ovrSession, propertyName: *const c_char, value: ovrBool) -> ovrBool;
2852 /// Reads an integer property.
2853 ///
2854 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
2855 ///
2856 /// `propertyName` The name of the property, which needs to be valid only for the call.
2857 ///
2858 /// `defaultVal` Specifes the value to return if the property couldn't be read.
2859 ///
2860 /// Returns the property interpreted as an integer value. Returns defaultVal if
2861 /// the property doesn't exist.
2862 pub fn ovr_GetInt(session: ovrSession, propertyName: *const c_char, defaultVal: c_int) -> c_int;
2863 /// Writes or creates an integer property.
2864 ///
2865 /// If the property wasn't previously a boolean property, it is changed to an integer property.
2866 ///
2867 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
2868 ///
2869 /// `propertyName` The name of the property, which needs to be valid only for the call.
2870 ///
2871 /// `value` The value to write.
2872 ///
2873 /// Returns true if successful, otherwise false. A false result should only occur if the property
2874 /// name is empty or if the property is read-only.
2875 pub fn ovr_SetInt(session: ovrSession, propertyName: *const c_char, value: c_int) -> ovrBool;
2876 /// Reads a `f32` property.
2877 ///
2878 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
2879 ///
2880 /// `propertyName` The name of the property, which needs to be valid only for the call.
2881 ///
2882 /// `defaultVal` specifes the value to return if the property couldn't be read.
2883 ///
2884 /// Returns the property interpreted as an `f32` value. Returns defaultVal if
2885 /// the property doesn't exist.
2886 pub fn ovr_GetFloat(session: ovrSession, propertyName: *const c_char, defaultVal: f32) -> f32;
2887 /// Writes or creates a `f32` property.
2888 ///
2889 /// If the property wasn't previously a `f32` property, it's changed to a `f32` property.
2890 ///
2891 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
2892 ///
2893 /// `propertyName` The name of the property, which needs to be valid only for the call.
2894 ///
2895 /// `value` The value to write.
2896 ///
2897 /// Returns true if successful, otherwise false. A false result should only occur if the property
2898 /// name is empty or if the property is read-only.
2899 pub fn ovr_SetFloat(session: ovrSession, propertyName: *const c_char, value: f32) -> ovrBool;
2900 /// Reads a `f32` array property.
2901 ///
2902 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
2903 ///
2904 /// `propertyName` The name of the property, which needs to be valid only for the call.
2905 ///
2906 /// `values` An array of `f32` to write to.
2907 ///
2908 /// `valuesCapacity` Specifies the maximum number of elements to write to the values array.
2909 ///
2910 /// Returns the number of elements read, or 0 if property doesn't exist or is empty.
2911 pub fn ovr_GetFloatArray(session: ovrSession, propertyName: *const c_char, values: *mut f32, valuesCapacity: c_uint) -> c_uint;
2912 /// Writes or creates a `f32` array property.
2913 ///
2914 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
2915 ///
2916 /// `propertyName` The name of the property, which needs to be valid only for the call.
2917 ///
2918 /// `values` An array of `f32` to write from.
2919 ///
2920 /// `valuesSize` Specifies the number of elements to write.
2921 ///
2922 /// Returns true if successful, otherwise false. A false result should only occur if the property
2923 /// name is empty or if the property is read-only.
2924 pub fn ovr_SetFloatArray(session: ovrSession, propertyName: *const c_char, values: *const f32, valuesSize: c_uint) -> ovrBool;
2925 /// Reads a string property.
2926 ///
2927 /// Strings are UTF8-encoded and null-terminated.
2928 ///
2929 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
2930 ///
2931 /// `propertyName` The name of the property, which needs to be valid only for the call.
2932 ///
2933 /// `defaultVal` Specifes the value to return if the property couldn't be read.
2934 ///
2935 /// Returns the string property if it exists. Otherwise returns defaultVal, which can be specified as NULL.
2936 ///
2937 /// The return memory is guaranteed to be valid until next call to `ovr_GetString` or
2938 /// until the session is destroyed, whichever occurs first.
2939 pub fn ovr_GetString(session: ovrSession, propertyName: *const c_char, defaultVal: *const c_char) -> *const c_char;
2940 /// Writes or creates a string property.
2941 ///
2942 /// Strings are UTF8-encoded and null-terminated.
2943 ///
2944 /// `session` Specifies an `ovrSession` previously returned by `ovr_Create`.
2945 ///
2946 /// `propertyName` The name of the property, which needs to be valid only for the call.
2947 ///
2948 /// `value` The string property, which only needs to be valid for the duration of the call.
2949 ///
2950 /// Returns true if successful, otherwise false. A false result should only occur if the property
2951 /// name is empty or if the property is read-only.
2952 pub fn ovr_SetString(session: ovrSession, propertyName: *const c_char, value: *const c_char) -> ovrBool;
2953
2954} // extern "C"
2955
2956
2957
2958#[cfg(test)]
2959#[test]
2960pub fn test() {
2961 use ::std::mem::size_of;
2962 //-----------------------------------------------------------------------------
2963 // ***** Compiler packing validation
2964 //
2965 // These checks ensure that the compiler settings being used will be compatible
2966 // with with pre-built dynamic library provided with the runtime.
2967
2968 assert!(size_of::<ovrBool>() == 1, "ovrBool size mismatch");
2969 assert!(size_of::<ovrVector2i>() == 4 * 2, "ovrVector2i size mismatch");
2970 assert!(size_of::<ovrSizei>() == 4 * 2, "ovrSizei size mismatch");
2971 assert!(size_of::<ovrRecti>() == size_of::<ovrVector2i>() + size_of::<ovrSizei>(), "ovrRecti size mismatch");
2972 assert!(size_of::<ovrQuatf>() == 4 * 4, "ovrQuatf size mismatch");
2973 assert!(size_of::<ovrVector2f>() == 4 * 2, "ovrVector2f size mismatch");
2974 assert!(size_of::<ovrVector3f>() == 4 * 3, "ovrVector3f size mismatch");
2975 assert!(size_of::<ovrMatrix4f>() == 4 * 16, "ovrMatrix4f size mismatch");
2976
2977 assert!(size_of::<ovrPosef>() == (7 * 4), "ovrPosef size mismatch");
2978 assert!(size_of::<ovrPoseStatef>() == (22 * 4), "ovrPoseStatef size mismatch");
2979 assert!(size_of::<ovrFovPort>() == (4 * 4), "ovrFovPort size mismatch");
2980
2981 assert!(size_of::<ovrHmdCaps>() == 4, "ovrHmdCaps size mismatch");
2982 assert!(size_of::<ovrTrackingCaps>() == 4, "ovrTrackingCaps size mismatch");
2983 assert!(size_of::<ovrEyeType>() == 4, "ovrEyeType size mismatch");
2984 assert!(size_of::<ovrHmdType>() == 4, "ovrHmdType size mismatch");
2985
2986 assert!(size_of::<ovrTrackerDesc>() == 4 + 4 + 4 + 4, "ovrTrackerDesc size mismatch");
2987 assert!(size_of::<ovrTrackerPose>() == 4 + 4 + size_of::<ovrPosef>() + size_of::<ovrPosef>(), "ovrTrackerPose size mismatch");
2988 assert!(size_of::<ovrTrackingState>() == size_of::<ovrPoseStatef>() + 4 + 4 + (size_of::<ovrPoseStatef>() * 2) + (size_of::<c_uint>() * 2) + size_of::<ovrPosef>() + 4, "ovrTrackingState size mismatch");
2989
2990
2991 //assert!(size_of::<ovrTextureHeader>() == size_of::<ovrRenderAPIType>() + size_of::<ovrSizei>(),
2992 // "ovrTextureHeader size mismatch");
2993 //assert!(size_of::<ovrTexture>() == size_of::<ovrTextureHeader>() OVR_ON64(+4) + size_of::<usize>() * 8,
2994 // "ovrTexture size mismatch");
2995 //
2996 assert!(size_of::<ovrStatusBits>() == 4, "ovrStatusBits size mismatch");
2997
2998 assert!(size_of::<ovrSessionStatus>() == 6, "ovrSessionStatus size mismatch");
2999
3000 assert!(size_of::<ovrEyeRenderDesc>() == size_of::<ovrEyeType>() + size_of::<ovrFovPort>() + size_of::<ovrRecti>() +
3001 size_of::<ovrVector2f>() + size_of::<ovrVector3f>(),
3002 "ovrEyeRenderDesc size mismatch");
3003 assert!(size_of::<ovrTimewarpProjectionDesc>() == 4 * 3, "ovrTimewarpProjectionDesc size mismatch");
3004
3005 assert!(size_of::<ovrInitFlags>() == 4, "ovrInitFlags size mismatch");
3006 assert!(size_of::<ovrLogLevel>() == 4, "ovrLogLevel size mismatch");
3007
3008 assert!(size_of::<ovrInitParams>() == 4 + 4 + size_of::<ovrLogCallback>() + size_of::<usize>() + 4 + 4,
3009 "ovrInitParams size mismatch");
3010
3011 if cfg!(target_pointer_width = "32") {
3012 assert!(size_of::<ovrHmdDesc>() ==
3013 size_of::<ovrHmdType>() // Type
3014 + 64 // ProductName
3015 + 64 // Manufacturer
3016 + 2 // VendorId
3017 + 2 // ProductId
3018 + 24 // SerialNumber
3019 + 2 // FirmwareMajor
3020 + 2 // FirmwareMinor
3021 + 4 * 4 // AvailableHmdCaps - DefaultTrackingCaps
3022 + size_of::<ovrFovPort>() * 2 // DefaultEyeFov
3023 + size_of::<ovrFovPort>() * 2 // MaxEyeFov
3024 + size_of::<ovrSizei>() // Resolution
3025 + 4 // DisplayRefreshRate
3026 , "ovrHmdDesc size mismatch");
3027 } else {
3028 assert!(size_of::<ovrHmdDesc>() ==
3029 size_of::<ovrHmdType>() // Type
3030 + 4 // pad0
3031 + 64 // ProductName
3032 + 64 // Manufacturer
3033 + 2 // VendorId
3034 + 2 // ProductId
3035 + 24 // SerialNumber
3036 + 2 // FirmwareMajor
3037 + 2 // FirmwareMinor
3038 + 4 * 4 // AvailableHmdCaps - DefaultTrackingCaps
3039 + size_of::<ovrFovPort>() * 2 // DefaultEyeFov
3040 + size_of::<ovrFovPort>() * 2 // MaxEyeFov
3041 + size_of::<ovrSizei>() // Resolution
3042 + 4 // DisplayRefreshRate
3043 + 4 // pad1
3044 , "ovrHmdDesc size mismatch");
3045 }
3046}
3047
3048/// Enumerates modifications to the projection matrix based on the application's needs.
3049///
3050/// see [`ovrMatrix4f_Projection`](struct.ovrMatrix4f_Projection.html)
3051///
3052pub type ovrProjectionModifier = i32;
3053/// Use for generating a default projection matrix that is:
3054///
3055/// * Right-handed.
3056/// * Near depth values stored in the depth buffer are smaller than far depth values.
3057/// * Both near and far are explicitly defined.
3058/// * With a clipping range that is (0 to w).
3059///
3060pub const ovrProjection_None: ovrProjectionModifier = 0x00;
3061
3062/// Enable if using left-handed transformations in your application.
3063pub const ovrProjection_LeftHanded: ovrProjectionModifier = 0x01;
3064
3065/// After the projection transform is applied, far values stored in the depth buffer will be less than closer depth values.
3066/// NOTE: Enable only if the application is using a floating-point depth buffer for proper precision.
3067pub const ovrProjection_FarLessThanNear: ovrProjectionModifier = 0x02;
3068
3069/// When this flag is used, the zfar value pushed into `ovrMatrix4f_Projection()` will be ignored
3070/// NOTE: Enable only if `ovrProjection_FarLessThanNear` is also enabled where the far clipping plane will be pushed to infinity.
3071pub const ovrProjection_FarClipAtInfinity: ovrProjectionModifier = 0x04;
3072
3073/// Enable if the application is rendering with OpenGL and expects a projection matrix with a clipping range of (-w to w).
3074/// Ignore this flag if your application already handles the conversion from D3D range (0 to w) to OpenGL.
3075pub const ovrProjection_ClipRangeOpenGL: ovrProjectionModifier = 0x08;
3076
3077/// Return values for `ovr_Detect`.
3078///
3079/// see [`ovr_Detect`](fn.ovr_Detect.html)
3080///
3081#[repr(C)]
3082#[derive(Copy, Clone, Debug)]
3083pub struct ovrDetectResult {
3084 pub _align: [u64; 0],
3085 /// Is `ovrFalse` when the Oculus Service is not running.
3086 /// This means that the Oculus Service is either uninstalled or stopped.
3087 /// `IsOculusHMDConnected` will be `ovrFalse` in this case.
3088 ///
3089 /// Is `ovrTrue` when the Oculus Service is running.
3090 /// This means that the Oculus Service is installed and running.
3091 /// `IsOculusHMDConnected` will reflect the state of the HMD.
3092 pub IsOculusServiceRunning: ovrBool,
3093
3094 /// Is `ovrFalse` when an Oculus HMD is not detected.
3095 /// If the Oculus Service is not running, this will be `ovrFalse`.
3096 ///
3097 /// Is `ovrTrue` when an Oculus HMD is detected.
3098 /// This implies that the Oculus Service is also installed and running.
3099 pub IsOculusHMDConnected: ovrBool,
3100 /// \internal struct pad.
3101 pub _pad0: [u8; 6],
3102}
3103
3104#[cfg(test)]
3105#[test]
3106fn test_detect_result() {
3107 assert!(::std::mem::size_of::<ovrDetectResult>() == 8, "ovrDetectResult size mismatch");
3108}
3109
3110extern "C" {
3111 /// Detects Oculus Runtime and Device Status
3112 ///
3113 /// Checks for Oculus Runtime and Oculus HMD device status without loading the LibOVRRT
3114 /// shared library. This may be called before `ovr_Initialize()` to help decide whether or
3115 /// not to initialize LibOVR.
3116 ///
3117 /// **in** `timeoutMilliseconds` Specifies a timeout to wait for HMD to be attached or 0 to poll.
3118 ///
3119 /// Returns an `ovrDetectResult` object indicating the result of detection.
3120 ///
3121 /// see [`ovrDetectResult`](struct.ovrDetectResult.html)
3122 ///
3123 pub fn ovr_Detect(timeoutMilliseconds: c_int) -> ovrDetectResult;
3124
3125 /// Used to generate projection from `ovrEyeDesc::Fov`.
3126 ///
3127 /// **in** `fov` Specifies the `ovrFovPort` to use.
3128 ///
3129 /// **in** `znear` Distance to near Z limit.
3130 ///
3131 /// **in** `zfar` Distance to far Z limit.
3132 ///
3133 /// **in** `projectionModFlags` A combination of the `ovrProjectionModifier` flags.
3134 ///
3135 /// Returns the calculated projection matrix.
3136 ///
3137 /// see [`ovrProjectionModifier`](struct.ovrProjectionModifier.html)
3138 ///
3139 pub fn ovrMatrix4f_Projection(fov: ovrFovPort, znear: f32, zfar: f32, projectionModFlags: c_uint) -> ovrMatrix4f;
3140
3141
3142 /// Extracts the required data from the result of `ovrMatrix4f_Projection`.
3143 ///
3144 /// **in** `projection` Specifies the project matrix from which to extract `ovrTimewarpProjectionDesc`.
3145 ///
3146 /// **in** `projectionModFlags` A combination of the `ovrProjectionModifier` flags.
3147 ///
3148 /// Returns the extracted `ovrTimewarpProjectionDesc`.
3149 ///
3150 /// see [`ovrTimewarpProjectionDesc`](struct.ovrTimewarpProjectionDesc.html)
3151 ///
3152 pub fn ovrTimewarpProjectionDesc_FromProjection(projection: ovrMatrix4f, projectionModFlags: c_uint) -> ovrTimewarpProjectionDesc;
3153
3154
3155 /// Generates an orthographic sub-projection.
3156 ///
3157 /// Used for 2D rendering, Y is down.
3158 ///
3159 /// **in** `projection` The perspective matrix that the orthographic matrix is derived from.
3160 ///
3161 /// **in** `orthoScale` Equal to `1.0f / pixelsPerTanAngleAtCenter`.
3162 ///
3163 /// **in** `orthoDistance` Equal to the distance from the camera in meters, such as 0.8m.
3164 ///
3165 /// **in** `HmdToEyeOffsetX` Specifies the offset of the eye from the center.
3166 ///
3167 /// Returns the calculated projection matrix.
3168 ///
3169 pub fn ovrMatrix4f_OrthoSubProjection(projection: ovrMatrix4f, orthoScale: ovrVector2f, orthoDistance: f32, HmdToEyeOffsetX: f32) -> ovrMatrix4f;
3170
3171
3172
3173 /// Computes offset eye poses based on headPose returned by `ovrTrackingState`.
3174 ///
3175 /// **in** `headPose` Indicates the HMD position and orientation to use for the calculation.
3176 ///
3177 /// **in** `hmdToEyeOffset` Can be `ovrEyeRenderDesc.HmdToEyeOffset` returned from
3178 /// `ovr_GetRenderDesc`. For monoscopic rendering, use a vector that is the average
3179 /// of the two vectors for both eyes.
3180 ///
3181 /// **out** `outEyePoses` If `outEyePoses` are used for rendering, they should be passed to
3182 /// `ovr_SubmitFrame` in `ovrLayerEyeFov::RenderPose` or `ovrLayerEyeFovDepth::RenderPose`.
3183 ///
3184 pub fn ovr_CalcEyePoses(headPose: ovrPosef, hmdToEyeOffset: *const [ovrVector3f; 2], outEyePoses: *const [ovrPosef; 2]);
3185
3186
3187 /// Returns the predicted head pose in outHmdTrackingState and offset eye poses in outEyePoses.
3188 ///
3189 /// This is a thread-safe function where caller should increment frameIndex with every frame
3190 /// and pass that index where applicable to functions called on the rendering thread.
3191 /// Assuming outEyePoses are used for rendering, it should be passed as a part of `ovrLayerEyeFov`.
3192 /// The caller does not need to worry about applying `HmdToEyeOffset` to the returned `outEyePoses` variables.
3193 ///
3194 /// **in** `hmd` Specifies an `ovrSession` previously returned by `ovr_Create`.
3195 ///
3196 /// **in** `frameIndex` Specifies the targeted frame index, or 0 to refer to one frame after
3197 /// the last time `ovr_SubmitFrame` was called.
3198 ///
3199 /// **in** `latencyMarker` Specifies that this call is the point in time where
3200 /// the "App-to-Mid-Photon" latency timer starts from. If a given `ovrLayer`
3201 /// provides "SensorSampleTimestamp", that will override the value stored here.
3202 ///
3203 /// **in** `hmdToEyeOffset` Can be `ovrEyeRenderDesc.HmdToEyeOffset` returned from
3204 /// `ovr_GetRenderDesc`. For monoscopic rendering, use a vector that is the average
3205 /// of the two vectors for both eyes.
3206 ///
3207 /// **out** `outEyePoses` The predicted eye poses.
3208 ///
3209 /// **out** `outSensorSampleTime` The time when this function was called. May be NULL, in which case it is ignored.
3210 ///
3211 pub fn ovr_GetEyePoses(session: ovrSession, frameIndex: c_longlong, latencyMarker: ovrBool, hmdToEyeOffset: *const [ovrVector3f; 2], outEyePoses: *const [ovrPosef; 2], outSensorSampleTime: *mut f64);
3212
3213
3214
3215 /// Tracking poses provided by the SDK come in a right-handed coordinate system. If an application
3216 /// is passing in `ovrProjection_LeftHanded` into `ovrMatrix4f_Projection`, then it should also use
3217 /// this function to flip the HMD tracking poses to be left-handed.
3218 ///
3219 /// While this utility function is intended to convert a left-handed `ovrPosef` into a right-handed
3220 /// coordinate system, it will also work for converting right-handed to left-handed since the
3221 /// flip operation is the same for both cases.
3222 ///
3223 /// **in** `inPose` that is right-handed
3224 ///
3225 /// **out** `outPose` that is requested to be left-handed (can be the same pointer to `inPose`)
3226 ///
3227 pub fn ovrPosef_FlipHandedness(inPose: *const ovrPosef, outPose: *mut ovrPosef);
3228}