Uniform arrays and element location


Can I always assume that in case of uniform arrays (especially samplers) all subsequent elements have their location incremented by 1 from base element or is it compiler dependent and I have to keep trace of locations for all array elements?

Example :

in fragment shader
   uniform sampler2D s_texture[3]

Uniform ----- Location
s_texture[0] – 4
s_texture[1] – 5
s_texture[2] – 6


No; you must query each individually. Or you can use the array forms of uploading (glUniformiv) to fill out an array.

BTW, sampler arrays have a number of limitations on them that may not be appropriate for your particular needs.

Normally, one would just setup the samplers only once, after your shader is linked.

For other types of uniforms, yes, use glUniform or glUniformMatrix.

Ok so I will just use uniform array setting function.