0

I'm developing a opengl es application for ios. I'm trying to blend two textures in my shader, but I always get only one active texture unit. I have generated two texture, and linked them with two "sampler2D" from the fragment shader. I set them to unit 0 and 1 by using glUniform1f();

And I have bind the textures using a loop

for (int i = 0; i < 2; i++)
{
    glActiveTexture(GL_TEXTURE0 + i);
    glBindTexture(GL_TEXTURE_2D, textures[i]);
}

But when I draw the opengl frame, only one unit is active. like in the picture below debug window in xcode using capture GPU frame

So, what I've been doing wrong?

1 Answer 1

0

The way I read the output of that tool (I have not used it), the left pane shows the currently active texture unit. There is always exactly one active texture unit, corresponding to your last call of glActiveTexture(). This means that after you call:

glActiveTexture(GL_TEXTURE0 + i);

the value in the left circled field will be the value of i.

The right pane shows the textures bound to each texture unit. Since you bound textures to unit 0 and 1 with the loop shown in your question, it shows a texture (with id 201) bound to texture unit 0, and a texture (with id 202) bound to texture unit 1.

So as far as I can tell, the state shown in the screenshot represents exactly what you set based on your description and code fragment.

Based on the wording in your question, you might be under the impression that glActiveTexture() enables texture units. That is not the case. glActiveTexture() only specifies which texture unit subsequent glBindTexture() calls operate on.

Which textures are used is then determined by the values you set for the sampler uniforms of your shader program, and by the textures you bound to the corresponding texture units. The value of the currently active texture unit has no influence on the draw call, only on texture binding.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.