Java2D not using OpenGL randomly?

Hello,
The game I am working on uses the javafx Canvas class and the BufferStrategy you get from it to draw to the screen. Normally, this uses the GPU, but occasionally, it stops being able to and uses CPU based methods (I have determined this by using the “sun.java2d.trace” system property which shows the draw operations). It’s not a per-execution thing either, as once it stops working once, no other instance of the game uses OpenGL to render until I restart the computer. After that, it will use OpenGL again.

Has anybody else had this problem, and does anybody have any ideas as to how to fix it?

Hi Cygnus,
It sounds like you’re already knowledgeable of Java2D and it’s limitations given the fact that you’re aware of the ‘trace’ debugging option. So that probably means that I’ve got little new information to offer, but here are some ideas.
Not all operations in Java2D are hardware accelerated using OpenGL. I haven’t looked at openGL in a number of years, but in the old days image rotation and translucent images were not hardware accelerated. Perhaps you’re rotating or painting translucent images? See here for some discussion:
http://www.oracle.com/technetwork/java/javase/java2d-142140.html#gcrvb
There are other reasons why hardware acceleration may not work too, such as driver problems and running out of VRAM.
Brackeen’s excellent book has some general information on this topic:
https://books.google.com.au/books?id=dOz-UK8Fl_UC&lpg=PA122&ots=ahiiWu4GnH&dq=java%202d%20rotate%20opengl%20hardware%20acceleration&pg=PA122#v=onepage&q=java%202d%20rotate%20opengl%20hardware%20acceleration&f=false

Another possibility is that it’s due to your computer having two graphics cards where one supports openGL and the other doesn’t. There’s some info here about setting the which GPU to use with which program:


Cheers,
Keith

I am doing painting of translucent images and rotation, but the strange thing is even drawing normal textures with no rotation or translucency becomes unaccelerated. It’s definitely not related to rotating images, as I’ve had those in the game for a long time, but it is possible that translucent images could be causing this. If Java2D accelerates transparent images but not translucent, that might make sense, as I’ve had images with full transparency for a while but only fairly recently have I added translucency. I’ll have to test this.

It’s not multiple GPUs (I have one), nor is it running out of VRAM (I have like 6GB). If it is a driver problem then I’m not sure how to verify that, maybe testing on other systems, but the problem with that is I still don’t know what causes the deceleration of the game; it just happens after some time.
Thank you for your help,
cygnus