iPhone OpenGL ES texture unit

五迷三道 提交于 2019-12-11 01:57:28

问题


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);

回答1:


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.



来源:https://stackoverflow.com/questions/8366033/iphone-opengl-es-texture-unit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!