glGenTextures question

Member
Posts: 509
Joined: 2002.05
Post: #1
Ok, right now in my game I have 5 textures for the terrain, possibly up to 8 for my model, and then a few random question, and I was wondering if my idea of keeping them organized would waste memory/speed. Here it is

glGenTextures( 30, &texture[0] );
// load textures 1-5 here (terrain)
// load texturess 10-18 here (model)
// load textures 20-30 here (random)

I know that textures 6-9 an 19 would never be touched (as well as some of the 20's), but will just having them exist take memory? I was thinking you actually need to send the texture to the card to take memory, but I could be wrong.
Quote this message in a reply
Member
Posts: 177
Joined: 2002.08
Post: #2
Having them as entries in the texture list doesn't take memory until you call glTexImage2D. OpenGL does not expose the details of video memory, it should handle everything for you.
Quote this message in a reply
Mars_999
Unregistered
 
Post: #3
The only wasted memory would be whatever your unsigned int texture array didn't get filled with. So in your case

unsinged int texture[30] = {0};

//you only assign textures to the first 25 elements than the last 5 are wasted or not being used.

Now if you actually assigned textures with

gluBuild2DMipmaps or glTexImage2D

to all 30 then yes you are wasting VRAM and system RAM.

BTW if you know that you're not going to use all 30 then why are you allocating 30 in your array?
Quote this message in a reply
Member
Posts: 509
Joined: 2002.05
Post: #4
Quote:Originally posted by Mars_999

BTW if you know that you're not going to use all 30 then why are you allocating 30 in your array?


Because I wrote a animated model class that uses meshworks data, so the textures are 1 through 8. I am already using texture 0-5, and at some point that will raise to 0-6 through 0-15 probably, so I want to keep the meshworks textures separate (start them on 20 or something)
Quote this message in a reply
Member
Posts: 233
Joined: 2003.05
Post: #5
Just use a seperate array for each group of textures.

i.e.
glGenTextures( 5, &terrainTexture[0] );
glGenTextures( 8, &modelTexture[0] );
glGenTextures( 10, &randomTexture[0] );

In my 2D game engine, I just have an object that takes care of smaller parts of a large texture. In other words the object takes care of the texture.

So it has one texture variable, and each instance does a glGenTexture call once. That way, when you create a bunch of these objects the textures are taken care of nicely, without any concern of one big array with many different textures owned by different objects.

This isn't the best way for all cases I suppose, but it might work for you! Grin

"Pay no attention to that man behind the curtain." - Wizard of Oz
Quote this message in a reply
Member
Posts: 509
Joined: 2002.05
Post: #6
Quote:Originally posted by aaronsullivan
Just use a seperate array for each group of textures.

i.e.
glGenTextures( 5, &terrainTexture[0] );
glGenTextures( 8, &modelTexture[0] );
glGenTextures( 10, &randomTexture[0] );


Thats perfect, Thanks Smile
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Pointer Warning in glGenTextures Pixelated 1 2,634 Apr 6, 2008 01:28 PM
Last Post: OneSadCookie
  glGenTextures() dies from EXC_BAD_ACCES? O.o wyrmmage 8 4,864 Apr 7, 2007 07:23 PM
Last Post: wyrmmage
  glGenTextures and EXC_BAD_ACCESS BobbyWatson 1 4,847 Aug 31, 2002 01:48 PM
Last Post: BobbyWatson
  death by glGenTextures(), with TGA sealfin 7 4,500 Jul 18, 2002 07:02 AM
Last Post: sealfin