I have a surface texture bound to gl_texture_external_oes format. It was working well on direct rendering.
Now I want to split my fragment shader to 2 and do an offscreen rendering to 2D texture in between. I could do that; but with an issue. Suppose I want to do RGB-YUV conversion in first shader and then do YUV-RGB conversion in 2nd shader. (just an example)
My 2 pass shaders look like this.
private final String mFragmentShader1 =
"#extension GL_OES_EGL_image_external : require\n" +
"precision mediump float;\n" +
"varying vec2 vTextureCoord;\n" +
"uniform samplerExternalOES sTexture;\n" +
"void main() {\n" +
" vec2 texCoord = vec2(vTextureCoord.x, vTextureCoord.y);\n" +
" vec4 p11 = texture2D(sTexture, texCoord);\n" +
" float y = dot(p11.rgb,rgb2y);\n" +
" float u = dot(p11.rgb,rgb2u);\n" +
" float v = dot(p11.rgb,rgb2v);\n" +
" vec3 yuv = vec3(y,u,v);\n" +
" gl_FragColor = vec4(yuv,0.0);\n" +
"}\n";
private final String mFragmentShader2 =
"precision mediump float;\n" +
"varying vec2 vTextureCoord;\n" +
"uniform sampler2D sTexture;\n" +
"void main() {\n" +
" vec4 p11 = texture2D(sTexture, vTextureCoord);\n" +
" gl_FragColor = vec4(dot(yuv2r,p11.rgb),dot(yuv2g,p11.rgb),dot(yuv2b,p11.rgb),0.0);\n" +
"}\n";
My problem is:
The yuv data which I get via p11 in 2nd shader is correct. But gl_fragcolor is wrong.
Wrong means when comparing with direct rendering the values differ. (In direct rendering, I do RGB-YUV and then YUV-RGB in one shader itself). I think my gl_fragcolor is mixed with value from 1st shader or something.
Can anybody see what I am missing here.? Thanks for reading.