web api instance method
XRWebGLBinding: createQuadLayer() method
Limited availability
The createQuadLayer() method of the XRWebGLBinding interface returns an XRQuadLayer object which is a layer that takes up a flat rectangular space in the virtual environment.
Syntax
createQuadLayer(options)
Parameters
options- : An object to configure the
XRQuadLayer. It must have thespace,viewPixelHeight, andviewPixelWidthproperties.inithas the following properties:colorFormatOptional- : A
GLenumdefining the data type of the color texture data. Possible values:gl.RGBgl.RGBAAdditionally, for contexts with theEXT_sRGBextension enabled:ext.SRGB_EXText.SRGB_ALPHA_EXTAdditionally, forWebGL2RenderingContextcontexts:gl.RGBA8gl.RGB8gl.SRGB8gl.RGB8_ALPHA8Additionally, for contexts with theWEBGL_compressed_texture_etcextension 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 theWEBGL_compressed_texture_astcextension enabled:- All of the formats the extension supports.
The default value is
gl.RGBA.
- : A
depthFormatOptional- : A
GLenumdefining the data type of the depth texture data or0indicating that the layer should not provide a depth texture (in that caseignoreDepthValueswill betrue). Possible values withinWebGLRenderingContextcontexts with theWEBGL_depth_textureextension enabled, or withinWebGL2RenderingContextcontexts (no extension required):gl.DEPTH_COMPONENTgl.DEPTH_STENCILAdditionally, forWebGL2RenderingContextcontexts:gl.DEPTH_COMPONENT24gl.DEPTH24_STENCIL24The default value isgl.DEPTH_COMPONENT.
- : A
heightOptional- : A number specifying the height of the layer in meters. The default value is
1.0.
- : A number specifying the height of the layer in meters. The default value is
isStaticOptional- : A boolean that, if true, indicates you can only draw to this layer when
needsRedrawistrue. The default value isfalse.
- : A boolean that, if true, indicates you can only draw to this layer when
layoutOptional- : A string indicating the layout of the layer. Possible values:
default- : The layer accommodates all views of the session.
mono- : A single
XRSubImageis allocated and presented to both eyes.
- : A single
stereo- : The user agent decides how it allocates the
XRSubImage(one or two) and the layout (top/bottom or left/right).
- : The user agent decides how it allocates the
stereo-left-right- : A single
XRSubImageis allocated. Left eye gets the left area of the texture, right eye the right.
- : A single
stereo-top-bottom- : A single
XRSubImageis allocated. Left eye gets the top area of the texture, right eye the bottom. The default value ismono.
- : A single
- : A string indicating the layout of the layer. Possible values:
mipLevelsOptional- : A number specifying desired number of mip levels. The default value is
1.
- : A number specifying desired number of mip levels. The default value is
spaceRequired- : An
XRSpaceobject defining the layer’s spatial relationship with the user’s physical environment.
- : An
textureTypeOptional- : A string defining the type of texture the layer will have. Possible values:
texture- : The textures of
XRWebGLSubImagewill be of typegl.TEXTURE_2D.
- : The textures of
texture-array- : the textures of
XRWebGLSubImagewill be of typegl.TEXTURE_2D_ARRAY(WebGL 2 contexts only). The default value istexture.
- : the textures of
- : A string defining the type of texture the layer will have. Possible values:
transformOptional- : An
XRRigidTransformobject defining the offset and orientation relative tospace.
- : An
viewPixelHeightRequired- : A number specifying the pixel height of the layer view.
viewPixelWidthRequired- : A number specifying the pixel width of the layer view.
widthOptional- : A number specifying the width of the layer in meters. The default value is
1.0.
- : A number specifying the width of the layer in meters. The default value is
- : An object to configure the
Return value
An XRQuadLayer object.
Examples
Creating an XRQuadLayer
Configure 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 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
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.