jogl performance

I’ve read Kevin Glass’s tutorial about refactoring space invaders to use OpenGL from Java2D to render to screen. (http://www.cokeandcode.com/info/tut2d-3.html)

It provides a link to see the difference between the Java2D version and the JOGL version. The thing is that the Java2D version actually runs faster on my machine! (tested it with the latest versions of Sun jvm 1.5 and 1.4)

Maybe this is caused because jogl uses native (jni?) calls that degrade the performance compared to Java2D? Because I believe Java2D uses OpenGL too under the hood (when available), which may not suffer from this overhead?

And if Java2D can use opengl, why don’t they make an pure java opengl binding which doesn’t require any external native libs?

Depending on your graphics card and OpenGL drivers you may see differing results. On Windows Java2D uses its DirectDraw pipeline by default, and on X11 platforms its X pipeline; you currently have to manually enable the Java2D OpenGL pipeline with -Dsun.java2d.noddraw=true. With a card with decent OpenGL support and a sufficiently complex scene you should be able to get faster performance for 3D-related operations from JOGL than Java2D.

Ah ok,

I run on windows xp, with a geforceFX5200.
So on my config 2d operations are faster using directdraw than with opengl. Is this the case on most systems? If so, i’d better stick to Java2d for my 2d library…

Maybe this is more a question for the performance board, but I’ve always wondered what the overhead is of using JNI calls for the opengl bindings… Is it noticable in the FPS? And doesn’t it create more garbage for the GC to cleanup?

Have you upgraded your OpenGL drivers to NVidia’s latest set? They are continually making performance improvements.

As long as you batch up your geometry and use vertex arrays or vertex buffer objects your Java code should run at exactly the same speed as the analogous C++ code. Our own experiments inside Sun have been unable to point a finger at JNI overhead as a principal bottleneck for Jake2 running on JOGL. Calling out through JNI creates no garbage inherently.

There’s no way that Java2D can beat handcrafted OpenGL code - there are too many hoops and niceties and generalisations. Something else is afoot.

Cas :slight_smile:

Do you guys get more fps in the opengl example then?
With my config (GeforceFX5200, latest nvidia drivers) I get with opengl: 74fps vs java2d: 100fps

For this simple example there is no way that it is either fill- or geometry-limited on your card. It is probably synced to the vertical refresh rate. You can disable this by going to Control Panel -> Display -> Settings -> Advanced -> NVidia tab -> OpenGL settings -> and choosing “Always off” for the Vertical Sync setting. The Space Invaders demo doesn’t seem to start properly when this property is disabled but other OpenGL applications do.

Yup, tested it and it was synced to the monitor refresh rate!

Thanks for pointing that out, now I can proceed without worries to add JOGL support for my 2d engine :wink: