GPUCanvasContext: getConfiguration() Methode
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Sicherer Kontext: Diese Funktion ist nur in sicheren Kontexten (HTTPS) in einigen oder allen unterstützenden Browsern verfügbar.
Hinweis: Diese Funktion ist in Web Workers verfügbar.
Die getConfiguration()
Methode der GPUCanvasContext
Schnittstelle gibt die aktuelle Konfiguration zurück, die für den Kontext eingestellt ist.
Syntax
getConfiguration()
Parameter
Keine.
Rückgabewert
Ein Objekt, das die auf den Kontext gesetzten Konfigurationsoptionen enthält (d.h. über die GPUCanvasContext.configure()
Methode), oder null
, wenn keine Konfiguration eingestellt ist (entweder wurde zuvor keine Konfiguration gesetzt, oder eine Konfiguration wurde gesetzt und dann wurde GPUCanvasContext.unconfigure()
auf den Kontext angewendet).
Beispiele
const canvas = document.querySelector("canvas");
const context = canvas.getContext("webgpu");
if (!navigator.gpu) {
throw Error("WebGPU not supported.");
}
const adapter = await navigator.gpu.requestAdapter();
if (!adapter) {
throw Error("Couldn't request WebGPU adapter.");
}
const device = await adapter.requestDevice();
context.configure({
device,
format: navigator.gpu.getPreferredCanvasFormat(),
alphaMode: "premultiplied",
});
console.log(context.getConfiguration());
/* Logs something like:
{
"alphaMode": "premultiplied",
"colorSpace": "srgb",
"device": { ... },
"format": "bgra8unorm",
"toneMapping": {
"mode": "standard"
},
"usage": 16,
"viewFormats": []
}
*/
Spezifikationen
Specification |
---|
WebGPU # dom-gpucanvascontext-getconfiguration |