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.
The MSDN documentation for HLSL seems to think that you can only do this in Direct3D 10. Of course, OpenGL and Direct3D don't always exactly match their functionality, but it's usually pretty close, since the same cards target OpenGL and DirectX. 

It could be that it is legal- just not for a target of the version that you are using.