I've implemented a sprite batch class that uses a sampler array so that I can select a texture to use based on the gl\_PrimitiveID. The idea was to be able to draw sprites that use different textures in a single draw call. I've managed to get it to compile the shaders and run, but the sampler indexing part does not seem to work, although I did not get any OpenGL error. I've done a bit of research and found out that it doesn't seem possible to index into a sampler array with an index that is not a compile-time constant or uniform variable.

Am I doing something wrong or is building a texture atlas the only way to draw sprites that use different textures at once?
['https://gamedev.stackexchange.com/questions/13853', 'https://gamedev.stackexchange.com', 'https://gamedev.stackexchange.com/users/2940/']
You can use multitexturing to do this - because you can bind a different texture to each texture unit you can then use your uniforms to select which one. The limit is hardware dependent, but usually no less than 8 and very occasionally as small as 4.

<http://www.opengl.org/resources/code/samples/sig99/advanced99/notes/node60.html>

Multitexturing predates shaders so support is fairly global.

This does mean not using a sampler array and instead using your own logic - "just" unroll a binary search, or even better use some bit magic.

It is however fastest to use one texture for all calls and for it to be an atlas of some kind.
> 
> Am I doing something wrong or is building a texture atlas the only way to draw sprites that use different textures at once?
> 
> 
> 

It is not necessarily the "only" way, but it is the *best* way. It is the way that works on anything, from the lowly Voodoo 1 all the way to the Radeon 6990. It doesn't require shaders (though they can be useful with this).

All it requires is a bit of pre-processing on your end to put all of the images in one large image. This is hardly an onerous burden.

That being said, how many sprites do you intend to draw per frame? If it's less than a couple of hundred, an atlas isn't that important to your rendering performance. Texture atlases matter most for things like particle systems and fonts, because you're drawing lots of them.