How to use a pshape inside a PGraphics element?

edited March 2018 in Questions about Code

What is the proper way to do this? Normally I can just draw for example PGraphics canvas;

void setup() {
  size (100, 100);
  canvas = createGraphics(width, height);
}

void draw() {

  canvas.beginDraw();
  canvas.fill(255);
  canvas.stroke(255, 0, 0);
  canvas.ellipse(50, 50, 25, 25);
  canvas.endDraw();
  image(canvas, 0, 0);
}

If I replace this with:

PGraphics canvas;
PShape circle;

void setup() {
  size (100, 100);
  canvas = createGraphics(width, height);
}

void draw() {

  canvas.beginDraw();
  circle.setFill(color(255));
  circle.setStroke(color(255, 0, 0));
  circle = createShape(ELLIPSE, 50, 50, 25, 25);
  canvas.endDraw();
  image(canvas, 0, 0);
}

I get worse performance, I was under the impression that it was more efficient to use Pshapes.

I need to change to PShapes because I suspect android openGL render has a hard time with stroke, I get 1.5 fps with OPENGL on android and 7fps with JAVA2D. Also I need the Pshapes to be different sizes and colors in an array.

Tagged:

Answers

  • If the PShape is constant then you can create it once, in setup. Creating it every loop isn't going to gain you anything.

  • This is a lot of questions about the same piece of code, it's getting hard to follow.

    Try and keep it together more or close some of the dead ends.

  • edited March 2018

    So if for example you generated an array of bubbles with different sizes, there is no advantage to using PShapes, right? Is there another way around the stroke problem with android OPENGL like drawing circles under each other or changing the number of segments on a circle?

    I guess my main question is, are PShapes drawn to the Pgraphics canvas or are they done independently and that's why I'm noticing a slowdown when using them? Is there something like a canvas.shape to make the pshape draw inside the pgraphics object like canvas.ellipse would?

  • Well, of there's a limited number of sizes for your bubbles then you could have a PShape for each size and just draw the one you want.

    PShapes are geometry stored on the graphics card, like the old display lists in opengl, define them once, draw them many times without the overhead of sending the geometry to the card every time.

    Is there another way around the stroke problem with android OPENGL

    Do you have any evidence for this stroke problem?

  • edited March 2018

    I was just reading this thread where he noted worse performance in p2d/p3d than the java2d rendering engine in Android, and some people suggested it could be due to the stroke. And it occurred to me I've been using stroke to generate a lot of the effects and animation in my app. At 300px resolution I get 15 or so fps with default renderer but only 1 or 2fps with p2d/p3d. Really strange.

    https://github.com/processing/processing-android/issues/203

    Unfortunately for it to work my shapes need infinite variability because they change independently in a large array so unless I'm not understanding pshapes maybe it wouldn't work too well for me after all.

  • On desktop: JAVA2D = 15fps P3D = 35-40fps

    On android JAVA2D = 15fps; P3D = 1.5fps

    Not sure what is wrong, but something seems really strange with that.

Sign In or Register to comment.