gomeboycolor-wasm
gomeboycolor-wasm copied to clipboard
suggestion on screenUpdate
From your blogpost:
Drawing an array of pixels seemed like a prime candidate for the HTML5 canvas API, constructing an ImageData object and repainting on every frame update. When trying this though, using the go syscall/js package, the performance was abysmal, eventually causing the browser tab to freeze. `
I ran into this aswell when porting something to wasm. slow and browser tab freeze. eventually got around it by using this:
s := time.Now()
buf := js.TypedArrayOf(g.Image.Pix) # g.Image being *image.RGBA
defer buf.Release()
imageData := g.ctx.Call("getImageData", 0, 0, g.Width, g.Height)
imageData.Get("data").Call("set", buf)
g.ctx.Call("putImageData", imageData, 0, 0)
fmt.Println("putImageData", time.Since(s))
with a 600x500 image it outputs putImageData 2.899712ms
hope this helps, can close the issue anyhow :)