Jump to content
  • Advertisement
Sign in to follow this  
mike74

OpenGL texture memory management

This topic is 4691 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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/

Share this post


Link to post
Share on other sites
Advertisement
Very nice. If the program exits and you don't call that function does the texture memory get freed?

mike
http://www.coolgroups.com/

Share this post


Link to post
Share on other sites
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 )

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!