PDA

View Full Version : texture bit depth query



zeckensack
07-20-2003, 12:07 AM
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_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,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_S IZE,&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_bi ts)*256*256)>>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).]

Bob
07-20-2003, 01:30 AM
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 http://www.opengl.org/discussion_boards/ubb/smile.gif

zeckensack
07-20-2003, 02:02 AM
Thanks Bob http://www.opengl.org/discussion_boards/ubb/biggrin.gif

Oh joy ... I've found it.

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

glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTUR E_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).]

Bob
07-20-2003, 03:35 AM
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. http://www.opengl.org/discussion_boards/ubb/rolleyes.gif

kehziah
07-25-2003, 12:12 AM
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.