user1075438
user1075438

Reputation: 31

iPhone OpenGL ES texture unit

I am new to writing OpenGL ES for the iPhone. I am trying to render yuv texture, but am very confused by the concept of a texture unit.

If I change the glUniform1i's second parameter with different combination, the resulting image is different. My question is how is this 0 or 1 texture unit configured? What is the right way of using it?

Edit: Stupid me... forgot to call this:

glTexParameteri(GL_TEXTURE_2D, GL_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_MAG_FILTER, GL_NEAREST);

Upvotes: 2

Views: 1065

Answers (1)

Brad Larson
Brad Larson

Reputation: 170317

You can bind a texture to an available texture unit using code like the following:

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture1);

glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, texture2);

This assumes you've properly configured both texture1 and texture2, of course.

When it comes time to bind your textures to your shaders, you specify which texture unit that particular texture is bound to using code like the following:

glUniform1i(texture1Index, 0);
glUniform1i(texture2Index, 1);

where texture1Index and texture2Index are the indices of the appropriate uniforms for your shader. The 0 and 1 correspond to the texture units we bound the textures to earlier on.

Upvotes: 2

Related Questions