plasma-arc / wgpu-device.js
p3nGu1nZz's picture
🔧 Refactor vertex size calculation in config
594b86d
raw
history blame contribute delete
648 Bytes
// wgpu-device.js
export async function initializeDevice(state) {
state.webgpu.context = state.canvas.getContext('webgpu');
state.webgpu.device = await state.webgpu.adapter?.requestDevice();
if (!state.webgpu.device) {
alert('need a browser that supports WebGPU');
state.webgpu.device = null;
state.webgpu.context = null;
state.webgpu.presentationFormat = null;
return;
}
state.webgpu.presentationFormat = navigator.gpu.getPreferredCanvasFormat();
state.webgpu.context.configure({
device: state.webgpu.device,
format: state.webgpu.presentationFormat,
});
}