1
votes

I'm setting up two textures as follow:

GLKTextureInfo  *texture = [GLKTextureLoader ...
glActiveTexture(GL_TEXTURE0);
glUniform1i(glGetUniformLocation(self.program, "uTextureMask"), 0);
glBindTexture(GL_TEXTURE_2D, texture.name);

texture = [GLKTextureLoader ...
glActiveTexture(GL_TEXTURE1);
glUniform1i(glGetUniformLocation(self.program, "uTextureLabel"), 1);
glBindTexture(GL_TEXTURE_2D, texture.name);

referred in the fragment shader:

uniform sampler2D uTextureMask;
uniform sampler2D uTextureLabel;

The problem is that only the last texture I bind is available in the shader. In the example above, only uTextureLabel works.

Any idea?

Thanks, DAN

UPDATE:

glGetUniformLocation returns 13 for uTextureMask and 14 for uTextureLabel.

In the shader I do:

highp vec4 label = texture2D(uTextureLabel, vTexel);
highp vec4 mask = texture2D(uTextureMask, vTexel);

highp vec3 surface;

surface = label.rgb;
// surface = mask.rgb; // <--- DOESN'T WORK    

gl_FragColor = vec4(surface, 1.0);
1
Can you check the return values of the glGetUniformLocation calls? What you're doing in the code shown here looks fine to me. I noticed that you bind the same texture twice, but I figure you did that just to simplify the example.Reto Koradi
sure! question updated with some detailsDAN
I don't know how GLKit works, but it might be the case that the GLKTextureLoader stuff internally changes the texture binding. Since you call it while unit 0 is still active, it might destroy the binding you had on that unit previously.derhass
Brilliant! I've moved glActiveTexture(GL_TEXTURE1) one line up and it works. Thank you derhass.DAN

1 Answers

0
votes

On IOS GLKTextureLoader not only load PNG. It's also create texture name byglGenTexture`, bind it and load data on GPU and also set default parametres for GL_WRAP_MODE and MIN/MAG algorithms.

In your code i see that you call

glActiveTexture(GL_TEXTURE0)
glBindTexture(MaskTexture)
glBindTexture(LabelTature) // this call made GLKTextureLoader
glActiveTexture(GL_TEXTURE1)
glBindTexture(LabelTexture)

In result you have LabelTexture binded into GL_TEXTURE0 and GL_TEXTURE1 texture blocks.