iPhone OpenGL Texturing / Memory

Posts: 12
Joined: 2008.11
Post: #1
Hi, I'm having an issue with textures. What is the opengl es available texture memory in iPhone?

What happens is that I'm trying to load about 60-70 varied size textures. And there is only two large textures that are 256x256. The most of them will be 32x32 or 64x64 and some 128x128. If I bind then on load time, I keep getting blank textures or textures being replaced by others (I think its memory issue?).

So I tried to bind and delete them just in their rendering time (bad, very bad, I know, its a test) and almost everything works, but then periodically I get a black texture somewhere. Mad

How can I manage a high texture count on iPhone? I thought to implement texture atlas 1024x1024 so I can save some "blank" space from my tiny textures.

But first I'm looking for possible causes of my problem and another possible solutions.

Quote this message in a reply
Posts: 3,591
Joined: 2003.06
Post: #2
White textures could be the result of many different things. Just a few things to keep in mind: You need to have glEnable(GL_TEXTURE_2D), and you need to have the correct texture coordinates in your glTexCoordPointer(), and you need to have glEnableClientState(GL_TEXTURE_COORD_ARRAY). You of course, also need to have uploaded your textures to the GL with glTexImage2D, and you need to have at least set the minification filter for each texture with something like glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

For memory, in practice, your app can use up maybe 10 to 15 or 20 MB before getting memory warnings on iPhone, according to some reports (more on iPod Touch I think). How much of that is for the GL is up to you. The guide says you should use no more than 24 MB for textures and surfaces.

What I do is use a texture atlas where possible, and PVRTC textures where possible. PVRTC saves an enormous amount of memory at the cost of some compression artifacts. For animated 2D images I've found the PVRTC is perfectly fine since you can't see the compression artifacts in the frames of animation as they whizz by.
Quote this message in a reply
Posts: 12
Joined: 2008.11
Post: #3
I double checked my gl and tex initializations and yes, everything is fine. As I said, my problem is that I get theses glitches randomly. Sometime texture X appears on place of texture Y. Then when I restart, I can get texture H in place of texture C. Or else, just some of my textures will not shown (be blank if they aren't replaced by another one). So this really look as memory problem.

I will check about PVRTC, but most of my textures I need check pixel collision, so I dont know I will be able to use compressed textures.

ps.: Just as measurement, I got about 27mb of memory in use during my application. 25mb are from textures. I will try to keep it under 20mb to see if will solve.
Quote this message in a reply
Posts: 86
Joined: 2006.08
Post: #4
It isn't expected that there will be any texture corruption issues. You should submit a bug report, with example code, at http://bugreport.apple.com.

However, if you go beyond 24MB of texture usage at the same time (dormant textures will be paged off), you will experience a very large drop in performance. Your framebuffers, including depth buffer, also count against this limit.

Use Instruments (GART Resident Object Size) to determine how much texture memory usage is currently being used.
Quote this message in a reply
Posts: 12
Joined: 2008.11
Post: #5
Thanks, never heard about GART, just looks what I need Smile
I will check it and post the results here. Btw, I got it working by deleting and rebinding textures "EVERY" frame. But pre-allocating them still doesn't work. And I haven't dormant textures. All them need shown off in the same screen at same time.

Thanks again.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGL Differences between iPhone Sim and Real iPhone SparkyNZ 5 10,109 Apr 13, 2011 11:40 AM
Last Post: SparkyNZ
  bloody iPhone memory problem again(opengl es, texture2d) mlady 1 4,617 Apr 16, 2009 09:54 AM
Last Post: savemeanegg
  iPhone memory management mlady 2 4,388 Mar 10, 2009 03:10 PM
Last Post: mlady
  OpenGL texturing problem jaguard 0 2,329 Jan 22, 2009 06:01 AM
Last Post: jaguard