In answer to your first question, there is unfortunately no way to create a VolatileImage that is non-opaque (translucent or transparent). This is API that we should introduce in jdk1.5 (a ways off, but I just thought I’d mention it). The main idea behind the first VolatileImage API was to have the ability to force the back buffer to live in hardware. Back buffers are usually opaque, so this simple API did the trick. Now that that functionality is there, we can beef up the Volatile API to include other related operations/formats that people care about.
As to how you work around the issue, you should be able to use createCompatibleImage(w,h,transparent) for any background which will remain static. Say you have a scrolling starfield (or whatever); you can create this as a compatible image and simply copy from there into your Volatile back buffer. At some point (usually the second copy), we will recognize this as something that we can do better in hardware and we will create a VRAM version of that compatible image to use from then on. As long as you are not touching the pixels of the compatible image, we will continue to use the VRAM version of it and you will get native-hardware speeds.
Things to watch for:
- DO NOT grab the Raster or DataBuffer for the compatible image. If you do this, we give up on accelerating that image because we cannot guarantee that our VRAM version matches the original image (because you can tweak the pixels directly without our knowing). We will probably introduce some sort of Lock/Unlock API for this in the future, but for now just avoid it if at all possible.
- Accelerating compatible images only works for opaque and transparent images for now. We’re working on translucency acceleration; this should be there in jdk1.5.
- There can be problems with images larger than the screen size (we may not be able to create a VRAM image larger than that size), so if you need a background image larger than this, you’ll have to tile it into several images.
Hope that helps.
Chet.
(Java2D)