WEBGL_lose_context: loseContext() Methode

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2018.

Die WEBGL_lose_context.loseContext()-Methode ist Teil der WebGL API und ermöglicht Ihnen eine Simulation des Verlusts des Kontextes eines WebGLRenderingContext-Kontextes.

Es löst die Schritte aus, die in der WebGL-Spezifikation zur Handhabung von verlorenem Kontext beschrieben sind. Der Kontext bleibt verloren, bis WEBGL_lose_context.restoreContext() aufgerufen wird.

Syntax

js
loseContext()

Parameter

Keine.

Rückgabewert

Keiner (undefined).

Beispiele

Mit dieser Methode können Sie das webglcontextlost Ereignis simulieren:

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

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

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

// WebGLContextEvent event with type "webglcontextlost" is logged.

Spezifikationen

Specification
WebGL WEBGL_lose_context Khronos Ratified Extension Specification

Browser-Kompatibilität

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
loseContext

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Requires a vendor prefix or different name for use.
Has more compatibility info.

Siehe auch