Jump to content
  • Advertisement
Sign in to follow this  
CodeZero

Cleaning textures out of memory

This topic is 4842 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

My Roguelike game I'm working on uses lots of tile graphics for the terrain, monsters, items etc. There are around 3000 different textures, but only 50 or so would be used for any particular level. So I'm thinking of having the textures dynamically loaded when a new level is loaded so that only textures that are used are in memory. I have 2 questions: 1. Does anybody know of a better way of doing this? 2. If not, then how do I go about cleaning out textures that are already in memory? Do I just build textures "over the top of them"? Any help would be appreciated. Jake

Share this post


Link to post
Share on other sites
Advertisement
Depending on the size of your textures, you could put multiple (related) textures on the same texture an then use texcoords to specify.

In order to delete existing textures you should be using

void glDeleteTextures(GLsizei numTextures, const GLuint *textures);


textures is an array of GLuint texture IDs to delete and numTextures is the size of the array.

Share this post


Link to post
Share on other sites
Quote:
Original post by skjinedmjeet
Do you know if you have to call that before exiting a program? I always do, but I haven't seen it in a lot of tutorials.


No, textures are not shared between contexts (by default), so they get freed during context cleanup.

Share this post


Link to post
Share on other sites
Quote:
No, textures are not shared between contexts (by default), so they get freed during context cleanup.

True, but cleaning up after yourself is always a good habit.

By the way, indeed caling glDeleteTextures and then creating the new texture works. When you're ready to optimize your code, you might look into reusing the textures.
By using glTexSubImage you can specify an existing texture and copy your new bitmap over the old one. That's a little faster.

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!