title: How to bind an array of textures to a WebGL shader uniform?
body: <p>I need to handle many objects which share only a few textures. Defining and loading textures one by one manually (as described in <a href="https://stackoverflow.com/questions/11292599/how-to-use-multiple-textures-in-webgl/11300434#11300434">another post on SO</a>) does not feel right... even more so since there's no <code>switch (index) {case:...}</code> statement in WebGL. </p>
  
  <p>So I wanted to pass the texture to use for a vertex as a vertex attribute, and use this number as an index into some "array of textures" in the fragement shader. But the <a href="http://www.opengl.org/wiki/Sampler_%28GLSL%29" rel="noreferrer">OpenGL wiki on Samplers</a> (not quite the perfect reference for WebGL, but the one I found) says:</p>
  
  <blockquote>
    <p>A variable of sampler can only be defined in one of two ways. It can be defined as a function parameter or as a uniform variable.</p>
    
    <p>uniform sampler2D texture1;</p>
  </blockquote>
  
  <p>That to me sounds like I can have no array of samplers. I've read a few pages on texture units, but until now, that remains a mystery to me. </p>
  
  <p>In the SO post cited above, Toji hinted at a solution, but wanted a separate question - voila!</p>
  
  <p>Thanks, nobi</p>
  
  <p>PS: I know the other possibility of using a "texture atlas" - if this is more efficient or less complicated - I'd be happy to hear experiences!</p>