WebGLRenderingContext: getContextAttributes() 方法
注意:此功能在 Web Workers 中可用。
WebGLRenderingContext.getContextAttributes() 方法返回一个 WebGLContextAttributes 对象,其中包含实际的上下文参数。如果上下文丢失,则可能返回 null。
语法
js
getContextAttributes()
参数
无。
返回值
一个 WebGLContextAttributes 对象,其中包含实际的上下文参数,或者在上下文丢失时返回 null。
示例
给定此 <canvas> 元素
html
<canvas id="canvas"></canvas>
并给定此 WebGL 上下文
js
const canvas = document.getElementById("canvas");
const gl = canvas.getContext("webgl");
gl.getContextAttributes();
getContextAttributes 方法返回一个对象,该对象描述了设置在此上下文上的属性,例如
json
{
"alpha": true,
"antialias": true,
"depth": true,
"failIfMajorPerformanceCaveat": false,
"powerPreference": "default",
"premultipliedAlpha": true,
"preserveDrawingBuffer": false,
"stencil": false,
"desynchronized": false
}
上下文属性可以在使用 HTMLCanvasElement.getContext() 方法创建上下文时设置
js
canvas.getContext("webgl", { antialias: false, depth: false });
有关各个属性的更多信息,请参阅 getContext()。
规范
| 规范 |
|---|
| WebGL 规范 # 5.14.2 |
浏览器兼容性
加载中…