files/en-us/web/api/xrwebglbinding/createcylinderlayer/index.md
{{APIRef("WebXR Device API")}}{{SeeCompatTable}}
The createCylinderLayer() method of the {{domxref("XRWebGLBinding")}} interface returns an {{domxref("XRCylinderLayer")}} object, which is a layer that takes up a curved rectangular space in the virtual environment.
createCylinderLayer(init)
init
space, viewPixelHeight, and viewPixelWidth properties. init has the following properties:
aspectRatio {{optional_inline}}
radius with the centralAngle. The default value is 2.0.centralAngle {{optional_inline}}
0.78539 (π / 4).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:All of the formats the extension supports.
The default value is 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.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.radius {{optional_inline}}
2.0.space Required
textureType {{optional_inline}}
texture: The textures of {{domxref("XRWebGLSubImage")}} will be of type gl.TEXTURE_2D.texture-array: the textures of {{domxref("XRWebGLSubImage")}} will be of type gl.TEXTURE_2D_ARRAY (WebGL 2 contexts only).
The default value is texture.transform {{optional_inline}}
space.viewPixelHeight Required
viewPixelWidth Required
An {{domxref("XRCylinderLayer")}} object.
XRCylinderLayerConfigure the cylinder layer using the properties listed above in a call to createCylinderLayer(). 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 cylinderLayer = xrGlBinding.createCylinderLayer({
space: xrReferenceSpace,
viewPixelWidth: 1200,
viewPixelHeight: 600,
centralAngle: (60 * Math.PI) / 180,
aspectRatio: 2,
radius: 2,
transform: new XRRigidTransform(/* … */),
});
xrSession.updateRenderState({
layers: [cylinderLayer],
});
}
{{Specifications}}
{{Compat}}