HTMLCanvasElement: webglcontextrestored イベント
webglcontextrestored は WebGL API インターフェイスのイベントで、ユーザーエージェントが WebGLRenderingContext オブジェクトの描画バッファーを復元したときに発行されます。
コンテキストが復元されると、コンテキストが失われる前に作成したテクスチャやバッファーなどの WebGL リソースは使えなくなります。WebGL アプリケーションの状態を再初期化し、リソースを再作成する必要があります。
このイベントはバブリングしません。
構文
このイベント名を addEventListener() などのメソッドで使用したり、イベントハンドラープロパティを設定したりしてください。
js
addEventListener("webglcontextrestored", (event) => {});
onwebglcontextrestored = (event) => {};
イベント型
WebGLContextEvent (en-US) です。Event を継承しています。
イベントプロパティ
このインターフェイスには親インターフェイスである Event から継承したプロパティもあります。
WebGLContextEvent.statusMessage(en-US)-
読み取り専用のプロパティで、イベントに関する追加情報を保持します。
例
WEBGL_lose_context (en-US) 拡張機能の助けにより、webglcontextrestored イベントをシミュレートすることができます。
js
const canvas = document.getElementById("canvas");
const gl = canvas.getContext("webgl");
canvas.addEventListener(
"webglcontextrestored",
(e) => {
console.log(e);
},
false
);
gl.getExtension("WEBGL_lose_context").restoreContext();
// "webglcontextrestored" event is logged.
仕様書
| Specification |
|---|
| WebGL Specification # 5.15.3 |
ブラウザーの互換性
BCD tables only load in the browser