Closed diwi closed 6 years ago
the base loadPixels() call does not take any arguments: https://p5js.org/reference/#/p5/loadPixels if loadPixels() is called on the GL renderer directly, the arguments are taken into consideration. https://github.com/processing/p5.js/blob/master/src/webgl/p5.RendererGL.js#L614 i think this is correct behavior? @mlarghydracept?
I think that was intentional back when I did it but I don't know if it makes sense in hindsight. My personal instinct is to say that it makes more sense to change it such that it always just pulls the whole canvas into pixels. It is already forcing the pixels array to be the size of the full canvas on this line. So the utility of grabbing a fragment becomes mostly non-existent.
for simplicity sake, that makes sense to me. we already have so many issues around pixels, pixel density, and canvas sizes. let's not complicate further if it's not adding a whole lot.
I had experimented a bit with loadpixels in this object-picking demo:
https://www.openprocessing.org/sketch/496458
You'll notice every couple of frame some stuttering (a ~150ms pause) which has to do with how loadPixels() is implemented. At first I thought it had to do with the amount of pixels to transfer from the gpu to the app, which is a costly operation and therefore it would be nice to have the x,y,w,h-arguments to defined a rectangle.
However I now had a closer look at the implementation, and now i think it's the GC. Loadpixels allocates a new array for the full frame every call, instead of reusing the same buffer.
Edit: Demo is updated with custom readPixels() to get rid of the framerate stuttering.
Good point! The data should be transferred directly from the gpu to the p5 instance's pixels array.
arguments are not passed to the subsequent renderer.loadPixels().
https://github.com/processing/p5.js/blob/master/src/image/pixels.js#L521
I feel like I have seen similar things a before but didnt keep track of it, so this is just a hint for a general check. Here is the updated version.