views:

189

answers:

2

Hey, I have a texture loaded with glTextImage2D. I want to get the texture's size after it was loaded to the VRAM, what do I need to do? My internal format is RGBA and the texture's format varies.

+4  A: 

This might be helpful to you and you can probably infer the actual memory usage from it. However, I believe this still is rather an approximation:

http://www.geeks3d.com/20100531/programming-tips-how-to-know-the-graphics-memory-size-and-usage-in-opengl/

(query the total memory usage of OpenGL using NVIDIA or ATI specific extensions)

Also note that from my experience, approximating the memory usage by rough calculation was usually sufficient. Textures "should" be stored either 1,2 or 4 components without any significant overhead. Therefore for a WxH RGBA texture, calculate W*H*4. If you store float textures (i.e. GL_RGBA32F), calculate W*H*4*4. For Mip-Maps, add (1/3) additional memory consumption. Be aware however, that - at least to my knowledge - texture memory can also fragment, possibly leaving you with less available memory as estimated.

zerm
The extension doesn't specify memory used by a single texture, but the total/available/used video memory. However, it could be a great aid for managing mipmaps in order to optimize mipmaps generation.
Luca
@Luca: as mentioned, you could possible _infer_ the memory usage of a single texture: Read total use before allocating texture, read total usage after allocation, compare. Haven't tried, though...
zerm
+1  A: 

Use GetTexLevelParameter, which can give you (for each level):

  • Width and height *
  • Depth
  • Internal format *
  • Compressed format and relative size

(*) Uses these parameters for computing the texture size (for the specified level).

The single texture memory usage is dependent on the generated mipmaps. Indeed to compute correctly the memory used by a single texture you have to determine the mipmaps related to the textures, and then sum the memory usage for each level.

The mipmap count is determined by the OpenGL specification depending on the texture target: texture arrays elements has their own mipmaps set, each cube face texture has its own mipmap set. The dimension of the mipmaps are halfed for each level, untill they goes to 1. In the case the dimension are not power of two, they are rounded to the lower integer.

Luca