files/en-us/web/api/xrwebglbinding/createcubelayer/index.md
{{APIRef("WebXR Device API")}}{{SeeCompatTable}}
The createCubeLayer() method of the {{domxref("XRWebGLBinding")}} interface returns an {{domxref("XRCubeLayer")}} object, which is a layer that renders directly from a cubemap, and projects it onto the inside faces of a cube.
createCubeLayer(init)
init
space, viewPixelHeight, and viewPixelWidth properties. init has the following properties:
colorFormat {{optional_inline}}
gl.RGBgl.RGBA (Default)
Additionally, for contexts with the {{domxref("EXT_sRGB")}} extension enabled:ext.SRGB_EXText.SRGB_ALPHA_EXT
Additionally, for {{domxref("WebGL2RenderingContext")}} contexts:gl.RGBA8gl.RGB8gl.SRGB8gl.RGB8_ALPHA8
Additionally, for contexts with the {{domxref("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_EAC
Additionally, for contexts with the {{domxref("WEBGL_compressed_texture_astc")}} extension enabled:depthFormat {{optional_inline}}
0 indicating that the layer should not provide a depth texture. (In that case {{domxref("XRProjectionLayer.ignoreDepthValues")}} will be true.)
Possible values for {{domxref("WebGLRenderingContext")}} contexts with the {{domxref("WEBGL_depth_texture")}} extension enabled, or for {{domxref("WebGL2RenderingContext")}} contexts (no extension required):
gl.DEPTH_COMPONENT (Default)gl.DEPTH_STENCIL
Additionally, for {{domxref("WebGL2RenderingContext")}} contexts:gl.DEPTH_COMPONENT24gl.DEPTH24_STENCIL24isStatic {{optional_inline}}
true. The default value is false.layout
default: The layer accommodates all views of the session.mono: A single {{domxref("XRSubImage")}} is allocated and presented to both eyes.stereo: The user agent decides how it allocates the {{domxref("XRSubImage")}} (one or two) and the layout (top/bottom or left/right).stereo-left-right: A single {{domxref("XRSubImage")}} is allocated. The left eye gets the left area of the texture, the right eye the right.stereo-top-bottom: A single {{domxref("XRSubImage")}} is allocated. The left eye gets the top area of the texture, the right eye the bottom.
The default value is mono.mipLevels {{optional_inline}}
1.orientation {{optional_inline}}
space property.space Required
viewPixelHeight Required
viewPixelWidth Required
An {{domxref("XRCubeLayer")}} object.
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 {{domxref("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}}
{{Compat}}