[LWJGL] Sending multiple textures to sampler uniforms in openGL

By convention, I’ve read on the internet and put into practice that to send a texture to a shader via sampler2D, you need to:


glActiveTexture(GL13.GL_TEXTURE0 + textureUnit);
glBindTexture(GL_TEXTURE_2D, textureId);
glUniform1i(uniform, textureUnit);

But… why do we need textureUnit? Surely there must be some way of sending exactly the texture data to the shader without having to bind it to a texture unit… To me this just seems like an extra little bit of faff that isn’t exactly needed…

Could someone explain?

Why couldn’t something like this exist:


glUniformSampler(glGetUniformLocation(shaderProgramId, "uSampler1"), texture1id);
glUniformSampler(glGetUniformLocation(shaderProgramId, "uSampler2"), texture2id);
glUniformSampler(glGetUniformLocation(shaderProgramId, "uSampler3"), texture3id);