安全上下文
此特征只可用于 安全上下文 (HTTPS),在某些或所有 支持浏览器 .

WebXR 设备 API XRWebGLLayer() constructor creates and returns a new XRWebGLLayer object, providing the linkage between the WebXR device and the WebGL graphics layer used to render the 3D scene.

句法

let glLayer = new XRWebGLLayer(session, context, layerInit);
					

参数

session
XRSession object specifying the WebXR session which will be rendered using the WebGL context.
context
WebGLRenderingContext or WebGL2RenderingContext identifying the WebGL drawing context to use for rendering the scene for the specified WebXR session.
layerInit 可选

An object conforming to the XRWebGLLayerInit dictionary, providing configuration options for the new XRWebGLLayer . The options available are:

alpha 可选
The frame buffer's color buffer will be established with an alpha channel if the alpha Boolean property is true . Otherwise, the color buffer will not have an alpha channel. The default value is true .
antialias 可选
A Boolean value which is true if anti-aliasing is to be used when rendering in the context; otherwise false . The browser selects the anti-aliasing method to use; there is no support for requesting a specific mode yet.  The default value is true .
depth 可选
A Boolean value which, if true , requests that the new layer have a depth buffer; otherwise, no depth layer is allocated. The default is true .
framebufferScaleFactor 可选
A floating-point value which is used to scale the image during compositing, with a value of 1.0 represents the default pixel size for the frame buffer. The static XRWebGLLayer function XRWebGLLayer.getNativeFramebufferScaleFactor() returns the scale that would result in a 1:1 pixel ratio, thereby ensuring that the rendering is occurring at the device's native resolution. The default is 1.0.
ignoreDepthValues 可选
A Boolean value which indicates whether or not to ignore the contents of the depth buffer while compositing the scene. The default is false .
stencil 可选
A Boolean value which, if true , requests that the new layer include a stencil buffer. Otherwise, no stencil buffer is allocated. The default is false .

返回值

A newly-created XRWebGLLayer which links the specified XRSession to the WebGL context given by context , which will be used as the renderer for the session. Any options specified in layerInit are used to tailor the rendering system's configuration.

异常

InvalidStateError

新的 XRWebGLLayer could not be created due to one of a number of possible state errors:

  • XRSession 指定通过 session has already been stopped.
  • The specified WebGL context, context , has been lost for any reason, such as a GPU switch or reset.
  • 指定 session is immersive but the context is not WebXR compatible.
OperationError

The resources (including memory buffers) needed for the layer to operate could not be allocated.

规范

规范 状态 注释
WebXR 设备 API
The definition of 'XRWebGLLayer()' in that specification.
工作草案 初始定义。

浏览器兼容性

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
XRWebGLLayer() 构造函数 Chrome 79 Edge 79 Firefox No IE No Opera No Safari No WebView Android No Chrome Android 79 Firefox Android No Opera Android No Safari iOS No Samsung Internet Android 11.2

图例

完整支持

完整支持

不支持

不支持

另请参阅

元数据

  • 最后修改: