PDA

View Full Version : How does glgentextures/gldeletetextures work?



DannyG
12-10-2010, 06:12 AM
I know it returns a set of texture names (ids) and stores them in a specified array.

As far as I understand, these ids are not linked to the index inside this array in any way.

What I'm wondering now is, what if I want to delete a single texture using its name?

Because concluding from the above facts, I guess I first need to find the array index myself, and then pass that index to the gldeletetextures as being the offset?

I really don't understand the array thing.. gldeletetextures should just be passed the texture name. The functions are updating the array but I still need to find the array element myself..

ZbuffeR
12-10-2010, 06:54 AM
The intent of glGenTextures/glDeleteTextures is to be able to work easily on several textures with a single call.
As C language does not handle lists directly, that is why you have to pass both the number of elements and the pointer to the start of the array, instead of simply sending a list like what could be done in other languages;

If that confuses you, simply call them with 1-element-array, like this :



GLuint textureVar;
glGenTextures(1,&textureVar); // & means 'pointer to'
// now id is stored in 'textureVar'




GLuint textureToDelete=textureVar;
glDeleteTextures(1,&textureToDelete); // & means 'pointer to'


Is it easier to understand for you if you call it 'list of ids' instead of 'array of ids' ?

DannyG
12-10-2010, 07:11 AM
I forgot to mention I don't do C but JAVA, as I am developing for Android.

You mention a 1-element-array, but you type it GLuint?

I do read a lot about the &pointer notation as being the second argument. I guess that confused me as this is not the way Android handles the function.

http://developer.android.com/reference/javax/microedition/khronos/opengles/GL10.html#glDeleteTextures%28int,%20int[],%20int%29

I'm not sure what's meant by the intBuffer, so I was talking about the first one in my first post.

btw, i assume list is a C term for array?

Alfonse Reinheart
12-10-2010, 07:25 AM
You mention a 1-element-array, but you type it GLuint?

Yes. In C/C++, there is no difference between a pointer to a one-element array and a pointer to an element. All an array is in C/C++ is a pointer to some memory of a certain type. Therefore, you can just get a pointer to a variable of type X, and you have a one-element array of type X.

How Android and Java exposes the glGen* functions probably doesn't let you use this trick.

So just create a one-element array, and store the result in a GLuint or whatever type the one-element array normally is.

david_f_knight
12-10-2010, 09:45 AM
All an array is in C/C++ is a pointer to some memory of a certain type.
Not true. An array in C or C++ is an indexed block of memory. A pointer is a memory element intended to contain the address of a memory element (which may be part of an array or not). Arrays can exist without pointers to them, and pointers can exist without arrays (or scalars) to point to.

ugluk
12-10-2010, 11:21 PM
Well, the only thing I am interested in this discussion is, if with the new GL versions >3.0, it is possible for GL to return a texture object 0? Currently I use 0 as an invalid texture indicator in my app.

Alfonse Reinheart
12-10-2010, 11:45 PM
it is possible for GL to return a texture object 0?

No. It has never been possible. 0 has always been the object name that refers to "no object", just as NULL is the pointer that refers to "no memory".