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 |
瀏覽器相容性
載入中…