Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Views::Inline #100

Merged
merged 1 commit into from
Dec 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions webxr-api/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ pub trait DeviceAPI<Surface>: 'static {

/// A resolution large enough to contain all the viewports.
/// https://immersive-web.github.io/webxr/#native-webgl-framebuffer-resolution
fn recommended_framebuffer_resolution(&self) -> Size2D<i32, Viewport> {
fn recommended_framebuffer_resolution(&self) -> Option<Size2D<i32, Viewport>> {
let viewport = match self.views() {
Views::Inline => return None,
Views::Mono(view) => view.viewport,
Views::Stereo(left, right) => left.viewport.union(&right.viewport),
};
Size2D::new(viewport.max_x(), viewport.max_y())
Some(Size2D::new(viewport.max_x(), viewport.max_y()))
}

/// This method should block waiting for the next frame,
Expand Down
3 changes: 2 additions & 1 deletion webxr-api/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Quitter {
pub struct Session {
floor_transform: RigidTransform3D<f32, Native, Floor>,
views: Views,
resolution: Size2D<i32, Viewport>,
resolution: Option<Size2D<i32, Viewport>>,
sender: Sender<SessionMsg>,
environment_blend_mode: EnvironmentBlendMode,
initial_inputs: Vec<InputSource>,
Expand All @@ -109,6 +109,7 @@ impl Session {

pub fn recommended_framebuffer_resolution(&self) -> Size2D<i32, Viewport> {
self.resolution
.expect("Inline XR sessions should not construct a framebuffer")
}

pub fn set_swap_chain(&mut self, swap_chain_id: Option<SwapChainId>) {
Expand Down
2 changes: 2 additions & 0 deletions webxr-api/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ impl<Eye> Default for View<Eye> {
#[derive(Clone, Debug)]
#[cfg_attr(feature = "ipc", derive(Serialize, Deserialize))]
pub enum Views {
/// Mono view for inline VR, viewport and projection matrices are calculated by client
Inline,
Mono(View<Viewer>),
Stereo(View<LeftEye>, View<RightEye>),
}
9 changes: 7 additions & 2 deletions webxr/headless/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ struct InputInfo {

struct HeadlessDevice {
data: Arc<Mutex<HeadlessDeviceData>>,
mode: SessionMode,
}

struct HeadlessDeviceData {
Expand Down Expand Up @@ -110,7 +111,7 @@ impl DiscoveryAPI<SwapChains> for HeadlessDiscovery {
return Err(Error::NoMatchingDevice);
}
let data = self.data.clone();
xr.run_on_main_thread(move || Ok(HeadlessDevice { data }))
xr.run_on_main_thread(move || Ok(HeadlessDevice { data, mode }))
}

fn supports_session(&self, mode: SessionMode) -> bool {
Expand All @@ -124,7 +125,11 @@ impl DeviceAPI<Surface> for HeadlessDevice {
}

fn views(&self) -> Views {
self.data.lock().unwrap().views.clone()
if self.mode == SessionMode::Inline {
Views::Inline
} else {
self.data.lock().unwrap().views.clone()
}
}

fn wait_for_animation_frame(&mut self) -> Option<Frame> {
Expand Down