texture memory management

Started by
5 comments, last by _the_phantom_ 18 years, 7 months ago
You know how when you use glTexImage2d you use up some texture memory? How does OpenGL know when to free this? And, is there a way to free it manually? Thanks. mike http://www.coolgroups.com/
Mike C.http://www.coolgroups.com/zoomer/http://www.coolgroups.com/ez/
Advertisement
There sure is: glDeleteTextures(int).
Very nice. If the program exits and you don't call that function does the texture memory get freed?

mike
http://www.coolgroups.com/
Mike C.http://www.coolgroups.com/zoomer/http://www.coolgroups.com/ez/
Quote:
You know how when you use glTexImage2d you use up some texture memory?


GL takes care to allocate and free memory. When you call glTexImage you reload the texture onto the current texture.

Quote:
How does OpenGL know when to free this?


When you reload a new texture onto an existing one
When you delete texture objects ( see DeleteTextures() )
When the rendering context is destroyed (application exit)

Quote:
And, is there a way to free it manually?


see DeleteTextures()

You should take care of the deallocation when you create texture objects ( via GenTextures )
A typical pseudo-code skeleton is this

Setup
GLuint id;glGenTextures(1, &id) glBindTexture(id)glTexImage2D(...)  


now it's safe to delete your image from client memory because GL has its own

Use
glBindTexture(id)


Release
glDeleteTextures(1, &id);


for the details see some tutorials/reference
Quote:Original post by blizzard999
A typical pseudo-code skeleton is this

Setup
GLuint id;glGenTextures(1, &id) glBindTexture(id)glTexImage2D(...)  


now it's safe to delete your image from client memory because GL has its own

Use
glBindTexture(id)


Release
glDeleteTextures(1, &id);


for the details see some tutorials/reference


you could use a fixed size buffer to load your textures iteratively move the texture to VRAM and load the next texture instead of allocating a ton buffers for the textures and deleting them again

should avoid a little bit of memory fragmentation
http://www.8ung.at/basiror/theironcross.html
Theres no good reason why it would, because you make and delete the data one after the other, and you are making a few assumptions about the size and useage patterns of the texture data in that situation, you might need to keep the data around for some reason and you need to known in advance the size of the largest texture you are going to be loading at any given moment.

This topic is closed to new replies.

Advertisement