WebGLRenderingContext: getContextAttributes() method
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Note: This feature is available in Web Workers.
Phương thức WebGLRenderingContext.getContextAttributes() trả về một đối tượng WebGLContextAttributes chứa các tham số ngữ cảnh thực tế. Có thể trả về null, nếu ngữ cảnh bị mất.
Cú pháp
getContextAttributes()
Thông số
Không có.
Giá trị trả về
Một đối tượng WebGLContextAttributes chứa các tham số ngữ cảnh thực tế, hoặc null nếu ngữ cảnh bị mất.
Ví dụ
Cho phần tử <canvas> này
<canvas id="canvas"></canvas>
và đưa ra bối cảnh WebGL này
const canvas = document.getElementById("canvas");
const gl = canvas.getContext("webgl");
gl.getContextAttributes();
phương thức getContextAttributes trả về một đối tượng mô tả các thuộc tính được đặt trong ngữ cảnh này, ví dụ:
{
"alpha": true,
"antialias": true,
"depth": true,
"failIfMajorPerformanceCaveat": false,
"powerPreference": "default",
"premultipliedAlpha": true,
"preserveDrawingBuffer": false,
"stencil": false,
"desynchronized": false
}
Các thuộc tính ngữ cảnh có thể được thiết lập khi tạo ngữ cảnh bằng phương thức HTMLCanvasElement.getContext():
canvas.getContext("webgl", { antialias: false, depth: false });
Xem getContext() để biết thêm thông tin về các thuộc tính riêng lẻ.
Thông số kỹ thuật
| Specification |
|---|
| WebGL Specification> # 5.14.2> |