Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Added first-cut implementation of XR layers
- Loading branch information
Alan Jeffrey
committed
Apr 13, 2020
1 parent
7ae1158
commit fda8da0
Showing
19 changed files
with
585 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* 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/layers/#xrlayertype | ||
[SecureContext, Exposed=Window, Pref="dom.webxr.layers.enabled"] | ||
interface XRLayer { | ||
readonly attribute unsigned long pixelWidth; | ||
readonly attribute unsigned long pixelHeight; | ||
|
||
// attribute boolean blendTextureSourceAlpha; | ||
// attribute boolean chromaticAberrationCorrection; | ||
|
||
void destroy(); | ||
}; | ||
// | ||
// TODO: Implement the layer types | ||
// | ||
// [SecureContext, Exposed=Window, Pref="dom.webxr.enabled"] | ||
// interface XRProjectionLayer : XRLayer { | ||
// readonly attribute boolean ignoreDepthValues; | ||
// }; | ||
// | ||
// [SecureContext, Exposed=Window, Pref="dom.webxr.layers.enabled"] | ||
// interface XRQuadLayer : XRLayer { | ||
// readonly attribute XRLayerLayout layout; | ||
// attribute XRRigidTransform transform; | ||
// | ||
// attribute float width; | ||
// attribute float height; | ||
// }; | ||
// | ||
// [SecureContext, Exposed=Window, Pref="dom.webxr.layers.enabled"] | ||
// interface XRCylinderLayer : XRLayer { | ||
// readonly attribute XRLayerLayout layout; | ||
// attribute XRReferenceSpace referenceSpace; | ||
// | ||
// attribute XRRigidTransform transform; | ||
// attribute float radius; | ||
// attribute float centralAngle; | ||
// attribute float aspectRatio; | ||
// }; | ||
// | ||
// [SecureContext, Exposed=Window, Pref="dom.webxr.layers.enabled"] | ||
// interface XREquirectLayer : XRLayer { | ||
// readonly attribute XRLayerLayout layout; | ||
// attribute XRReferenceSpace referenceSpace; | ||
// | ||
// attribute XRRigidTransform transform; | ||
// attribute float radius; | ||
// attribute float scaleX; | ||
// attribute float scaleY; | ||
// attribute float biasX; | ||
// attribute float biasY; | ||
// }; | ||
// | ||
// [SecureContext, Exposed=Window, Pref="dom.webxr.layers.enabled"] | ||
// interface XRCubeLayer : XRLayer { | ||
// readonly attribute XRLayerLayout layout; | ||
// attribute XRReferenceSpace referenceSpace; | ||
// | ||
// attribute DOMPoint orientation; | ||
// }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* 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/layers/#xrmediabindingtype | ||
[SecureContext, Exposed=Window, Pref="dom.webxr.layers.enabled"] | ||
interface XRMediaBinding { | ||
constructor(XRSession session); | ||
|
||
// XRQuadLayer createQuadVideoLayer(HTMLVideoElement video, optional XRMediaLayerInit init = {}); | ||
// XRCylinderLayer createCylinderVideoLayer(HTMLVideoElement video, optional XRMediaLayerInit init = {}); | ||
// XREquirectLayer createEquirectVideoLayer(HTMLVideoElement video, optional XRMediaLayerInit init = {}); | ||
}; | ||
|
||
dictionary XRMediaLayerInit { | ||
XRLayerLayout layout = "mono"; | ||
boolean invertStereo = false; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* 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/layers/#xrsubimagetype | ||
[SecureContext, Exposed=Window, Pref="dom.webxr.layers.enabled"] | ||
interface XRSubImage { | ||
readonly attribute XRViewport viewport; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* 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/layers/#XRWebGLBindingtype | ||
[SecureContext, Exposed=Window, Pref="dom.webxr.layers.enabled"] | ||
interface XRWebGLBinding { | ||
constructor(XRSession session, XRWebGLRenderingContext context); | ||
|
||
// readonly attribute double nativeProjectionScaleFactor; | ||
|
||
// XRProjectionLayer createProjectionLayer(GLenum textureTarget, optional XRProjectionLayerInit init = {}); | ||
// XRQuadLayer createQuadLayer(GLenum textureTarget, XRLayerInit init); | ||
// XRCylinderLayer createCylinderLayer(GLenum textureTarget, XRLayerInit init); | ||
// XREquirectLayer createEquirectLayer(GLenum textureTarget, XRLayerInit init); | ||
// XRCubeLayer createCubeLayer(XRLayerInit init); | ||
|
||
XRWebGLSubImage? getSubImage(XRLayer layer, XRFrame frame); // for mono layers | ||
XRWebGLSubImage? getViewSubImage(XRLayer layer, XRView view); // for stereo layers | ||
}; | ||
|
||
dictionary XRProjectionLayerInit { | ||
boolean depth = true; | ||
boolean stencil = false; | ||
boolean alpha = true; | ||
double scaleFactor = 1.0; | ||
}; | ||
|
||
dictionary XRLayerInit { | ||
required unsigned long pixelWidth; | ||
required unsigned long pixelHeight; | ||
XRLayerLayout layout = "mono"; | ||
boolean depth = false; // This is a change from typical WebGL initialization, but feels appropriate. | ||
boolean stencil = false; | ||
boolean alpha = true; | ||
}; | ||
|
||
enum XRLayerLayout { | ||
"mono", | ||
"stereo", | ||
"stereo-left-right", | ||
"stereo-top-bottom" | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* 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/layers/#xrwebglsubimagetype | ||
[SecureContext, Exposed=Window, Pref="dom.webxr.layers.enabled"] | ||
interface XRWebGLSubImage : XRSubImage { | ||
readonly attribute WebGLTexture colorTexture; | ||
readonly attribute WebGLTexture? depthStencilTexture; | ||
readonly attribute unsigned long? imageIndex; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* 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::XRLayerBinding::XRLayerBinding::XRLayerMethods; | ||
use crate::dom::bindings::reflector::Reflector; | ||
use crate::dom::bindings::root::Dom; | ||
use crate::dom::webglrenderingcontext::WebGLRenderingContext; | ||
use crate::dom::xrsession::XRSession; | ||
use dom_struct::dom_struct; | ||
use euclid::Size2D; | ||
use webxr_api::Viewport; | ||
|
||
#[dom_struct] | ||
pub struct XRLayer { | ||
reflector: Reflector, | ||
session: Dom<XRSession>, | ||
context: Dom<WebGLRenderingContext>, | ||
size: Size2D<u32, Viewport>, | ||
} | ||
|
||
impl XRLayerMethods for XRLayer { | ||
/// https://immersive-web.github.io/layers/#dom-xrlayer-pixelwidth | ||
fn PixelWidth(&self) -> u32 { | ||
self.size.width | ||
} | ||
|
||
/// https://immersive-web.github.io/layers/#dom-xrlayer-pixelheight | ||
fn PixelHeight(&self) -> u32 { | ||
self.size.height | ||
} | ||
|
||
/// https://immersive-web.github.io/layers/#dom-xrlayer-destroy | ||
fn Destroy(&self) { | ||
// TODO: Implement this | ||
} | ||
} | ||
|
||
impl XRLayer { | ||
#[allow(dead_code)] | ||
pub fn new_inherited( | ||
session: &XRSession, | ||
context: &WebGLRenderingContext, | ||
size: Size2D<u32, Viewport>, | ||
) -> XRLayer { | ||
XRLayer { | ||
reflector: Reflector::new(), | ||
session: Dom::from_ref(session), | ||
context: Dom::from_ref(context), | ||
size: size, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* 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::reflector::reflect_dom_object; | ||
use crate::dom::bindings::reflector::Reflector; | ||
use crate::dom::bindings::root::Dom; | ||
use crate::dom::bindings::root::DomRoot; | ||
use crate::dom::window::Window; | ||
use crate::dom::xrsession::XRSession; | ||
use dom_struct::dom_struct; | ||
|
||
#[dom_struct] | ||
pub struct XRMediaBinding { | ||
reflector: Reflector, | ||
session: Dom<XRSession>, | ||
} | ||
|
||
impl XRMediaBinding { | ||
pub fn new_inherited(session: &XRSession) -> XRMediaBinding { | ||
XRMediaBinding { | ||
reflector: Reflector::new(), | ||
session: Dom::from_ref(session), | ||
} | ||
} | ||
|
||
pub fn new(global: &Window, session: &XRSession) -> DomRoot<XRMediaBinding> { | ||
reflect_dom_object(Box::new(XRMediaBinding::new_inherited(session)), global) | ||
} | ||
|
||
#[allow(non_snake_case)] | ||
pub fn Constructor(global: &Window, session: &XRSession) -> DomRoot<XRMediaBinding> { | ||
XRMediaBinding::new(global, session) | ||
} | ||
} |
Oops, something went wrong.