GPUCanvasContext: getConfiguration() 方法
注意:此功能在 Web Workers 中可用。
GPUCanvasContext 接口的 getConfiguration() 方法返回为上下文设置的当前配置。
语法
js
getConfiguration()
参数
无。
返回值
返回一个包含为上下文设置的配置选项的对象(即通过 GPUCanvasContext.configure() 方法设置),如果未设置配置(之前未设置配置,或者设置配置后调用了 GPUCanvasContext.unconfigure()),则返回 null。
示例
js
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": []
}
*/
规范
| 规范 |
|---|
| WebGPU # dom-gpucanvascontext-getconfiguration |
浏览器兼容性
加载中…