currently I am having problems with passing multiple Textures to a glsl shader on iOS.
I have read through several similar questions and also tried whats written in eg. How can I pass multiple textures to a single shader, but that did not work either.
Here is my code:
[self setupVBOs];
[self compileSimpleShaders];
[self render];
in compileSimpleShaders the Shader gets compiled and uniforms get set. For the Textures it does:
_textureUniform = glGetAttribLocation(programHandle, "Texture");
_textureUniform2 = glGetAttribLocation(programHandle, "Texture2");
in render the wanted Textures get bound to the Uniform as
glActiveTexture(GL_TEXTURE0);
glBindTexture(CVOpenGLESTextureGetTarget(_display.chromaTexture),
CVOpenGLESTextureGetName(_display.chromaTexture));
glUniform1i(_textureUniform, 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(CVOpenGLESTextureGetTarget(_display.lumaTexture),
CVOpenGLESTextureGetName(_display.lumaTexture));
glUniform1i(_textureUniform2, 0);
glDisable(GL_BLEND);
I have been using GL_TEXTURE0 and GL_TEXTURE1 here, because when the Textures, which are actually the luma and Chroma Textures from the iPhone Camera,that are ultimately used to calculate the corresponding rgb value, are getting created, these Textureslots are used.
The fragmentshader I am using is very simple, it just textures a simple Screen Filling Quad with a given texture:
varying lowp vec4 DestinationColor;
varying lowp vec2 TexCoordsOut;
uniform sampler2D Texture;
uniform sampler2D Texture2;
void main(void) {
gl_FragColor = texture2D(Texture2,TexCoordsOut);
}
I have been using this to check if both textures are getting correctly uploaded by swapping Texture/Texture2 in the gl_FragColor.
The Textures themselves work just perfectly fine. The problem here is, that only one Texture gets used despite with what Texture the Quad gets textured.
Since thats the case, the Problem might be that the first loaded texture gets overwritten with the second texture.
I Hope someone can help me here and sees what I did wrong, because i simply don't see it.