So what is VolatileImage exactly?
How is it different/better/worse than BufferedImage?
In early versions of Java, BufferedImages were not hardware accelerated. If you wanted acceleration, you used a VolatileImage, which represented an Image held in the graphics processor memory. However as that memory is of limited size, images that hadn’t been used recently got discarded to make room for new ones that needed to be drawn immediately. Thus before you use a VolatileImage, you had to check whether it has been discarded and if so recreate it.
In later versions of java, BufferedImages were extended to have hardware acceleration. Most useful is that when you draw a BufferedImage, it now automatically checks to see if the GPU copy has been discarded and automatically recreates it if necessary. The end result is that nowadays there is little point to using VolatileImages, as BufferedImages offer the same performance, but with less coding.
Edit: I just looked at the other thread, which said that in some cases volatile images were still faster than bufferedimages except in fullscreen. It looks to be graphics driver/card dependent. It maybe that BufferedImages use slightly different graphics calls, some of which are not hardware accelerated on some platforms. Similarly the graphics pipeline for fullscreen may fail to get hardware acceleration for some card related issue. Possibly the card doesn’t have enough memory in fullscreen mode and cannot cache all the images. Could happen if BufferStrategy is being used. The discard algorithm that BufferedImage uses may differ from a user defined scheme used with VolatileImages.
On Java 1.4.2 there was a bug that certain window sizes rendered slowly for no apparent reason. I added a frig that resized the window slightly if this appeared to be happening. This was not using VolatileImages so is probably unrelated.
Thanks!
This is a really clear explanation.
Another quick question:
What is the difference between double buffering:
-creating BufferedImage, drawing in it, drawImage() onto screen,
-using BufferStrategy.
I have only used BufferStrategy once and it doesn’t seem that much different.
EDIT:Should I make another thread for this question since I can feel the replies coming in on this one?
Yeah, I’d like to see code examples of an animation thread using BufferStrategy and one without.