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
(en-US) 事件:
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 |
---|
WebGL WEBGL_lose_context Khronos Ratified Extension Specification |
浏览器兼容性
BCD tables only load in the browser