Pages

March 14, 2013

Advantages of TGA Files in Games

I've been looking why almost all C++ libraries and frameworks works mainly with .TGA files. What advantages the TGA format has over other image formats? I came to this answer:
There are a number of considerations here:
  1. How fast you can get the texture off disk and into system memory. 
  2. How fast you can get the texture from system memory to the GPU (via glTexImage2D in your case).
  3. How much disk space and video RAM storage is in your budget.
  4. Performance and quality.
TGA is a good choice because in the 24 and 32 bit uncompressed cases you can read the data in one single fread/whatever and send the result directly through glTexImage2D without further processing. It's a bad choice because it can have the largest file size and if disk I/O is a bottleneck then your reads will be slow. 
PNG is a good choice because it preserves quality of images with a reasonably small file size. It's a bad choice because PNGs can be slow to decompress - if that's your bottleneck then - well, you know. 
JPG is a good choice because it generally has the smallest file size and will come off disk really fast (doubly good if you need to send the file over a network). It's a bad choice because of intermediate software decompression steps and quality loss (although you can tune the quality settings to mitigate this). No alpha channel either. 
DDS (or other compressed formats) are good choices because of the smaller file size and the ability to include a prebuilt mipmap chain. If it's a format that's natively supported in hardware (and DDS is natively supported on most consumer PC hardware - has been for a long time too) you get the same benefit as TGA - one fread, a bit of poking in the header to figure out some image properties, then send the data straight through without intermediate steps. Compressed textures will also make your program run faster and use less video RAM. They're bad choices because they use lossy compression (which can sometimes be really noticeable) and may not be supported on all hardware. 
(...)
I thing this just answer my question.

No comments:

Post a Comment