I’m having a weird problem. What I want: use one texture in one fragment shader (GLSL) using two different sampling modes, this case let it be nearest and linear on min/mag/mip. So the code:
glActiveTexture(GL_TEXTURE0 + 0);
glBindTexture(GL_TEXTURE_2D, texture1.id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
glActiveTexture(GL_TEXTURE0 + 1);
glBindTexture(GL_TEXTURE_2D, texture1.id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
int location = glGetUniformLocation(4, "diffuseMapSampler1");
glUniform1i(location, 0);
location = glGetUniformLocation(4, "diffuseMapSampler2");
glUniform1i(location, 1);
Draw();
And the shader:
uniform sampler2D diffuseMapSampler1;
uniform sampler2D diffuseMapSampler2;
varying vec3 varNormal;
varying vec2 varTexCoord;
void main(void)
{
gl_FragColor = vec4(1.0f);
#ifdef TEX
gl_FragColor *= texture2D(diffuseMapSampler1, varTexCoord);
#endif
}
As we can see, the shader should use texture1 with nearest sampling, but it uses linear sampling. What is interesting, when I change this piece of code:
glActiveTexture(GL_TEXTURE0 + 0);
glBindTexture(GL_TEXTURE_2D, texture1.id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
to this:
glActiveTexture(GL_TEXTURE0 + 0);
glBindTexture(GL_TEXTURE_2D, texture2.id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
i.e. I use a different texture, then I indeed see as a result this different texture with nearest sampling.
All this leads me to a conclusion that glTexParameter doesn’t attach to a texture unit (glActiveTexture) but rather to a texture object (glBindTexture), what is incorrect.
Is it me who has forgotten something important here?