texture bit depth query

Am I just being an idiot, or why do I get zero?

glGenTextures(1,&tex0);
glBindTexture(GL_TEXTURE_2D,tex0);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,256,256,0,GL_RGBA,GL_UNSIGNED_BYTE,shtuff);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);

GLint red_bits=0,green_bits=0,blue_bits=0,alpha_bits=0;

glGetTexParameteriv(GL_TEXTURE_2D,GL_TEXTURE_RED_SIZE,&red_bits);
glGetTexParameteriv(GL_TEXTURE_2D,GL_TEXTURE_GREEN_SIZE,&green_bits);
glGetTexParameteriv(GL_TEXTURE_2D,GL_TEXTURE_BLUE_SIZE,&blue_bits);
glGetTexParameteriv(GL_TEXTURE_2D,GL_TEXTURE_ALPHA_SIZE,?_bits);

tex0_size=((red_bits+green_bits+blue_bits+alpha_bits)256256)>>3;

(R300, Cat3.6)

Oh yeah, I should add that the texture renders as expected. That has never been a problem.

[This message has been edited by zeckensack (edited 07-20-2003).]

Reading through the spec quickly, I can’t see GL_TEXTURE_*_SIZE as a valid parameter to glGetTexParameter. And when I try your code, glGetError returns GL_INVALID_ENUM after the first glGetTexParameter.

And you get zero because you initialize your variables to zero, and glGetTexParameter does not modify them because of the error. Change them and you will get another result

Thanks Bob

Oh joy … I’ve found it.

In case anyone’s interested in the solution, it’s

glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_RED_SIZE,&red_bits);

Seems somewhat illogical to me. Can a texture have different internal formats per mipmap level? I don’t think so …

Ho hum.

[This message has been edited by zeckensack (edited 07-20-2003).]

Well, since you must upload each mipmap level separately, then maybe you CAN specify different internal formats for each level. If so, then it makes sense to use glGetTexLevelParameter. Just tried and it reported no errors at least (tried it in a debugger only, no visual tests to see if it actually renders correct, I do that when I got more time).

Gee, you really do learn something every day, even basic stuff when you’ve known OpenGL for several years.

OpenGL 1.4 spec, section 3.8.10 : Texture completeness

A texture is said to be complete if all the image arrays and texture parameters required to utilize the texture for texture application is consistently defined. The definition of completeness varies depending on the texture dimensionality.
For one-, two-, or three-dimensional textures, a texture is complete if the following conditions all hold true:
The set of mipmap arrays levelbase through q (where q is defined in the
Mipmapping discussion of section 3.8.8) were each specified with the same internal format.

(…)
Effects of Completeness on Texture Application
If one-, two-, or three-dimensional texturing (but not cube map texturing) is enabled for a texture unit at the time a primitive is rasterized, if TEXTURE MIN FILTER is one that requires a mipmap, and if the texture image bound to the enabled texture target is not complete, then it is as if texture mapping were disabled for that texture unit.