HTMLCanvasElement: webglcontextlost イベント
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
webglcontextlost は WebGL API のイベントで、WebGLRenderingContext オブジェクトに関連づけられた描画バッファーが失われたことをユーザーエージェントが検出した場合に発行されます。
このイベントはバブリングしません。
構文
このイベント名を addEventListener() などのメソッドで使用したり、イベントハンドラープロパティを設定したりしてください。
js
addEventListener("webglcontextlost", (event) => {}); onwebglcontextlost = (event) => {}; イベント型
WebGLContextEvent です。Event を継承しています。
イベントプロパティ
このインターフェイスには親インターフェイスである Event から継承したプロパティもあります。
WebGLContextEvent.statusMessage-
読み取り専用のプロパティで、イベントに関する追加情報を保持します。
例
WEBGL_lose_context 拡張機能の助けにより、webglcontextlost イベントをシミュレートすることができます。
js
const canvas = document.getElementById("canvas"); const gl = canvas.getContext("webgl"); canvas.addEventListener("webglcontextlost", (event) => { console.log(event); }); gl.getExtension("WEBGL_lose_context").loseContext(); // "webglcontextlost" event is logged. 仕様書
| Specification |
|---|
| WebGL Specification> # 5.15.2> |