iPhone OpenGL ES纹理单元 [英] iPhone OpenGL ES texture unit
问题描述
我是为iPhone编写OpenGL ES的新手.我正在尝试渲染yuv纹理,但对纹理单元的概念感到非常困惑.
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.
如果我使用不同的组合更改glUniform1i的第二个参数,则生成的图像会有所不同.我的问题是如何配置0或1纹理单元?正确的使用方式是什么?
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?
愚蠢的我...忘了打电话:
Stupid me... forgot to call this:
glTexParameteri(GL_TEXTURE_2D, GL_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_MAG_FILTER, GL_NEAREST);
推荐答案
您可以使用以下代码将纹理绑定到可用的纹理单元:
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);
这当然假设您已经正确配置了texture1
和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);
其中,texture1Index
和texture2Index
是您的着色器的适当制服的索引. 0和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.
这篇关于iPhone OpenGL ES纹理单元的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!