2d texture arrays vs multi texturing

Does anyone have opinions about TEXTURE_2D_ARRAY vs multi texturing?

More specifically I’m writing a 2d game engine and im using 2d texture arrays for sprite sheets. Each frame of the sheet is one of the layers.

Now aside from color I’m going to want more textures for say normals, depth, and possibly other shader effects.

The obvious way to do this is to do multi texturing and have a 2d texture array for color frames, another for normal frames, and so on. Another way to do this would be to just pack everything into one single 2d texture array, store the offsets using uniforms, and not use multi texturing at all.

Its less API calls and seems like it might be easier to manage. Does anyone have opinions either way? Were 2d texture arrays meant to be used like this? Any performance pitfalls to be aware of?

What was the original problem developers were having that 2d texture arrays were developed to solve?

Thanks!

1 Like

Another way to do this would be to just pack everything into one single 2d texture array, store the offsets using uniforms, and not use multi texturing at all.

That’s just not going to work. You can’t store images with multiple image formats in a single texture. And “depth” generally needs to be in 24-bits or more of storage. You would ultimately have to compromise the storage for one of the kinds of image data.

What was the original problem developers were having that 2d texture arrays were developed to solve?

Array textures were invented to solve texture switching problems. Imagine you have a game where there are many characters that use the same mesh and shader, but different textures. In order to render them without array textures, you would have to insert a texture binding between each character rendering. You don’t have to do that with array textures.

Also, imagine you have a game where a character has sufficient texture detail that cannot be contained in a single texture. They have different attachable weapons and so forth or whatever. Without array textures, you would have to render each individual piece with a separate rendering call, with a bind texture between each one. It’s more efficient to use one rendering call instead of many.

If you’re dealing with sprites, array textures aren’t really going to help you. Mostly because any GPU (even embedded ones) will chew up what you’re rendering without really noticing. Performance is simply not going to be noticeable; not unless your shader is really heavy.

When you stop and think about what they provide it’s probably intuitive.

Before with one “object texture” per texture, if you wanted to draw an object, you had to switch textures. That meant breaking a batch, doing a state change, and drawing another batch. Inefficient.

…so folks started atlasing texture – that is, allocating a big 2D texture and pasting a bunch of little texture into different corners of it. Great! Now we can draw a bunch more objects in a single batch without intervening state changes! …except that you had nasty texture bleeding between the maps, couldn’t have nice clamp and repeat on the subtextures, etc…

So along come texture arrays, which give you the “bigger batches” advantages of texture atlases but without any of their ugly cons.