views:

301

answers:

3

Approximately what's the maximum number of 1024x1024 32 bit .pngs which can be loaded at the same time with openGL in iphone ?, without risk of the app crashing.

And .pvr ? a much higher number ?

If I need a huge amount of textures in my game, is healthy to keep loading and calling dealloc to not overload the memory with all the textures ?

+5  A: 

You should load textures as required and unload unused textures when your application receives a low memory warning.

To answer your maximum memory question, it seems that the iPhone 2G/3G gives memory warnings around the 20 MB mark and iPhone 3GS starts to give warnings around 128 MB.

1024 * 1024 * 32 bits = 4 MB

So that's about 5 textures loaded before you get warnings. 1024 x 1024 is quite large (it's the largest you can have AFAIK) for a texture, so if possible you should reduce their size.

Note: My warning threshold values aren't official, they're just from experience and from other questions on stackoverflow.

Ben S
Sounds like my best option is to either use 24 bit pngs 1024*1024*24= 3MB or even 16 bit pngs 1024*1024*16= 2MB. But each of those formats supports alpha ? ( since my sprite sheets contain all the sprites of the game, i really need the alpha !)
José Joel.
Your best option is, as Ben mentions here, to load and unload as required. Manage the memory! :)
John Rudy
+2  A: 

PVRTC can be used with either 2 or 4 bits per texel, which is a huge saving. It's not possible to give a specific number for the amount of texture memory which is safe to use. Apple really dropped the ball on this, see this and this articles from Noel Lopis.

Also remember that if you're using mipmaps it takes 33% more memory (each mipmap is 1/4 of the level above => 1 + 1 / 4 + 1 / 16... ~= 1.33).

EDIT: One more note PVRTC doesn't work well if you have a very distinct alpha mask that you want to preserve.

Andreas Brinck
Why was this downvoted?
Andreas Brinck
+2  A: 

I hope when you say "and calling dealloc" you mean "and releasing those objects with -release" because you should never ever call -dealloc on any object yourself.

Steven Degutis
Not a direct answer to the question, but still a valid point.
Ben S