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

WEBGL_lose_context 是属于 WebGL API 的一个扩展API,它提供一组方法用来模拟一个 {{domxref("WebGLRenderingContext")}} 上下文的丢失和恢复。

+ +

WebGL扩展可以通过 {{domxref("WebGLRenderingContext.getExtension()")}} 方法来使用。更多信息可参阅 WebGL教程 中的 使用WebGL扩展 。

+ +
+

可用性:该扩展在 {{domxref("WebGLRenderingContext", "WebGL1", "", 1)}} 和 {{domxref("WebGL2RenderingContext", "WebGL2", "", 1)}} 上下文中都是可用的。

+
+ +

方法

+ +
+
{{domxref("WEBGL_lose_context.loseContext()")}}
+
模拟上下文丢失。
+
{{domxref("WEBGL_lose_context.restoreContext()")}}
+
模拟上下文恢复。
+
+ +

示例

+ +

使用这个扩展,你可以模拟 {{Event("webglcontextlost")}} 和 {{Event("webglcontextrestored")}} 事件:

+ +
var canvas = document.getElementById('canvas');
+var gl = canvas.getContext('webgl');
+
+canvas.addEventListener('webglcontextlost', function(e) {
+  console.log(e);
+}, false);
+
+gl.getExtension('WEBGL_lose_context').loseContext();
+
+// 打印了 "webglcontextlost" 类型的 WebGLContextEvent 事件。
+
+ +

规范

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('WEBGL_lose_context', "", "WEBGL_lose_context")}}{{Spec2('WEBGL_lose_context')}}初始定义
+ +

浏览器兼容性

+ + + +

{{Compat("api.WEBGL_lose_context.loseContext")}}

+ +

参阅

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