add doc comments
This commit is contained in:
@@ -3,6 +3,9 @@ use std::rc::Rc;
|
|||||||
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
/// Entry point to the API
|
||||||
|
///
|
||||||
|
/// To see methods available for this struct, refer to [EntryTrait]
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Entry(Rc<dyn EntryTrait>);
|
pub struct Entry(Rc<dyn EntryTrait>);
|
||||||
|
|
||||||
@@ -16,100 +19,71 @@ impl Entry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Represents an intent to start a session with requested extensions.
|
||||||
|
///
|
||||||
|
/// To see methods available for this struct, refer to [InstanceTrait]
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Instance(Rc<dyn InstanceTrait>);
|
pub struct Instance(Rc<dyn InstanceTrait>);
|
||||||
|
|
||||||
|
/// Represents a running XR application.
|
||||||
|
///
|
||||||
|
/// To see methods available for this struct, refer to [SessionTrait]
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Session(Rc<dyn SessionTrait>);
|
pub struct Session(Rc<dyn SessionTrait>);
|
||||||
|
|
||||||
|
/// A view of one eye. Used to retrieve render data such as texture views and projection matrices.
|
||||||
|
///
|
||||||
|
/// To see methods available for this struct, refer to [ViewTrait]
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct View(Rc<dyn ViewTrait>);
|
pub struct View(Rc<dyn ViewTrait>);
|
||||||
|
|
||||||
|
/// Represents all XR input sources.
|
||||||
|
///
|
||||||
|
/// To see methods available for this struct, refer to [InputTrait]
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Input(Rc<dyn InputTrait>);
|
pub struct Input(Rc<dyn InputTrait>);
|
||||||
|
|
||||||
|
/// Represents an XR Action. Can be used to retrieve input values or trigger output devices such as haptics.
|
||||||
|
///
|
||||||
|
/// The methods available to this struct are dependent upon the action type. For input values, use `.get()` to retrieve the values.
|
||||||
|
/// For haptics, please refer to [HapticTrait]
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Action<A: ActionType>(A::Inner);
|
pub struct Action<A: ActionType>(Rc<A::Inner>);
|
||||||
|
|
||||||
impl Deref for Entry {
|
macro_rules! impl_api {
|
||||||
type Target = dyn EntryTrait;
|
($($t:ty, $trait:ident; )*) => {
|
||||||
|
$(
|
||||||
|
impl std::ops::Deref for $t {
|
||||||
|
type Target = dyn $trait;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&*self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: $trait + 'static> From<T> for $t {
|
||||||
|
fn from(value: T) -> Self {
|
||||||
|
Self(Rc::new(value))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)*
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
impl_api! {
|
||||||
|
Entry, EntryTrait;
|
||||||
|
Instance, InstanceTrait;
|
||||||
|
Session, SessionTrait;
|
||||||
|
View, ViewTrait;
|
||||||
|
Input, InputTrait;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<A: ActionType> Deref for Action<A> {
|
||||||
|
type Target = A::Inner;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
&*self.0
|
&self.0
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for Instance {
|
|
||||||
type Target = dyn InstanceTrait;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&*self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for Session {
|
|
||||||
type Target = dyn SessionTrait;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&*self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for View {
|
|
||||||
type Target = dyn ViewTrait;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&*self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for Input {
|
|
||||||
type Target = dyn InputTrait;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&*self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<O, A> Deref for Action<A>
|
|
||||||
where
|
|
||||||
A: ActionType,
|
|
||||||
A::Inner: Deref<Target = O>,
|
|
||||||
{
|
|
||||||
type Target = O;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&*self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: EntryTrait + 'static> From<T> for Entry {
|
|
||||||
fn from(value: T) -> Self {
|
|
||||||
Self(Rc::new(value))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: InstanceTrait + 'static> From<T> for Instance {
|
|
||||||
fn from(value: T) -> Self {
|
|
||||||
Self(Rc::new(value))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: SessionTrait + 'static> From<T> for Session {
|
|
||||||
fn from(value: T) -> Self {
|
|
||||||
Self(Rc::new(value))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
|
||||||
fn from(value: T) -> Self {
|
|
||||||
Self(Rc::new(value))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ pub trait SessionTrait {
|
|||||||
-> Option<(Device, Queue, AdapterInfo, Adapter, wgpu::Instance)>;
|
-> Option<(Device, Queue, AdapterInfo, Adapter, wgpu::Instance)>;
|
||||||
/// Request input modules with the specified bindings.
|
/// Request input modules with the specified bindings.
|
||||||
fn create_input(&self, bindings: Bindings) -> Result<Input>;
|
fn create_input(&self, bindings: Bindings) -> Result<Input>;
|
||||||
/// Blocks until a rendering frame is available, then returns the texture views for the left and right eyes.
|
/// Blocks until a rendering frame is available, then returns the views for the left and right eyes.
|
||||||
fn begin_frame(&self) -> Result<(TextureView, TextureView)>;
|
fn begin_frame(&self) -> Result<(View, View)>;
|
||||||
/// Submits rendering work for this frame.
|
/// Submits rendering work for this frame.
|
||||||
fn end_frame(&self) -> Result<()>;
|
fn end_frame(&self) -> Result<()>;
|
||||||
}
|
}
|
||||||
@@ -64,8 +64,12 @@ pub trait ActionTrait {
|
|||||||
fn id(&self) -> ActionId;
|
fn id(&self) -> ActionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ActionInputTrait<A> {}
|
/// Represents input actions, such as bools, floats, and poses
|
||||||
|
pub trait ActionInputTrait<A> {
|
||||||
|
fn get(&self) -> A;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Represents haptic actions.
|
||||||
pub trait HapticTrait {}
|
pub trait HapticTrait {}
|
||||||
|
|
||||||
impl<T: InstanceTrait> EntryTrait for T {
|
impl<T: InstanceTrait> EntryTrait for T {
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ impl SessionTrait for WebXrSession {
|
|||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn begin_frame(&self) -> Result<(wgpu::TextureView, wgpu::TextureView)> {
|
fn begin_frame(&self) -> Result<(View, View)> {
|
||||||
let mut end_frame_sender = self.end_frame_sender.lock().unwrap();
|
let mut end_frame_sender = self.end_frame_sender.lock().unwrap();
|
||||||
if end_frame_sender.is_some() {
|
if end_frame_sender.is_some() {
|
||||||
Err(XrError::Placeholder)?
|
Err(XrError::Placeholder)?
|
||||||
|
|||||||
@@ -33,13 +33,13 @@ pub struct Haptic;
|
|||||||
pub struct Pose;
|
pub struct Pose;
|
||||||
|
|
||||||
pub trait ActionType: Sized {
|
pub trait ActionType: Sized {
|
||||||
type Inner;
|
type Inner: ?Sized;
|
||||||
|
|
||||||
fn get(input: &dyn InputTrait, path: ActionId) -> Result<Action<Self>>;
|
fn get(input: &dyn InputTrait, path: ActionId) -> Result<Action<Self>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ActionType for Haptic {
|
impl ActionType for Haptic {
|
||||||
type Inner = Rc<dyn HapticTrait>;
|
type Inner = dyn HapticTrait;
|
||||||
|
|
||||||
fn get(input: &dyn InputTrait, path: ActionId) -> Result<Action<Self>> {
|
fn get(input: &dyn InputTrait, path: ActionId) -> Result<Action<Self>> {
|
||||||
input.get_haptics(path)
|
input.get_haptics(path)
|
||||||
@@ -47,7 +47,7 @@ impl ActionType for Haptic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ActionType for Pose {
|
impl ActionType for Pose {
|
||||||
type Inner = Rc<dyn ActionInputTrait<Pose>>;
|
type Inner = dyn ActionInputTrait<Pose>;
|
||||||
|
|
||||||
fn get(input: &dyn InputTrait, path: ActionId) -> Result<Action<Self>> {
|
fn get(input: &dyn InputTrait, path: ActionId) -> Result<Action<Self>> {
|
||||||
input.get_pose(path)
|
input.get_pose(path)
|
||||||
@@ -55,7 +55,7 @@ impl ActionType for Pose {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ActionType for f32 {
|
impl ActionType for f32 {
|
||||||
type Inner = Rc<dyn ActionInputTrait<f32>>;
|
type Inner = dyn ActionInputTrait<f32>;
|
||||||
|
|
||||||
fn get(input: &dyn InputTrait, path: ActionId) -> Result<Action<Self>> {
|
fn get(input: &dyn InputTrait, path: ActionId) -> Result<Action<Self>> {
|
||||||
input.get_float(path)
|
input.get_float(path)
|
||||||
@@ -63,7 +63,7 @@ impl ActionType for f32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ActionType for bool {
|
impl ActionType for bool {
|
||||||
type Inner = Rc<dyn ActionInputTrait<bool>>;
|
type Inner = dyn ActionInputTrait<bool>;
|
||||||
|
|
||||||
fn get(input: &dyn InputTrait, path: ActionId) -> Result<Action<Self>> {
|
fn get(input: &dyn InputTrait, path: ActionId) -> Result<Action<Self>> {
|
||||||
input.get_bool(path)
|
input.get_bool(path)
|
||||||
|
|||||||
Reference in New Issue
Block a user