This topic is now archived and is closed to further replies.

Do I need free TextureArray?

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

i''m trying to make a game with OpenGL and C++. that game has several buildings. and i applied lots of texture on them. here is my problem: if i''m not using that glDeleteTexture function, the program gonna eat half of my memory in 1 minute if i move around in the game. that''s 256MB. so if i don''t clear loaded textures in the memory, i will run out of memeory very quick. if i do use the glDeleteTexture, it will take 50% of my 2.4GHz CPU. and also there''s a delay. btw, i put all my buildings in individual cpp files. inside that file, i load texture first, then draw building by vertex. i also tried to set a flag, such as firstTime in each building file, hoping it will not load the texture again and again, but it gave me linking error said i can''t have same firstTime in different file. so, do u guys have any idea about that? please help me!!!

Share this post

Link to post
Share on other sites
You shouldn''t be loading textures in your render function.

Load the textures once at the start and store the identifiers generated by glGenTextures.

When you need to use a texture, just use glBindTexture with the identifier you got when creating it.

Finally when it''s time to quit, use glDeleteTextures on those stored identifiers. Actually that''s not really nessesary since the driver should take care of it for you, but its good programming practice.

here''s some pseudocode


Share this post

Link to post
Share on other sites
Infact, if you dont plan on doing anything with the textures once you''ve given them to OpenGL you can delete the loaded texture data so your load function becomes something like

  • Load Texture data (using ''new'' to grab some memory for example)

  • Send Texture data to OpenGL and store texture ID

  • delete loaded texture data (''delete'' if you used ''new'')

  • If needed return texture ID for later use

This stops you having that extra ram chewed up by the textures you dont need (the texture data given to OpenGL could all be stored on the gfx card if enuff video ram (VRam) exists).

And to reiterate what Melekor said, load the textures on start up and then rebind them in the main loop to use.

Share this post

Link to post
Share on other sites