Samplers of different types use the same texture image unit.
how can it know?
since you must first compile & validate the program before u use glUniform1i( loc, val ); to say what texture units you use
same with
2. A sampler’s texture unit is out of range (greater than max allowed or negative).
the only way it knows this is if it somehow has travelled into the future! as its telling me my unit is invalid before I even say what unit Im using
NOTE - this is on an apple software opengl (for IOS), the above works on PC/linux and webgl
Hi,
Could u show us what val contains in this line
glUniform1i( loc, val );
Usually val is the texture unit where the texture is bound to. In your case since u have two different textures, they should be bound to different texture units. In other words, something along thes lines should work.
glUniform1i( locEnvSampler, 0); //set envMap to tex unit 0
glUniform1i( locTexSampler, 1); //set tex to tex unit 1
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, envTexID);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, texID);
Hi, you can set your samplers locations right after you’ve checked that the program linked successfully.
I.e. something like this:
glLinkProgram(progID);
GLint linked;
glGetProgramiv(progID, GL_LINK_STATUS, &linked);
if ( !linked ) handle_error_here;
glBindProgram(progID);
// here you can use glUniform1i() to set the sampler units
glBindProgram(0);
// now validate the program
glValidateProgram(progID);
GLint valid=1;
glGetProgramiv(progID, GL_VALIDATE_STATUS, &valid);
if ( !valid ) handle_error_here;
glValidateProgram() is validating current context state (the sampler uniforms, the draw framebuffer, the current vertex array state, etc— anything that can cause a draw-time error when used with the program.) You shouldn’t validate immediately after linking.
Really you should validate right before drawing. And only in your debug build; it’s a tool for you to debug with.