WEBGL_lose_context
WEBGL_lose_context 是属于 WebGL API 的一个扩展API,它提供一组方法用来模拟一个 WebGLRenderingContext
上下文的丢失和恢复。
WebGL扩展可以通过 WebGLRenderingContext.getExtension()
方法来使用。更多信息可参阅 WebGL教程 中的 使用WebGL扩展 。
方法
WEBGL_lose_context.loseContext()
- 模拟上下文丢失。
WEBGL_lose_context.restoreContext()
- 模拟上下文恢复。
示例
使用这个扩展,你可以模拟 webglcontextlost
和 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 事件。
规范
Specification | Status | Comment |
---|---|---|
WEBGL_lose_context WEBGL_lose_context |
Recommendation | 初始定义 |
浏览器兼容性
BCD tables only load in the browser
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.