files/en-us/web/api/xrwebglbinding/createquadlayer/index.md
{{APIRef("WebXR Device API")}}{{SeeCompatTable}}
The createQuadLayer() method of the {{domxref("XRWebGLBinding")}} interface returns an {{domxref("XRQuadLayer")}} object which is a layer that takes up a flat rectangular space in the virtual environment.
createQuadLayer(options)
options
space, viewPixelHeight, and viewPixelWidth properties. init has the following properties:
colorFormat {{optional_inline}}
gl.RGBgl.RGBA
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:gl.RGBA.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 within {{domxref("WebGLRenderingContext")}} contexts with the {{domxref("WEBGL_depth_texture")}} extension enabled, or within {{domxref("WebGL2RenderingContext")}} contexts (no extension required):
gl.DEPTH_COMPONENTgl.DEPTH_STENCIL
Additionally, for {{domxref("WebGL2RenderingContext")}} contexts:gl.DEPTH_COMPONENT24gl.DEPTH24_STENCIL24
The default value is gl.DEPTH_COMPONENT.height {{optional_inline}}
1.0.isStatic {{optional_inline}}
true. The default value is false.layout {{optional_inline}}
default
mono
stereo
stereo-left-right
stereo-top-bottom
mono.mipLevels {{optional_inline}}
1.space Required
textureType {{optional_inline}}
texture
gl.TEXTURE_2D.texture-array
gl.TEXTURE_2D_ARRAY (WebGL 2 contexts only).
The default value is texture.transform {{optional_inline}}
space.viewPixelHeight Required
viewPixelWidth Required
width {{optional_inline}}
1.0.An {{domxref("XRQuadLayer")}} object.
XRQuadLayerConfigure the quad layer using the properties listed above in a call to createQuadLayer(). 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 quadLayer = xrGlBinding.createQuadLayer({
space: xrReferenceSpace,
viewPixelHeight: 512,
viewPixelWidth: 512,
transform: new XRRigidTransform({ z: -2 }),
});
xrSession.updateRenderState({
layers: [quadLayer],
});
}
{{Specifications}}
{{Compat}}