A sampler is the connection between the shader and a texture unit. The value you set using glUniform is the number of the texture unit you want to associate with that sampler variable.
So if you want a sampler to read from a certain texture, you bind that texture to a texture unit and set the sampler to the number of that texture unit, e.g.:
Thank you but what’s the difference between a sampler and a normal uniform? Why GLSL texture functions need such kind of sampler type to access texels?
The GLSL texture functions need to know which texture to read. That information is given using a sampler uniform.
Samplers are opaque handles to textures. You can’t modify them nor get their “value” in some way. The internal details of how a sampler refers to a texture are hidden which allows different ways to implement it in hardware.
When you set a sampler to 0 using glUniform, it doesn’t necessarily follow that the shader hardware actually uses the value 0 anywhere to look up which texture to use.
"When you set a sampler to 0 using glUniform, it doesn’t necessarily follow that the shader hardware actually uses the value 0 anywhere to look up which texture to use.[/quote]