WebXR Device API
The XRWebGLBinding() constructor creates and
returns a new XRWebGLBinding object.
Syntax
new XRWebGLBinding(session, context)
Parameters
session- : An XRSession object specifying the WebXR session which will be rendered using the WebGL context.
context- : A WebGLRenderingContext or WebGL2RenderingContext identifying the WebGL drawing context to use for rendering the scene for the specified WebXR session.
Return value
A new XRWebGLBinding.
Exceptions
InvalidStateErrorDOMException- : Thrown if the new
XRWebGLBindingcould not be created due to one of the following situations:- The XRSession specified by
sessionhas already been stopped. - The specified WebGL context,
context, has been lost for any reason, such as a GPU switch or reset. - The specified
sessionis immersive but thecontextis not WebXR compatible.
- The XRSession specified by
- : Thrown if the new
Examples
const canvasElement = document.querySelector(".output-canvas");
const gl = canvasElement.getContext("webgl");
const xrSession = await navigator.xr.requestSession("immersive-vr");
await gl.makeXRCompatible();
const glBinding = new XRWebGLBinding(xrSession, gl);
Specifications
Browser compatibility
See also
- WebGLRenderingContext.makeXRCompatible()
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
