rust_webvr_api/vr_display.rs
1use {VRDisplayData, VRFramebuffer, VRFramebufferAttributes, VRFrameData, VRFutureFrameData, VRGamepadPtr, VRLayer};
2use sparkle::gl::Gl;
3use std::sync::Arc;
4use std::cell::RefCell;
5pub type VRDisplayPtr = Arc<RefCell<dyn VRDisplay>>;
6
7/// The VRDisplay traits forms the base of all VR device implementations
8pub trait VRDisplay: Send + Sync {
9
10 /// Returns unique device identifier
11 fn id(&self) -> u32;
12
13 /// Returns the current display data.
14 fn data(&self) -> VRDisplayData;
15
16 /// Returns gamepads attached to this display
17 fn fetch_gamepads(&mut self) -> Result<Vec<VRGamepadPtr>, String>;
18
19 /// Returns the immediate VRFrameData of the HMD
20 /// Should be used when not presenting to the device.
21 fn immediate_frame_data(&self, near_z: f64, far_z: f64) -> VRFrameData;
22
23 /// Returns the synced VRFrameData to render the next frame.
24 /// The future that is returned will resolve with frame data when the
25 /// next frame is available.
26 #[allow(deprecated)]
27 fn future_frame_data(&mut self, near_z: f64, far_z: f64) -> VRFutureFrameData {
28 // The default implementation blocks waiting for the display.
29 self.sync_poses();
30 VRFutureFrameData::resolved(self.synced_frame_data(near_z, far_z))
31 }
32
33 /// Returns the synced VRFrameData to render the current frame.
34 /// Should be used when presenting to the device.
35 /// sync_poses must have been called before this call.
36 #[deprecated(since="0.10.3", note="please use `future_frame_data` instead")]
37 fn synced_frame_data(&self, next: f64, far_z: f64) -> VRFrameData;
38
39 /// Resets the pose for this display
40 fn reset_pose(&mut self);
41
42 /// Synchronization point to keep in step with the HMD
43 /// Returns VRFrameData to be used in the next render frame
44 /// Must be called in the render thread, before doing any work
45 #[deprecated(since="0.10.3", note="please use `future_frame_data` instead")]
46 fn sync_poses(&mut self);
47
48 /// Binds the framebuffer to directly render to the HDM
49 /// Must be called in the render thread, before doing any work
50 fn bind_framebuffer(&mut self, index: u32);
51
52 /// Returns the available FBOs that must be used to render to all eyes
53 /// Must be called in the render thread, before doing any work
54 fn get_framebuffers(&self) -> Vec<VRFramebuffer>;
55
56 /// Renders a VRLayer from a external texture
57 /// Must be called in the render thread
58 #[deprecated(since="0.10.3", note="please use `submit_layer` instead")]
59 fn render_layer(&mut self, layer: &VRLayer);
60
61 /// Submits frame to the display
62 /// Must be called in the render thread
63 #[deprecated(since="0.10.3", note="please use `submit_layer` instead")]
64 fn submit_frame(&mut self);
65
66 /// Renders a VRLayer from an external texture, and submits it to the device.
67 /// Must be called in the render thread
68 #[allow(unused_variables)]
69 #[allow(deprecated)]
70 fn submit_layer(&mut self, gl: &Gl, layer: &VRLayer) {
71 self.render_layer(layer);
72 self.submit_frame();
73 }
74
75 /// Hint to indicate that we are going to start sending frames to the device
76 fn start_present(&mut self, _attributes: Option<VRFramebufferAttributes>) {}
77
78 /// Hint to indicate that we are going to stop sending frames to the device
79 fn stop_present(&mut self) {}
80}
81
82impl PartialEq for dyn VRDisplay {
83 fn eq(&self, other: &dyn VRDisplay) -> bool {
84 self.id() == other.id()
85 }
86}