Page 2 of 2

Re: Is there something like Canvas:overwriteOldImageData() ?

Posted: Thu Mar 01, 2018 5:23 pm
by raidho36
You know you can do it fairly easily just by doing some math, right? Take a look at "shapes" section of this touchscreen library https://github.com/raidho36/love-multitouch it does exactly what you're doing, but without touching the GPU. And it's pretty fast, on account of being designed specifically for mobile, and can even return back the mouse/touch position in local coordinates, even if the element is transformed arbitrarily.

Re: Is there something like Canvas:overwriteOldImageData() ?

Posted: Thu Mar 01, 2018 5:58 pm
by no_login_found
raidho36 wrote: Thu Mar 01, 2018 5:23 pm Take a look at "shapes" section of this touchscreen library https://github.com/raidho36/love-multitouch it does exactly what you're doing, but without touching the GPU.
Ok, thanks for the link. However at the moment I want to go neither geometry path nor third-party lib path.

Re: Is there something like Canvas:overwriteOldImageData() ?

Posted: Thu Mar 01, 2018 7:36 pm
by raidho36
As per MIT license, you can take any and all parts of the code and do with them as you see fit.

Anyway as I said originally, you don't need to read any of the pixels from GPU back to RAM, that's just unnecessary waste of performance. There's no such scenario where this approach outperforms basic geometry hit testing, simply due to GPU calls overhead.

As a final note, there's a saying "faster computational hardware is offset by programmers that write slower software". It exists for this very reason. Don't be that programmer.