WEBGL_lose_context

WEBGL_lose_context extension is part of the WebGL API and exposes functions to simulate losing and restoring a WebGLRenderingContext .

WebGL extensions are available using the WebGLRenderingContext.getExtension() method. For more information, see also Using Extensions WebGL tutorial .

Availability: This extension is available to both, WebGL1 and WebGL2 contexts.

方法

WEBGL_lose_context.loseContext()
Simulates losing the context.
WEBGL_lose_context.restoreContext()
Simulates restoring the context.

范例

With this extension, you can simulate the webglcontextlost and webglcontextrestored events:

const canvas = document.getElementById('canvas');
const gl = canvas.getContext('webgl');
canvas.addEventListener('webglcontextlost', (event) => {
  console.log(event);
});
gl.getExtension('WEBGL_lose_context').loseContext();
// WebGLContextEvent event with type "webglcontextlost" is logged.
					

规范

规范 状态 Comment
WEBGL_lose_context
The definition of 'WEBGL_lose_context' in that specification.
Recommendation 初始定义。

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
loseContext Chrome Yes Edge 17 Firefox 22
22
不支持 19 — 58
Prefixed
Prefixed Implemented with the vendor prefix: MOZ_
IE ? Opera Yes Safari ? WebView Android Yes Chrome Android Yes Firefox Android ? Opera Android Yes Safari iOS ? Samsung Internet Android Yes

图例

完整支持
完整支持
兼容性未知
兼容性未知
要求使用供应商前缀或不同名称。
要求使用供应商前缀或不同名称。

另请参阅