function rasterGL({ width, height, fill, dpr = window.devicePixelRatio || 1 }) {
const canvas = document.createElement("canvas");
const scaledWidth = width * dpr;
const scaledHeight = height * dpr;
canvas.width = scaledWidth;
canvas.height = scaledHeight;
canvas.style.width = width + "px";
canvas.style.height = height + "px";
const regl = create({ canvas });
const draw = regl({
frag: `
precision mediump float;
uniform vec2 cm_resolution;
uniform float cm_time;
${fill}
`,
vert: `
precision mediump float;
attribute vec2 position;
void main() {
gl_Position = vec4(position, 0, 1);
}
`,
attributes: {
position: regl.buffer([
[-1, 1],
[1, 1],
[1, -1],
[1, -1],
[-1, -1],
[-1, 1]
])
},
uniforms: {
cm_resolution: regl.prop("cm_resolution"),
cm_time: regl.prop("cm_time")
},
count: 6
});
regl.frame(({ time }) => {
draw({
cm_resolution: [scaledWidth, scaledHeight],
cm_time: time
});
});
invalidation.then(() => regl.destroy());
return canvas;
}