Results 1 to 7 of 7

Thread: How does glgentextures/gldeletetextures work?

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2010
    Posts
    12

    How does glgentextures/gldeletetextures work?

    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..

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: How does glgentextures/gldeletetextures work?

    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 :

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

    Code :
    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' ?

  3. #3
    Junior Member Newbie
    Join Date
    Sep 2010
    Posts
    12

    Re: How does glgentextures/gldeletetextures work?

    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/referen...s%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?

  4. #4
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,671

    Re: How does glgentextures/gldeletetextures work?

    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.

  5. #5
    Senior Member Regular Contributor
    Join Date
    Nov 2010
    Posts
    201

    Re: How does glgentextures/gldeletetextures work?

    Quote Originally Posted by Alphonse Reinheart
    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.

  6. #6
    Senior Member Frequent Contributor
    Join Date
    Oct 2009
    Posts
    592

    Re: How does glgentextures/gldeletetextures work?

    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.

  7. #7
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,671

    Re: How does glgentextures/gldeletetextures work?

    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".

Similar Threads

  1. glDeleteTextures
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-17-2005, 08:48 AM
  2. glDeleteTextures...
    By Sephiroth in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-09-2003, 09:50 PM
  3. glDeleteLists and glDeleteTextures
    By ARES in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 03-18-2002, 02:06 PM
  4. Problems with glDeleteTextures
    By jeppa in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 04-04-2001, 08:20 AM
  5. glDeleteTextures / glGenTextures crash!
    By JamesP in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 01-12-2001, 07:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean