api changes

This commit is contained in:
awtterpip
2023-12-27 19:20:59 -06:00
parent fd5323069f
commit 660dd32d84
5 changed files with 48 additions and 6 deletions

View File

@@ -9,6 +9,7 @@ linked = ["openxr/linked"]
[dependencies] [dependencies]
futures = "0.3.29" futures = "0.3.29"
glam = "0.25.0"
thiserror = "1.0.51" thiserror = "1.0.51"
wgpu = "0.18" wgpu = "0.18"

View File

@@ -7,8 +7,12 @@ use crate::prelude::*;
pub struct Entry(Rc<dyn EntryTrait>); pub struct Entry(Rc<dyn EntryTrait>);
impl Entry { impl Entry {
/// Constructs a new Xr entry
pub fn new() -> Self { pub fn new() -> Self {
todo!() #[cfg(target_family = "wasm")]
return crate::backend::webxr::WebXrEntry::new().into();
#[cfg(not(target_family = "wasm"))]
return crate::backend::oxr::OXrEntry::new().into();
} }
} }
@@ -18,6 +22,9 @@ pub struct Instance(Rc<dyn InstanceTrait>);
#[derive(Clone)] #[derive(Clone)]
pub struct Session(Rc<dyn SessionTrait>); pub struct Session(Rc<dyn SessionTrait>);
#[derive(Clone)]
pub struct View(Rc<dyn ViewTrait>);
#[derive(Clone)] #[derive(Clone)]
pub struct Input(Rc<dyn InputTrait>); pub struct Input(Rc<dyn InputTrait>);
@@ -48,6 +55,14 @@ impl Deref for Session {
} }
} }
impl Deref for View {
type Target = dyn ViewTrait;
fn deref(&self) -> &Self::Target {
&*self.0
}
}
impl Deref for Input { impl Deref for Input {
type Target = dyn InputTrait; type Target = dyn InputTrait;
@@ -86,6 +101,12 @@ impl<T: SessionTrait + 'static> From<T> for Session {
} }
} }
impl<T: ViewTrait + 'static> From<T> for View {
fn from(value: T) -> Self {
Self(Rc::new(value))
}
}
impl<T: InputTrait + 'static> From<T> for Input { impl<T: InputTrait + 'static> From<T> for Input {
fn from(value: T) -> Self { fn from(value: T) -> Self {
Self(Rc::new(value)) Self(Rc::new(value))

View File

@@ -32,6 +32,15 @@ pub trait SessionTrait {
fn end_frame(&self) -> Result<()>; fn end_frame(&self) -> Result<()>;
} }
pub trait ViewTrait {
/// Returns the [TextureView] used to render this view.
fn texture_view(&self) -> TextureView;
/// Returns the [Pose] representing the current position of this view.
fn pose(&self) -> Pose;
/// Returns the projection matrix for the current view.
fn projection_matrix(&self) -> glam::Mat4;
}
pub trait InputTrait { pub trait InputTrait {
/// Get the haptic action at the specified path. /// Get the haptic action at the specified path.
fn get_haptics(&self, path: ActionId) -> Result<Action<Haptic>>; fn get_haptics(&self, path: ActionId) -> Result<Action<Haptic>>;

View File

@@ -16,6 +16,17 @@ use utils::*;
#[derive(Clone)] #[derive(Clone)]
pub struct WebXrEntry(web_sys::XrSystem); pub struct WebXrEntry(web_sys::XrSystem);
impl WebXrEntry {
pub fn new() -> Self {
Self(
web_sys::window()
.expect("No window available in current environment")
.navigator()
.xr(),
)
}
}
impl EntryTrait for WebXrEntry { impl EntryTrait for WebXrEntry {
fn available_extensions(&self) -> Result<ExtensionSet> { fn available_extensions(&self) -> Result<ExtensionSet> {
Ok(ExtensionSet::default()) Ok(ExtensionSet::default())
@@ -45,7 +56,7 @@ impl InstanceTrait for WebXrInstance {
self.exts self.exts
} }
fn create_session(&self, info: SessionCreateInfo) -> Result<Session> { fn create_session(&self, _info: SessionCreateInfo) -> Result<Session> {
Ok(WebXrSession { Ok(WebXrSession {
instance: self.clone().into(), instance: self.clone().into(),
session: self session: self
@@ -170,15 +181,15 @@ impl InputTrait for WebXrInput {
Ok(WebXrHaptics(haptics, path).into()) Ok(WebXrHaptics(haptics, path).into())
} }
fn get_pose(&self, path: ActionId) -> Result<Action<Pose>> { fn get_pose(&self, _path: ActionId) -> Result<Action<Pose>> {
todo!() todo!()
} }
fn get_float(&self, path: ActionId) -> Result<Action<f32>> { fn get_float(&self, _path: ActionId) -> Result<Action<f32>> {
todo!() todo!()
} }
fn get_bool(&self, path: ActionId) -> Result<Action<bool>> { fn get_bool(&self, _path: ActionId) -> Result<Action<bool>> {
todo!() todo!()
} }
} }

View File

@@ -10,7 +10,7 @@ pub enum XrError {
} }
impl Display for XrError { impl Display for XrError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
todo!() todo!()
} }
} }