Java2D OpenGL Acceleration

The following quote is from Sun re J2SE 5.0:

[quote]Linux and Solaris users, and new in beta2, Windows users, who have the latest OpenGL drivers and select graphic cards can get native hardware acceleration from Java2D using the following runtime property:

java -Dsun.java2d.opengl=true -jar Java2D.jar
[/quote]
Does this mean that if I take my 1.4.2 Java2D game, and run it under 5.0 with the above switch I will automatically get OpenGL acceleration for free(assuming I have OpenGL drivers installed) ? In particular does this mean translucent images will be accelerated?

Yes, and yes, as long as you enable a translucency flag.

For opengl pipeline, you don’t have use the translucency flag to get accelerated alpha compositing (and it has no effect for the opengl pipeline).

Well, here’s a quick comparison between normal and opengl-enabled under 5.0 on my machine (AMD64 3000+, GeForce 6600GT):

Using “java ImageSpeedTest”:

Opaque: 3970.6667 images/sec
Transparent: 50370.0 images/sec
Translucent: 300.66666 images/sec
Translucent (Anti-Aliased): 374.0 images/sec

Using “java -Dsun.java2d.opengl=True ImageSpeedTest”:

OpenGL pipeline enabled for default config on screen 0
Opaque: 33.0033 images/sec
Transparent: 23219.334 images/sec
Translucent: 406.0 images/sec
Translucent (Anti-Aliased): 519.3333 images/sec

So opaque rendering is over 100 times slower with opengl and transparent is 50% slower. Translucent is slightly better. The code is from Brackeen’s book and simply spits sprites at the screen and counts the images/sec.

Are these strange figures or am I missing something? The opengl switch seems to slow down more than it speeds up!

First of all hello ^^ i’ve been lurking over here for long but this si my first post .

Well it hapens the same to me, with the opengl pipeline disabled my little rendering experiment in java2d runs at 50 - 33 fps, with opengl enabled it does at 0 fps (one if lucky) both on Winxp with a geforce 5200 suposed to support opengl

same here… well, looks like we’ve got something to look forward to in 6.0 :wink:

My impresion is that you on windows should use the directX based hardware acceleration instead of the openGL one.

i thought java was supposed to be os independant ;D

There are a couple different issues contributing to the poor performance numbers you’re seeing… First, it appears that we’re having a problem (in our image management code) that makes us unable to cache the opaque.png, translucent.png, and antialiased.png images from David’s testcase in hardware. This means that we end up using software loops to copy the images to the screen, which explains why (in both the OGL and non-OGL cases) we’re slow in the non-translucent cases.

The problem appears to be isolated to the old Toolkit image loaders (which ImageIcon uses currently). If you modify his testcase to use ImageIO (or simply “new BufferedImage()”), you’ll see that the numbers are much more reasonable. In any case, I’ll have to investigate this further.

Regarding the comparitively poor performance of the opaque case with OGL enabled… As I mentioned, due to the bug described above, we always copy the sysmem-based copy of the image to the destination (since we don’t have a copy cached in VRAM). There is a performance bug in Nvidia’s OGL drivers for Windows that makes this case extremely slow, thus the low scores with OGL enabled. Nvidia fixed this in their most recent Linux drivers (6629), and the fix should also be included in their next Windows release as well.

So here again are the dangers of microbenchmarking. Low scores in one case can lead people to believe that the whole pipeline is slow or broken, but that isn’t the case. I’m still hoping to post an article that shows how the performance of the OGL pipeline compares to our existing pipelines. I’ll let you know when that’s up…

Also, we have some big changes to both our OGL and D3D pipelines coming soon to a Mustang build near you… So you should see those scores continue to improve in 6.0… We’ll make an announcement when those changes are available in the early Mustang builds.

Chris

For the record, I tracked down the problem and filed a new bug (6231864), which will show up on the Bug Parade by tomorrow.

Chris

Interesting stuff Chris. I’ll try BufferedImage today as well.

I’ll stay tuned. thanks for the detailed reply ;D

Ok, just out of interest I used BufferedImages instead of Images in the test program, these are the results:

OpenGL/BufferedImage:

Opaque: 20784.666 images/sec
Transparent: 24412.666 images/sec
Translucent: 18764.0 images/sec
Translucent (Anti-Aliased): 23033.334 images/sec

non-OpenGL/BufferedImage:

Opaque: 38738.668 images/sec
Transparent: 50322.0 images/sec
Translucent: 50.666668 images/sec
Translucent (Anti-Aliased): 51.451187 images/sec

So we have much better translucent performance with OpenGL/BufferedImage than with OpenGL/Image. However OpenGL/BufferedImage is still slower than non-OpenGL/BufferedImage for opaque and transparent images in this particular test.

I know I shouldn’t microbenchmark, but I just can’t resist!

why are anti-aliased translucent images faster than non-anti-aliased ones? o_O

because AA images are not accerlated :wink: