I simply dunno why the JAVA2D renderer would happen to be faster than the P2D 1!
But the king of performance is the FX2D renderer FYI: size(800, 700, FX2D);
The answer is quite simple - P2D and P3D use OpenGL which is very slow rendering lines and very fast at filling areas so change the display method in Bubble class to
void display() {
fill(c);
noStroke();
circle(x, y, 2*r);
}
That’s part of it, but this is also due to the implementation of line drawing in P2D which favours accuracy over performance. There’s a bit more info in Performance troubles in P2D that’s worth a read. There’s an out of date code branch somewhere based on that issue - keep meaning to try updating it for latest Processing.
It’s stroke weights higher than 1 that are particularly affected. The default stroke weight keeps to 60fps easy here.
Incidentally, another workaround with P2D is to do -
void display() {
noStroke();
fill(0);
circle(x, y, 2*r+1);
fill(c);
circle(x, y, 2*r);
}
Thanks, the FX2D is truly the king!!!
Like Neilcsmith and Quark said, it is the stroke weight makes the difference. Particularly when stroke weight higher than 1(default stroke weight).
I did some test, this is the number of bubbles makes the FPS slower than 30 in diffrent renderer and stroke weight.
This has been bugging me, because frankly I don’t believe the figures - I think there’s more to it. One thing to be aware of with JavaFX is that unlike the OpenGL pipelines it’s not single threaded. Something that has caused a whole lot of issues with a recent client project I did, and I think is behind those figures - they’re going to be different, but not that different.
With P2D and P3D all your calculations and rendering happen on the animation thread. With JavaFX, drawing calls are batched up, then another thread handles rendering asynchronously. I have a feeling your figures might be reflecting just the framerate of batching up the data, not actually rendering it to the screen. It’s likely JavaFX is just throwing some frames away.
Note also this from the Javadoc of the JavaFX GraphicsContext used by Processing -
Each call pushes the necessary parameters onto the buffer where they will be later rendered onto the image of the Canvas node by the rendering thread at the end of a pulse.
I’m just a beginner, don’t know much about the principles behind it.
When I test it, I set the for loop to increase 1000 bubbles a click. With other renderer, the animation soon get slower. FX2D just get stuck a while when I increase the bubbles, then the screen looks fluently as the animation runs beginning.
No problem! In general, if you get outlier figures, always question why. Like you did with P2D, and the issue linked before is probably the cause there.
With FX2D, why would it be so much different? The possible answer is always that you’re not measuring what you think you are. Unlike the other renderers, I don’t think Processing’s framerate value with FX2D is really the number of frames being rendered per second. For that I think you’d need to get the value directly from JavaFX itself, and offhand I can’t remember an easy way to do that.