files/en-us/web/api/xrwebgllayer/framebuffer/index.md
{{APIRef("WebXR Device API")}}{{SeeCompatTable}}{{SecureContext_Header}}
The read-only {{domxref("XRWebGLLayer")}} property
framebuffer is an opaque {{domxref("WebGLFramebuffer")}}
which is used to buffer the rendered image if the XR compositor is being used. Otherwise, this property's value is
null. The opaque framebuffer is functionally nearly the same as a
standard WebGL framebuffer, except for the differences covered in the section
How opaque framebuffers are special below.
A {{domxref("WebGLFramebuffer")}} object representing the framebuffer into which the 3D
scene is being rendered, or null if the XR compositor is disabled for the session.
The framebuffer represented by the framebuffer property is opaque. As
such, its behavior is different in several ways from a standard WebGL context. These
differences cause the opaque framebuffer to behave more like the default WebGL
framebuffer:
INVALID_OPERATION (0x0502).INVALID_FRAMEBUFFER_OPERATION error (0x0506).
Calling {{domxref("WebGLRenderingContext.checkFramebufferStatus", "checkFramebufferStatus()")}} on the WebGL context from outside the animation frame
callback causes the WebGL FRAMEBUFFER_UNSUPPORTED error (0x8CDD) to be reported.depth property set to false will not have a depth buffer and will
rely on the coordinates alone to determine distance.stencil property will not have a stencil buffer.alpha property is true when
creating the layer.premultipliedAlpha context
attribute is set.[!NOTE] The
depthandstencilproperties are not required to be supported in order for a browser to be construed as having full WebGL support.
Upon creating a new {{domxref("XRWebGLLayer")}}, its new framebuffer is initialized just like the default framebuffer for any WebGL interface:
This example gets the XRWebGLLayer for a session and then passes its
framebuffer into the WebGL context's {{domxref("WebGLRenderingContext.bindFramebuffer", "bindFramebuffer()")}} function.
let glLayer = xrSession.renderState.baseLayer;
gl.bindFramebuffer(gl.FRAMEBUFFER, glLayer.framebuffer);
{{Specifications}}
{{Compat}}