Programming => OpenGL => Topic started by: ac on May 13, 2013, 18:34:15

Title: choppy rendering on OSX when using GLCanvas
Post by: ac on May 13, 2013, 18:34:15
Hello, I'm running this raymarching effect from shadertoy: https://www.shadertoy.com/view/MdX3Rr, in a Java program where the rendering takes place inside a GLCanvas (which I set as the parent of the Display object), and the rendering is very choppy.

My test system is a macbook pro with OSX 10.8.3 and a Radeon HD 6490M video card. On shadertoy, the effect runs slow (~14fps, as it is very fragment-shader intensive), but the rendering is reasonably smooth. In a simple LWJGL program without canvas (just a barebones loop adapted from the basic LWJGL examples), the rendering is also smooth.

But when I run this effect in a more complex Java program where I use a GLCanvas as the parent for the LWJGL display (same machine, LWJGL 2.9.0), the rendering stutters significantly. One strange thing is that the fps, as calculated from the Java application, is similar to the fps reported by shadertoy.

It seems to me that there is some threading issue going on, but not sure how to debug it. The GLCanvas is attached to an Applet object, which in turn is inside an AWT Frame. Maybe this structure is conflicting with LWJGL's rendering mechanism? I run the program both with Java 6 and 7, and the stuttering doesn't change.

Just in case anyone wants to take a look, the code for the simple LWJGL program (no GLCanvas) is here:


while the program that uses GLCanvas is the following:


Any help and/or comments will be highly appreciated.

Title: Re: choppy rendering on OSX when using GLCanvas
Post by: ac on May 14, 2013, 16:04:59
I put my code inside the Basic LWJGL Applet template (http://www.lwjgl.org/wiki/index.php?title=Basic_LWJGL_Applet), in order to check if the problem was due to the use of the Frame. But I still get stuttering and, interestingly, across different versions of OSX from 10.6 to 10.8. This is my modified applet code:


Maybe I should go ahead and open a bug report about this issue?
Title: Re: choppy rendering on OSX when using GLCanvas
Post by: ac on May 16, 2013, 15:55:29
As the issue appears to be reproducible across several versions of OSX, Java and hardware, I just went ahead and opened a bug report on github:


Title: Re: choppy rendering on OSX when using GLCanvas
Post by: kappa on May 16, 2013, 16:14:55
Unfortunately the poor performance when using AWT/Swing isn't really a bug but due to the changes made by Apple/Oracle to AWT/Swing (moving from NSView to CALayer embedding and removing the NSView option altogether) its no longer technically possible to get the speeds with OpenGL we previously enjoyed with LWJGL (2.8.5 and lower). This is because content needs to be drawn at least twice due to the way CALayers work.

As for running in the browser all plugins must now use CALayer's on OS X including Java, probably why you get similar results with shadertoy (as WebGL will go through the same path). Avoiding AWT/Swing and using the native Display window is the fastest way as it bypasses the requirements to use CALayer's.
Title: Re: choppy rendering on OSX when using GLCanvas
Post by: ac on May 17, 2013, 20:34:55
Thanks for the explanation. Quick question, when you say that the "content needs to be drawn at least twice due" you specifically mean the GL rendering code is executed twice each frame for AWT/Swing? If the GL output is initially rendered into an offscreen texture, couldn't the second draw just consists in rendering this texture?

Just as a clarification, shadertoy runs smoothly, at par with the LWJGL application that uses the native Display. The stuttering problem occurs with anything that puts the canvas inside an Applet object, irrespective of whether it runs as an applet through the Applet Viewer (I didn't test embedding inside an html and running it in the browser, although I expect similar results as with the Viewer), or as a stand-alone application where the Applet object is contained inside a frame.