Add XRRenderState

This commit is contained in:
Manish Goregaokar 2019-01-14 19:15:33 -08:00
parent 5ae562bfc3
commit 1dc7636135
3 changed files with 82 additions and 0 deletions

View file

@ -538,6 +538,7 @@ pub mod xr;
pub mod xrframe;
pub mod xrlayer;
pub mod xrreferencespace;
pub mod xrrenderstate;
pub mod xrrigidtransform;
pub mod xrsession;
pub mod xrspace;

View file

@ -0,0 +1,17 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// https://immersive-web.github.io/webxr/#xrrenderstate-interface
dictionary XRRenderStateInit {
double depthNear = 0.1;
double depthFar = 1000.0;
XRLayer? baseLayer = null;
};
[SecureContext, Exposed=Window] interface XRRenderState {
readonly attribute double depthNear;
readonly attribute double depthFar;
readonly attribute XRLayer? baseLayer;
};

View file

@ -0,0 +1,64 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::dom::bindings::codegen::Bindings::XRRenderStateBinding::{self, XRRenderStateMethods};
use crate::dom::bindings::num::Finite;
use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::reflector::Reflector;
use crate::dom::bindings::root::{DomRoot, MutNullableDom};
use crate::dom::globalscope::GlobalScope;
use crate::dom::xrlayer::XRLayer;
use dom_struct::dom_struct;
use std::cell::Cell;
#[dom_struct]
pub struct XRRenderState {
reflector_: Reflector,
depth_near: Cell<f64>,
depth_far: Cell<f64>,
layer: MutNullableDom<XRLayer>,
}
impl XRRenderState {
pub fn new_inherited(
depth_near: f64,
depth_far: f64,
layer: Option<&XRLayer>,
) -> XRRenderState {
XRRenderState {
reflector_: Reflector::new(),
depth_near: Cell::new(depth_near),
depth_far: Cell::new(depth_far),
layer: MutNullableDom::new(layer),
}
}
pub fn new(
global: &GlobalScope,
depth_near: f64,
depth_far: f64,
layer: Option<&XRLayer>,
) -> DomRoot<XRRenderState> {
reflect_dom_object(
Box::new(XRRenderState::new_inherited(depth_near, depth_far, layer)),
global,
XRRenderStateBinding::Wrap,
)
}
}
impl XRRenderStateMethods for XRRenderState {
fn DepthNear(&self) -> Finite<f64> {
Finite::wrap(self.depth_near.get())
}
fn DepthFar(&self) -> Finite<f64> {
Finite::wrap(self.depth_far.get())
}
fn GetBaseLayer(&self) -> Option<DomRoot<XRLayer>> {
self.layer.get()
}
}