with the PGraphics class, is there a way to read pixles as they get drawn?
for example
PGraphics c;
void settings() {
size(100, 100, P3D);
}
void setup() {
c = createGraphics(100,100, P3D);
c.beginDraw();
}
void draw() {
c.background(255);
// read pixels
c.background(100, 100, 100);
// read pixels
}
i want to do this in order to, for example, eliminate the need to do beginDraw and endDraw every single time i want to update and display my pixels
as i am thinking that i could thus copy the live pixels from the PGraphics object into a PImage and then image that similar to how most renderers will directly access the graphics (stack?) buffer to update the screen and just grab what ever may be there even while a draw may be executing (single buffered)
as this is the only way i can think of that will speed up my rendering when
for example, rendering 2500 PGraphics objects, calling beginDraw(); /* ... */; endDraw();
makes my fps go to about 7 FPS
NOTE: loadPixels internally calls beginDraw and endDraw so this will add additional overhead and thus be ineffective - https://github.com/processing/processing/blob/78f7c30076de3f9a24536913249009be7e543a6b/core/src/processing/opengl/PGraphicsOpenGL.java#L5378
example:
PGraphics g1, g2;
void settings() {
size(400, 400, P3D);
}
void setup() {
background(0);
g1 = createGraphics(500,500, P3D);
g1.beginDraw();
g2 = createGraphics(500,500, P3D);
g2.beginDraw();
}
void draw() {
g2.clip(0,0,50,50);
g2.background(0, 128, 128);
g2.clip(0,0,25,25);
g2.background(0);
g2.clip(35,35,65,65);
g2.background(0, 228, 128);
g2.clip(0,0,50,50);
g2.flush();
g1.image(g2.get(0,0,500,500), 0, 0);
g1.flush();
image(g1.get(0,0,500,500), 0, 0);
}