WebGLRenderingContext: getContextAttributes()-Methode

Baseline Widely available

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

Hinweis: Diese Funktion ist in Web Workers verfügbar.

Die WebGLRenderingContext.getContextAttributes()-Methode gibt ein WebGLContextAttributes-Objekt zurück, das die tatsächlichen Kontextparameter enthält. Es kann null zurückgeben, wenn der Kontext verloren geht.

Syntax

js
getContextAttributes()

Parameter

Keine.

Rückgabewert

Ein WebGLContextAttributes-Objekt, das die tatsächlichen Kontextparameter enthält, oder null, wenn der Kontext verloren geht.

Beispiele

Angenommen, dieses <canvas>-Element

html
<canvas id="canvas"></canvas>

und der folgende WebGL-Kontext

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

Die getContextAttributes-Methode gibt ein Objekt zurück, das die für diesen Kontext festgelegten Attribute beschreibt, zum Beispiel:

js
{
  alpha: true,
  antialias: true,
  depth: true,
  failIfMajorPerformanceCaveat: false,
  powerPreference: "default",
  premultipliedAlpha: true,
  preserveDrawingBuffer: false,
  stencil: false,
  desynchronized: false
}

Die Kontextattribute können beim Erstellen des Kontexts mit der HTMLCanvasElement.getContext()-Methode festgelegt werden:

js
canvas.getContext("webgl", { antialias: false, depth: false });

Siehe getContext() für weitere Informationen zu den einzelnen Attributen.

Spezifikationen

Specification
WebGL Specification
# 5.14.2

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
getContextAttributes

Legend

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

Full support
Full support

Siehe auch