As mentioned here it would be possible to "bind all the textures you need to a sampler array in the shader and then index it with a vertex attribute". How would I do the binding? Currently I bind my textures like so (if that's correct in the first place; it works at least):
sampler[i] = gl.getUniformLocation(program, "u_sampler" + i);
...
for (var i = 0, len = textures.length; i < len; i++) {
gl.activeTexture(gl.TEXTURE0 + i);
gl.bindTexture(gl.TEXTURE_2D, textures[i]);
gl.uniform1i(sampler[i], i);
}
To bind an array of samplers now would I throw away activeTexture
and bindTexture
and use something like this?
gl.uniform1iv(sampler, [0,...,len-1]);