View Full Version : Range of valid indices for glGenTextures, glGenBuffers

01-14-2013, 08:03 AM
I'm programming OpenGL 1.1 ES in Android, i.e. using fixed pipeline.

I'm using glGenTextures and glGenBuffers, which return an index in array (I use them only for one texture/buffer at a time). What is tha guaranteed range of this index?

Empirically, I observed that valid indices start with 1, but documentation doesn't mention anything about it. Is the value 0 guaranteed to be invalid?

I need it because sometimes I need to check if a texture/buffer was loaded already or not. If 0 can be valid, I need to initialize my values to -1 (to be able to detect that they are uninitialized/unloaded), but if 0 is invalid texture/buffer name, then things are easier.

In Android, an int[] is filled, but in OpenGL ES API, I saw that there are GLUint values there. So I'm afraid that (in theory) even initializing to -1 in my Android program can be incorrect, because (in theory) an uint can return 0xFFFFFFFF.

So what is the valid range, and what is the invalid range/value that I can be sure that it doesn't represent a valid texture/buffer name (index)?

01-21-2013, 06:33 PM
This is covered in the Red Book:


Naming A Texture Object
Any nonzero unsigned integer may be used as a texture name. To avoid accidentally reusing names, consistently use
glGenTextures() to provide unused texture names.
void glGenTextures(GLsizei n, GLuint *textureNames);
Returns n currently unused names for texture objects in the array textureNames. The names returned in
textureNames do not have to be a contiguous set of integers.
The names in textureNames are marked as used, but they acquire texture state and dimensionality (1D or 2D)
only when they are first bound.
Zero is a reserved texture name and is never returned as a texture name by glGenTextures().

Regards, Clay