View Full Version : glTexStorage* 'levels' param, and bad texture rendering.

01-27-2014, 10:34 PM
From the output of the man page:

glTexStorage2D - simultaneously specify storage for all levels of a
two-dimensional or one-dimensional array texture

void glTexStorage2D(GLenum target, GLsizei levels,
GLenum internalformat, GLsizei width,
GLsizei height);

Specify the target of the operation. target must be one of

Specify the number of texture levels.


I wound up pulling a Google search on "texture levels" and found only references to mipmaps, but no official definition on what this actually means. If someone could clarify that this is in fact
what the parameter correlates with, I'd appreciate it.

Regardless, how do I know what an appropriate value is for this parameter?

I have a 36*36 texture which is composed of unsigned chars. The texture is rendererd on the faces
of a cube (36 vertices; no indices are used).

For instance, passing in 16 as a value causes nothing at all to show,
where as a value of 2 causes a "wtf" mixture of colors which simply shouldn't be there.

So, I'm just not sure exactly where to begin with this. Thanks again for any clarifications/advice.

01-28-2014, 02:36 AM
Yeah, levels are mipmap levels.

From the guide (http://www.opengl.org/sdk/docs/man4/xhtml/glTexStorage2D.xml): "glTexStorage2D specifies the storage requirements for all levels of a two-dimensional texture or one-dimensional texture array simultaneously. Once a texture is specified with this command, the format and dimensions of all levels become immutable unless it is a proxy texture. The contents of the image may still be modified, however, its storage requirements may not change. Such a texture is referred to as an immutable-format texture"

So the xxxStorage*D() functions are used to specify an "immutable" (in size and format) texture with fixed size. You can upload/update its bytes but within the same size in bytes.
If you are using Storage*D functions for textures without mipmaps, you need to set "levels = 1"

01-28-2014, 08:03 AM
Would this be correct for a 2d texture storage with mipmaps then?:

int levels = int(ceil(log(max(sizeX, sizeY) + 1)));

Dark Photon
01-28-2014, 04:52 PM
Would this be correct for a 2d texture storage with mipmaps then?:

int levels = int(ceil(log(max(sizeX, sizeY) + 1)));

ARB_texture_non_power_of_two (http://www.opengl.org/registry/specs/ARB/texture_non_power_of_two.txt) contains this definition for the number of MIPmaps:
numLevels = 1 + floor(log2(max(w, h, d)))

Your formula seems to be equivalent.