From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../getcontextattributes/index.html | 79 ++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 files/zh-cn/web/api/webglrenderingcontext/getcontextattributes/index.html (limited to 'files/zh-cn/web/api/webglrenderingcontext/getcontextattributes/index.html') diff --git a/files/zh-cn/web/api/webglrenderingcontext/getcontextattributes/index.html b/files/zh-cn/web/api/webglrenderingcontext/getcontextattributes/index.html new file mode 100644 index 0000000000..a7eccd10a4 --- /dev/null +++ b/files/zh-cn/web/api/webglrenderingcontext/getcontextattributes/index.html @@ -0,0 +1,79 @@ +--- +title: WebGLRenderingContext.getContextAttributes() +slug: Web/API/WebGLRenderingContext/getContextAttributes +translation_of: Web/API/WebGLRenderingContext/getContextAttributes +--- +
{{APIRef("WebGL")}}
+ +

WebGLRenderingContext.getContextAttributes() 方法返回一个包含实际上下文参数的 WebGLContextAttributes 对象。如果上下文丢失,可能返回 {{jsxref("null")}}。

+ +

语法

+ +
gl.getContextAttributes();
+ +

返回值

+ +

一个包含实际上下文参数的 WebGLContextAttributes 的对象,或 {{jsxref("null")}} (如果上下文丢失)。

+ +

实例

+ +

给定 {{HTMLElement("canvas")}} 元素

+ +
<canvas id="canvas"></canvas>
+
+ +

和给定 WebGL 上下文

+ +
var canvas = document.getElementById('canvas');
+var gl = canvas.getContext('webgl');
+gl.getContextAttributes();
+
+ +

getContextAttributes 方法返回描述在此上下文中设置的属性的对象,例如:

+ +
{
+  alpha: true,
+  antialias: true,
+  depth: true,
+  failIfMajorPerformanceCaveat: false,
+  premultipliedAlpha: true,
+  preserveDrawingBuffer: false,
+  stencil: false
+}
+ +

上下文的属性可以在用 {{domxref("HTMLCanvasElement.getContext()")}} 方法创建上下文时设置:

+ +
canvas.getContext('webgl',
+                 { antialias: false,
+                   depth: false });
+ +

有关各个属性的更多信息,请参阅 {{domxref("HTMLCanvasElement.getContext()", "getContext()")}}。

+ +

规范

+ + + + + + + + + + + + + + +
规范状态注释
{{SpecName("WebGL", "#5.14.2", "WebGLRenderingContext.getContextAttributes")}}{{Spec2("WebGL")}}初始定义
+ +

浏览器兼容性

+ + + +

{{Compat("api.WebGLRenderingContext.getContextAttributes")}}

+ +

另请参阅

+ + -- cgit v1.2.3-54-g00ecf