Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: glTexImage* with width/height == 0

  1. #1
    Junior Member Regular Contributor
    Join Date
    Mar 2002
    Location
    NI, Germany
    Posts
    114

    glTexImage* with width/height == 0

    Quick question:
    Does a call to glTexImage* with a width and/or height set to 0 free the allocated memory used by the currently bound texture object?

  2. #2
    Intern Newbie
    Join Date
    Mar 2006
    Posts
    35

    Re: glTexImage* with width/height == 0

    Yes, that is allowed in the spec.

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Feb 2006
    Location
    Sweden
    Posts
    748

    Re: glTexImage* with width/height == 0

    glDeleteTextures is preferred though.

  4. #4
    Junior Member Regular Contributor
    Join Date
    Mar 2002
    Location
    NI, Germany
    Posts
    114

    Re: glTexImage* with width/height == 0

    Thanks to you both. I have a lot of dynamic textures and don't want to call glDeleteTextures()/glGenTextures() every time I delete/create a new one. So my plan is to allocate a fixed number of texture objects and reuse them as needed.

  5. #5
    Senior Member OpenGL Pro
    Join Date
    May 2000
    Location
    Naarn, Austria
    Posts
    1,142

    Re: glTexImage* with width/height == 0

    That won't make your application any faster. The performance penalty when excessively using glGen/DeleteTextures is mostly because of dynamic memory allocation overhead. Changing the height and width most likely has the same overhead.

    Of course, if you just keep a pool of textures with fixed dimensions and reuse them for different images with the *SubTexImage functions, you might gain some performance at the cost of memory consumption.

  6. #6
    Junior Member Regular Contributor
    Join Date
    Feb 2000
    Location
    Santa Clara, CA
    Posts
    193

    Re: glTexImage* with width/height == 0

    Overmind is correct. In fact Longs Peak will not allow you to resize an existing texture (image object) as the dimensions are immutable.

    Changing a texture's dimensions is roughly equivalent to deleting the old texture and creating a new one. I'm fairly sure this is not what you want.

    This does provoke a thought, however. You are allowed to call TexImage with a NULL pointer; in this case the GL might allocate the texture structure but defer allocation of texel storage until the data is supplied via TexSubImage. This is a one-way operation, as there is no way to signal the GL that the data should be freed without deleting the texture object.

    Its possible we could provide an API which says "delete the storage associated with this (image or buffer) object". I'm not sure, in practice, how useful this would be.

    By the way, you don't need to call GenTextures again after calling DeleteTextures. You may reuse the existing name(s).

  7. #7
    Junior Member Regular Contributor
    Join Date
    Mar 2002
    Location
    NI, Germany
    Posts
    114

    Re: glTexImage* with width/height == 0

    Originally posted by Michael Gold:
    By the way, you don't need to call GenTextures again after calling DeleteTextures. You may reuse the existing name(s).
    But what if somewhere later I want to generate new texture objects? Wouldn't GenTextures possibly return me a name I'm still using?

    So I thinkt I'll generate the texture names as needed and do a call to DeleteTextures if they are no longer needed.
    I'll also try to pre-allocate some dynamic textures for reuse, as Overmind stated. But that will be at a later stage, when I know my number of textures and their sizes.

    Thanks for your input.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •