Search code examples
texturesgpu

How to calculate how much video memory or memory cost by a texture


I want to know how to calculate how much video memory or memory cost by a texture. for example, how much video memory cost by TGA or DDS or PNG or JPEG. Are the same?

If there are the same, why PVRTC cost less video memory than PNG in IOS.

I know this is such a big topic that can fill a book. So does anyone can give some references for this topic after brief introduce. Thanks in advance.


Solution

  • TGA or DDS or PNG or JPEG. Are the same?

    That's file format. File format has little to do with texture format in video memory.

    TGA, PNG and JPEG are generic file formats. When game reads a file, it decompresses file and converts it into internal representation. From those formats, png offers lossless compression, jpeg offers lossy compression, tga is normally uncompressed. I think that only png and tga support transparency.

    DDS is somewhat DirectX oriented, because it stores data in one of the texture formats supported by DirectX. May be compressed (lossy), uncompressed, with or without alpha channel.

    As far as I know, (at least)DirectX supports two (types of) texture formats - compressed and uncompressed. In addition to that, texture might have mipmaps or might have no mipmaps. OpenGL should support some compressed formats, but I haven't tried to use them in OpenGL, so I'm not quite sure.

    1. An uncompressed 2D texture with no mipmaps takes at least width*height*pixel_size of bytes of video memory (driver may allocate more).
    2. An uncompressed 2D texture with mipmaps (full mipmaps chain) takes at least width*height*pixel_size*2 bytes of video memory.
    3. An uncompressed cubic texture with no mipmaps takes at least size*size*pixel_size*6 bytes of data.
    4. An uncompressed volume texture with no mipmaps takes at least width*height*depth*pixel_size bytes of data.
    5. Compressed textures take less bytes than uncompressed, but it is hard to predict exact number of bytes.

    Now, here's a list of texture formats for DirectX. Anything that is not DXT is uncompressed, but has different set of channels, and different number of bits per channel. For example, there are several 16bit texture format. DXT formats offer lossy compression, which will produce noticeable ugly artifacts if you apply it to normal maps in your shader. Depending on your data, DXT format can significantly reduce size of texture. Because format is lossy, it is not suitable for normal maps, and for 2d art that's supposed to be masked with alpha-channel.

    some references

    You can download DirectX sdk, opengl standard, or your platform documentation (if you're developing for something like ios) and start reading.