WebXR Device API
The createCubeLayer() method of the XRWebGLBinding interface returns an XRCubeLayer object, which is a layer that renders directly from a cubemap, and projects it onto the inside faces of a cube.
Syntax
createCubeLayer(init)
Parameters
init- : An object to configure the XRCubeLayer. It must have the
space,viewPixelHeight, andviewPixelWidthproperties.inithas the following properties:colorFormat- : A WebGL_API/Types defining the data type of the color texture data. Possible values:
gl.RGBgl.RGBA(Default) Additionally, for contexts with the EXT_sRGB extension enabled:ext.SRGB_EXText.SRGB_ALPHA_EXTAdditionally, for WebGL2RenderingContext contexts:gl.RGBA8gl.RGB8gl.SRGB8gl.RGB8_ALPHA8Additionally, for contexts with the WEBGL_compressed_texture_etc extension enabled:ext.COMPRESSED_RGB8_ETC2ext.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2ext.COMPRESSED_RGBA8_ETC2_EACext.COMPRESSED_SRGB8_ETC2ext.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2ext.COMPRESSED_SRGB8_ALPHA8_ETC2_EACAdditionally, for contexts with the WEBGL_compressed_texture_astc extension enabled:- All of the formats the extension supports.
- : A WebGL_API/Types defining the data type of the color texture data. Possible values:
depthFormat- : A WebGL_API/Types defining the data type of the depth texture data or
0indicating that the layer should not provide a depth texture. (In that case XRProjectionLayer.ignoreDepthValues will betrue.) Possible values for WebGLRenderingContext contexts with the WEBGL_depth_texture extension enabled, or for WebGL2RenderingContext contexts (no extension required):gl.DEPTH_COMPONENT(Default)gl.DEPTH_STENCILAdditionally, for WebGL2RenderingContext contexts:gl.DEPTH_COMPONENT24gl.DEPTH24_STENCIL24
- : A WebGL_API/Types defining the data type of the depth texture data or
isStatic- : A boolean that, if true, indicates you can only draw to this layer when XRCompositionLayer.needsRedraw is
true. The default value isfalse.
- : A boolean that, if true, indicates you can only draw to this layer when XRCompositionLayer.needsRedraw is
layout- : A string indicating the layout of the layer. Possible values:
default: The layer accommodates all views of the session.mono: A single XRSubImage is allocated and presented to both eyes.stereo: The user agent decides how it allocates the XRSubImage (one or two) and the layout (top/bottom or left/right).stereo-left-right: A single XRSubImage is allocated. The left eye gets the left area of the texture, the right eye the right.stereo-top-bottom: A single XRSubImage is allocated. The left eye gets the top area of the texture, the right eye the bottom. The default value ismono.
- : A string indicating the layout of the layer. Possible values:
mipLevels- : A number specifying the desired number of mip levels. The default value is
1.
- : A number specifying the desired number of mip levels. The default value is
orientation- : A DOMPointReadOnly specifying the orientation relative to the
spaceproperty.
- : A DOMPointReadOnly specifying the orientation relative to the
spaceRequired- : An XRSpace object defining the layer's spatial relationship with the user's physical environment.
viewPixelHeightRequired- : A number specifying the pixel height of the layer view.
viewPixelWidthRequired- : A number specifying the pixel width of the layer view.
- : An object to configure the XRCubeLayer. It must have the
Return value
An XRCubeLayer object.
Examples
Creating an XRCubeLayer
Configure the cube layer using the properties listed above in a call to createCubeLayer(). To present layers to the XR device, add them to the layers render state using XRSession.updateRenderState().
function onXRSessionStarted(xrSession) {
const glCanvas = document.createElement("canvas");
const gl = glCanvas.getContext("webgl2", { xrCompatible: true });
const xrGlBinding = new XRWebGLBinding(xrSession, gl);
const cubeLayer = xrGlBinding.createCubeLayer({
space: xrReferenceSpace,
viewPixelHeight: 512,
viewPixelWidth: 512,
});
xrSession.updateRenderState({
layers: [cubeLayer],
});
}
Specifications
Browser compatibility
See also
- XRCubeLayer
- WebGL constants
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
