use crate::ContextId;
use crate::EnvironmentBlendMode;
use crate::Error;
use crate::Event;
use crate::Floor;
use crate::Frame;
use crate::HitTestId;
use crate::HitTestSource;
use crate::InputSource;
use crate::LayerId;
use crate::LayerInit;
use crate::Native;
use crate::Quitter;
use crate::Sender;
use crate::Session;
use crate::SessionBuilder;
use crate::SessionInit;
use crate::SessionMode;
use crate::Viewports;
use euclid::{Point2D, RigidTransform3D};
pub trait DiscoveryAPI<GL>: 'static {
fn request_session(
&mut self,
mode: SessionMode,
init: &SessionInit,
xr: SessionBuilder<GL>,
) -> Result<Session, Error>;
fn supports_session(&self, mode: SessionMode) -> bool;
}
pub trait DeviceAPI: 'static {
fn create_layer(&mut self, context_id: ContextId, init: LayerInit) -> Result<LayerId, Error>;
fn destroy_layer(&mut self, context_id: ContextId, layer_id: LayerId);
fn floor_transform(&self) -> Option<RigidTransform3D<f32, Native, Floor>>;
fn viewports(&self) -> Viewports;
fn begin_animation_frame(&mut self, layers: &[(ContextId, LayerId)]) -> Option<Frame>;
fn end_animation_frame(&mut self, layers: &[(ContextId, LayerId)]);
fn initial_inputs(&self) -> Vec<InputSource>;
fn set_event_dest(&mut self, dest: Sender<Event>);
fn quit(&mut self);
fn set_quitter(&mut self, quitter: Quitter);
fn update_clip_planes(&mut self, near: f32, far: f32);
fn environment_blend_mode(&self) -> EnvironmentBlendMode {
EnvironmentBlendMode::Opaque
}
fn granted_features(&self) -> &[String];
fn request_hit_test(&mut self, _source: HitTestSource) {
panic!("This device does not support requesting hit tests");
}
fn cancel_hit_test(&mut self, _id: HitTestId) {
panic!("This device does not support hit tests");
}
fn update_frame_rate(&mut self, rate: f32) -> f32 {
rate
}
fn supported_frame_rates(&self) -> Vec<f32> {
Vec::new()
}
fn reference_space_bounds(&self) -> Option<Vec<Point2D<f32, Floor>>> {
None
}
}
impl<GL: 'static> DiscoveryAPI<GL> for Box<dyn DiscoveryAPI<GL>> {
fn request_session(
&mut self,
mode: SessionMode,
init: &SessionInit,
xr: SessionBuilder<GL>,
) -> Result<Session, Error> {
(&mut **self).request_session(mode, init, xr)
}
fn supports_session(&self, mode: SessionMode) -> bool {
(&**self).supports_session(mode)
}
}