I have been writing a Processing application/sketch in Eclipse (due to external libraries and heavy OOP) and stumbled upon this problem:
During the drawing process (initialized from a normal
draw() method in my PApplet subclass) I am delegating some functionality to a second class, which creates PGraphics and does some rendering on them:
PGraphics buffer = master.createGraphics(master.width, master.height, PConstants.P2D); buffer.beginDraw(); renderPage(page, buffer); //does some rendering on the buffer including draw calls, push/pop operations & translations, fill, stroke etc. buffer.endDraw();
(master is my PApplet subclass responsible for the screen)
The buffer is then drawn to the screen, sometimes with resizing.
The issue is the following: making the sketch use the “P2D” renderer (and the graphics buffer, as seen above) lowers the framerate to around 0.05-0.1 (one frame per 10-20 seconds).
frameRate(60) has absolutely no effect.
I have stepped through the code with the debugger and there is some semi-random behavior: at least one of the functions executing a draw call (such as
background()) take the observed 10-20 seconds to execute. This also occurs sometimes inside the
beginDraw() implementation of PGraphics2D (or PGraphicsOpenGL) where certain methods take a lot of time. After such a method was executed, all the rest of the frame is finished in no time at all (stepping is always finished before any noticeable slowdown).
It really depends on where I put the breakpoints, and time measurement with
System.currentTimeMillis() only measures up to 20ms for even the heaviest draw methods, so I am very sure the issue is not in these self-written methods.
Funny thing is: When I change all renderers to
JAVA2D, my program runs at full 60fps with no slowdown whatsoever. Luckily, the application does not require
P2D, so I will stick with the default renderer for now.
My point is: Am I doing something wrong or is Eclipse or the JRE not liking the P2D?
I have included Processing 3.3.6 as a User Library, with referenced source folders (this is working correctly). I have added the core.jar as well as gluegen-rt.jar and jogl-all.jar. For both the /core/library directory is referenced as the Native Library Location. Using the special native JAR’s for my architecture (Windows 10 x64 (64 bit) so the natives-windows-i586 jars) directly in both cases leads to
Both Java 10.0.1 and Java 1.8 have the same exact issue, although there is a reflect warning thrown for Java 10 from the JOGL library (probably has to do with compliance etc. but again, Java 1.8 does not solve the issue).
Thanks in advance!