View Full Version : glTexImage* with width/height == 0
02-27-2007, 12:46 PM
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?
02-27-2007, 02:28 PM
Yes, that is allowed in the spec.
02-27-2007, 03:53 PM
glDeleteTextures is preferred though.
02-28-2007, 03:08 AM
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.
02-28-2007, 03:26 AM
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.
02-28-2007, 05:48 AM
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).
03-01-2007, 03:26 AM
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.
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.