Best image type for best performance

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Best image type for best performance

Chen norris
Hello all,

I've got a question about the best image type to use with the glTexImage2D and glTexSubImage2D functions. I've read over the Khronos wiki that most graphic cards prefers the BGRA format but the BufferedImage class only provides the following image types in its constructor :
  • TYPE_INT_RGB
  • TYPE_INT_ARGB
  • TYPE_INT_ARGB_PRE
  • TYPE_INT_BGR
  • TYPE_3BYTE_BGR
  • TYPE_4BYTE_ABGR
  • TYPE_4BYTE_ABGR_PRE
  • TYPE_BYTE_GRAY
  • TYPE_USHORT_GRAY
  • TYPE_BYTE_BINARY
  • TYPE_BYTE_INDEXED
  • TYPE_USHORT_565_RGB
  • TYPE_USHORT_555_RGB
To me, the closest image type in this list seems to be the TYPE_4BYTE_ABGR but I'm not sure at all. Does OpenGL has to do some stuff to put the alpha component at the end for rendering ? If so, that would mean the ABGR is not the best suitable image type. Maybe OpenGL can reverse from ARGB to BGRA faster and then the TYPE_INT_ARGB image type would give better performance… ? (once again, I'm not sure at all).

Do you advice me to implement my own method to convert a ARGB BufferedImage into BGRA BufferedImage ? (and then call the glTexImage2D and glTexSubImage2D functions with the image type parameter set to GL_BGRA) Or let OpenGL do the stuff ? (because it may be fastest than my own stuff)

Another idea would be to create TYPE_3BYTE_BGR buffered images and then do the stuff in an extra method to add the alpha component at the beginning to keep the 4-alignment. Once again, I'm not sure if it's the best way to have something optimized.

Thanks in advance for all your advices.
Reply | Threaded
Open this post in threaded view
|

Re: Best image type for best performance

gouessej
Administrator
Hey

If you worry about the performance and if you use the images only to make textures, don't use BufferedImage, use TextureIO & TextureData.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Best image type for best performance

Chen norris
Once again, perfect solution provided by Mr Gouesse

Just replaced all the stuff generating a BufferedImage with awtGlReadBufferUtil.readPixelsToBufferedImage by a simple awtGlReadBufferUtil.readPixels and it's running twice faster now ^^
All I have to try now is to see if it's possible to easily resize a TextureData to see if it makes me gain a bit more FPS (resizing my reflection texture was something I made to speed up a little my app)

Anyway, thanks a lot for your solution