Problems getting the size of a texture...


I’m trying to get GL to tell me how big a texture is that I’ve currently uploaded. With compressed textures this is no problem, but with uncompressed textures I am a bit stumped.

I thought that using glGetTexLevelParameter with GL_TEXTURE_COMPONENTS would get me a 3 if it is an RGB texture and a 4 for an RGBA. That’s not the case. I get far larger values that does not correspond to anything sane.

(getting height and width does work…)

What is the proper way of doing it, in terms of OpenGL 1.1?

(Using GeForce DDR, 7.58 drivers)

I don’t know how it works, but can it be that it retuns GL_RGB instead of 3, and GL_RGBA instead of 4?

AUX_RGBImageRec* image;
image = auxDIBImageLoad(“filename.bmp”);
unsigned int *size = (unsigned int *)(image->sizeX * image->sizeY * 3 * sizeof(int));

Macke, you did upload the textures yourself, correct? You knew the width, height, and bit-depth; you had to in order to load them in the first place. You know which texture object contains which texture. So why not store them someplace when you upload teh texture instead of using a slow glGet*?

Yes, I do upload the textures myself… but I’m not quite sure how all GL cards handle stuff like GL_LUMINANCE_ALPHA (are they kept in float format with two channels, or converted to 32-bit RGBA, or just 16-bit luminance+alpha?) and there’s mipmaps and stuff that complicate things.

I did the calculations myself for a while, just taking widthheightcomponents*4/3 (for mipmaps) … but I wasn’t sure if it was really right so I decided that there should be a way to ask opengl how much memory a texture that I’ve uploaded takes. (after the driver having done the conversion to some internal format.)

I want to keep track on how much texture memory I’m using, so I don’t like to guesstimate.