3
votes

I am creating an OpenGL game that will use texture atlases to load a lot of artwork.

Texture atlases are good because you load your image once and then cut sprites out of it. You save the time that would be necessary to load all files from disk, if they were independent and you save memory to store the images. But in my mind, beyond a certain point this benefit will not be that true, right? My idea is that if the texture atlas is very huge, you will waste a lot of memory to store it and perhaps some of the sprites on it will not be used that frequently.

What is the best approach for that? divide in multiple sprites? a sprite for level or what?

Anyway, my question is this: what is the size in pixels that corresponds the maximum an atlas should have to be considered a benefit?

2
There is no rule of thumb. You would have to profile your own application to determine the performance tradeoff.Dietrich Epp
OK, I know, I am talking about common sense.Duck
Well, common sense dictates you keep the dimensions under the maximum supported texture dimensions. GL_MAX_TEXTURE_SIZE x GL_MAX_TEXTURE_SIZE. A very real problem is that a texture cannot be "partially resident" in OpenGL ES (you tagged this question for the wrong version of GL, BTW), so you don't want to use a MAX SIZE texture and waste 90% of your memory on empty space, or force textures that are almost never referenced to stay resident just because some other much more common texture is always referenced. At that point you start to undo the benefits of individual texture caching.Andon M. Coleman
OK, thanks for the explanation. I was suspecting that beyond a certain point it will not benefit the app. Thanks.Duck

2 Answers

5
votes

Latest iOS devices (iPhone 4S and later, iPad 2 and later) support up to 4096 * 4096 px textures. All the previous devices except first two iPhones which are now pretty much obsolete support 2048 * 2048 px, so it's not like you can go to infinity and beyond.

iOS devices will not have trouble handling a few max size textures, but how high you should actually go depends a lot on your content. For example there would be no point in wasting memory on a max size texture atlas that holds sprites for multiple player characters if user can only play as one of them at a time. So I guess there is no universal answer to your question.

0
votes

If you're actually using all of the area in the texture, and so are not concerned about wasted memory space, there isn't any particular performance penalty to going to 2048x2048.

The catch is if you end up under-filtering when sampling (for example, a 512*512 texture region projected in to a much smaller area of the screen), which can then cause a lot of extra memory fetches. If you are writing a 2D game with sprites that are mostly drawn 1:1 (perhaps with minor scaling or rotation), then that isn't a concern.

Similarly, if you're doing 3D rendering and have mipmaps, then the mipmaps will handle the underfiltering case.