plasma-arc / wgpu-device.js
p3nGu1nZz's picture
✨ Updated state initialization and organized code
0870851
raw
history blame
696 Bytes
// wgpu-device.js
export async function initializeDevice(state) {
const context = state.canvas.getContext('webgpu');
const device = await state.webgpu.adapter?.requestDevice();
if (!device) {
alert('need a browser that supports WebGPU');
state.webgpu.device = null;
state.webgpu.context = null;
state.webgpu.presentationFormat = null;
return;
}
const presentationFormat = navigator.gpu.getPreferredCanvasFormat();
context.configure({
device,
format: presentationFormat,
});
state.webgpu.device = device;
state.webgpu.context = context;
state.webgpu.presentationFormat = presentationFormat;
}