XRWebGLBinding: createEquirectLayer() method
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The createEquirectLayer() method of the XRWebGLBinding interface returns an XREquirectLayer object, which is a layer that maps equirectangular coded data onto the inside of a sphere.
Syntax
createEquirectLayer(options)
Parameters
options-
An object to configure the
XREquirectLayer. It must have thespace,viewPixelHeight, andviewPixelWidthproperties.inithas the following properties:centralHorizontalAngleOptional-
A number indicating the central horizontal angle in radians of the sphere. Default value:
6.28318(2π). 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:Allof the formats the extension supports. The default value isgl.RGBA.
depthFormatOptional-
A
GLenumdefining the data type of the depth texture data, or else0to indicate that the layer should not provide a depth texture (in that caseXRProjectionLayer.ignoreDepthValueswill 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.
isStaticOptional-
A boolean that, if true, indicates you can only draw to this layer when
needsRedrawistrue. The default value isfalse. 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. 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
XRSubImageis allocated. Left eye gets the left area of the texture, right eye the right. stereo-top-bottom-
A single
XRSubImageis allocated. Left eye gets the top area of the texture, right eye the bottom. The default value ismono.
lowerVerticalAngleOptional-
A number indicating the lower vertical angle in radians of the sphere. Default value:
-1.570795(-π/2). mipLevelsOptional-
A number specifying desired number of mip levels. The default value is
1. radiusOptional-
A number indicating the radius of the sphere. Default value:
0(infinite sphere). spaceRequired-
An
XRSpaceobject defining the layer's spatial relationship with the user's physical environment. textureTypeOptional-
A string defining the type of texture the layer will have. Possible values:
texture-
The textures of
XRWebGLSubImagewill be of typegl.TEXTURE_2D. texture-array-
The textures of
XRWebGLSubImagewill be of typegl.TEXTURE_2D_ARRAY(WebGL 2 contexts only). The default value istexture.
transformOptional-
An
XRRigidTransformobject defining the offset and orientation relative tospace. upperVerticalAngleOptional-
A number indicating the upper vertical angle in radians of the sphere. Default value:
1.570795(π/2). viewPixelHeightRequired-
A number specifying the pixel height of the layer view.
viewPixelWidthRequired-
A number specifying the pixel width of the layer view.
Return value
An XREquirectLayer object.
Examples
>Creating an XREquirectLayer
Configure the equirect layer using the properties listed above in a call to createEquirect(). 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 equirectLayer = xrGlBinding.createEquirectLayer({
space: xrReferenceSpace,
viewPixelWidth: 1200,
viewPixelHeight: 600,
centralHorizontalAngle: 2 * Math.PI,
upperVerticalAngle: Math.PI / 2.0,
lowerVerticalAngle: -Math.PI / 2.0,
radius: 0,
});
xrSession.updateRenderState({
layers: [equirectLayer],
});
}
Specifications
| Specification |
|---|
| WebXR Layers API Level 1> # dom-xrwebglbinding-createequirectlayer> |
Browser compatibility
Loading…