WEBGL_lose_context 擴充套件
WEBGL_lose_context 擴充套件是 WebGL API 的一部分,它公開了用於模擬丟失和恢復 WebGLRenderingContext 的函式。
可以使用 WebGLRenderingContext.getExtension() 方法來訪問 WebGL 擴充套件。有關更多資訊,請參閱 WebGL 教程中的 使用擴充套件。
例項方法
WEBGL_lose_context.loseContext()-
模擬丟失上下文。
WEBGL_lose_context.restoreContext()-
模擬恢復上下文。
示例
使用此擴充套件,您可以模擬 webglcontextlost 和 webglcontextrestored 事件
js
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.
規範
| 規範 |
|---|
| WebGL WEBGL_lose_context Khronos 批准的擴充套件規範 |
瀏覽器相容性
載入中…