WEBGL_lose_context: restoreContext() 方法

Baseline 已廣泛支援

此功能已成熟,可跨多種裝置和瀏覽器版本工作。它自 ⁨2018 年 4 月⁩ 起已在所有瀏覽器中可用。

WEBGL_lose_context.restoreContext() 方法是 WebGL API 的一部分,它允許你模擬恢復 WebGLRenderingContext 物件的上下文。

語法

js
restoreContext()

引數

無。

返回值

無(undefined)。

異常

瀏覽器可能預設不報告 WebGL 錯誤。WebGL 的錯誤報告透過呼叫 getError() 並檢查錯誤來工作。可能會丟擲以下異常:

INVALID_OPERATION

如果上下文未丟失,則丟擲此異常。

示例

使用此方法,你可以模擬 webglcontextrestored 事件。

js
const canvas = document.getElementById("canvas");
const gl = canvas.getContext("webgl");

canvas.addEventListener("webglcontextrestored", (e) => {
  console.log(e);
});

gl.getExtension("WEBGL_lose_context").restoreContext();

規範

規範
WebGL WEBGL_lose_context Khronos 批准的擴充套件規範

瀏覽器相容性

另見