ColorModel / ColorSpace

I recently started doing some work with Java2D again, now that we have the possibility of drawing acclerated using the d3d & ogl pipeline.

I started to build a little wrapper that handles common operations like setting the backbuffer, fullscreen/windowed mode, color depth etc.

But I’m wondering how ColorMode’s /ColorSpace’s are used under the hood in Java2D and how they affect performance.

Just to give an extreme example:
Suppose my display has a color depth of 32bpp. I load some 24bit images (sprites) which I blit to an offscreen image which has a color depth of 16bpp, then I blit this 16bpp image to my 32bpp screen. I guess this means that the pixels have to be converted each blit (for the copy to the offscreen image & the blit to screen)? Would it be better to get the current display depth and set the colormodel for all images i use to that colormodel/depth?

Thanks!

Martijn

Yes, that would be the best. Which is why there exist methods
for creating images best suited for the current environment -
see GraphicsConfiguration.createCompatibleImage() methods.

It has become less important now that we have some hw acceleration
because if your sprite doesn’t change every frame, it may be cached in vram
in the best format available, so the convertion happens only
once when the sprite is copied to the vram.

But still, for cases where there’s no hw acceleration it is the best
approach to avoid conversions if possible.

Now for your backbuffer you should either use VolatileImage
(which is always created in the best format possible),
or better yet, BufferStrategy.

Thanks,
Dmitri
Java2D Team

Thanks for your reply Dmitri!

[quote]Now for your backbuffer you should either use VolatileImage
(which is always created in the best format possible),
or better yet, BufferStrategy.
[/quote]
I always thought a BufferStrategy just used a VolatileImage under the hoods?

And another question, I readhttp://java.sun.com/j2se/1.4.2/docs/api/java/awt/image/BufferStrategy.html a BufferStrategy can use double buffering and tripple buffering, but why would I use a tripplebuffer, it sounds that it just takes more (v)ram, how does it help performance wise?

Not exactly. In particular, depending on the configuration when buffer
strategy is “shown” buffer swapping could be used instead of
copying.

[quote]… but why would I use a tripplebuffer
[/quote]
Take a look:
http://en.wikipedia.org/wiki/Triple_buffering

Thanks,
Dmitri