here is one
const adapter = await navigator.gpu.requestAdapter();
if (!adapter) throw new Error("no WebGPU adapter");
const device = await adapter.requestDevice();
const win = new Deno.BrowserWindow({
title: "Raw Backend",
width: 800,
height: 600,
});
const surface = win.getNativeWindow();
surface.width = 800;
surface.height = 600;
const fmt = navigator.gpu.getPreferredCanvasFormat();
const context = surface.getContext("webgpu") as GPUCanvasContext;
context.configure({ device, format: fmt, alphaMode: "opaque" });
let hue = 0;
setInterval(() => {
hue = (hue + 0.5) % 360;
const r = Math.sin(hue * Math.PI / 180) * 0.5 + 0.5;
const g = Math.sin((hue + 120) * Math.PI / 180) * 0.5 + 0.5;
const b = Math.sin((hue + 240) * Math.PI / 180) * 0.5 + 0.5;
const encoder = device.createCommandEncoder();
const textureView = context.getCurrentTexture().createView();
const pass = encoder.beginRenderPass({
colorAttachments: [{
view: textureView,
clearValue: { r, g, b, a: 1.0 },
loadOp: "clear",
storeOp: "store",
}],
});
pass.end();
device.queue.submit([encoder.finish()]);
surface.present();
}, 16);
here is one