web api instance method
XRWebGLBinding: createProjectionLayer() method
Limited availability
The createProjectionLayer() method of the XRWebGLBinding interface returns an XRProjectionLayer object which is a layer that fills the entire view of the observer and is refreshed close to the device’s native frame rate.
Syntax
createProjectionLayer(options)
Parameters
options- : An object to configure the
XRProjectionLayer.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:
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_ALPHA8The default value isgl.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
scaleFactorOptional- : A floating-point value which is used to scale the layer during compositing. A value of
1.0represents the default pixel size for the frame buffer. (See alsoXRWebGLLayer.getNativeFramebufferScaleFactor().) Unlike other layers, theXRProjectionLayercan’t be created with an explicit pixel width and height, because the size is inferred by the hardware. (Projection layers fill the observer’s entire view.)
- : A floating-point value which is used to scale the layer during compositing. A value of
- : An object to configure the
Return value
An XRProjectionLayer object.
Examples
Creating an XRProjectionLayer in a WebGL 2 context
The textureType option allows allocating a texture array instead, in which every XRView will be rendered into a separate level of the array. This allows for some rendering optimizations, such as the use of the OVR_multiview2 extension available in WebGL 2 contexts.
function onXRSessionStarted(xrSession) {
const glCanvas = document.createElement("canvas");
const gl = glCanvas.getContext("webgl2", { xrCompatible: true });
const xrGlBinding = new XRWebGLBinding(xrSession, gl);
const projectionLayer = xrGlBinding.createProjectionLayer({
textureType: "texture-array",
});
xrSession.updateRenderState({
layers: [projectionLayer],
});
}
Specifications
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.