OpenGL ES 2.0 on Android: A very simple shader that works on a almost all devices, but doesn't on a Huawei Ascend P6:
vertex shader:
attribute vec2 a_position;
attribute vec2 a_texcoords;
uniform mat4 u_matrix;
varying mediump vec2 v_texcoords;
void main()
{
gl_Position = u_matrix * vec4(a_position, 0.0, 1.0);
v_texcoords = a_texcoords;
}
fragment shader:
uniform lowp sampler2D u_textureUnit;
varying mediump vec2 v_texcoords;
void main()
{
gl_FragColor = texture2D(u_textureUnit, v_texcoords);
}
The shader program is used to draw squares in the z=0 plane (as 4-vertex triangle strips) and a_position is given in world space. a_texcoords are standard (0,0)->(1,1) coordinates. u_matrix is set from a perspective camera, i.e. projectionmatrix*viewmatrix. when i change the distance in the view matrix (zooming in), at one point the tiles disappear, and only the clear color is shown, as if the fragment shader was never executed. when i zoom out again, i see tiles again.
Now the weird thing starts: when i (in the C++ code) transform the position to clip space and pass it to the shader as an attribute vec4 and write it unmodified to gl_Position, everything works as expected on the Huawei device. I have also compared the results of u_matrix * vec4(a_position, 0.0, 1.0) with the clip space position that i passed, and it turns out that they are *almost* equal to the clip space coordinates that i pass in from the cpu side. (in fact, i did the perspective division on both and then emitted vec4(1)-vec4(abs(difference).xyz*20.0,0.0) as a color - it was barely differentiable from white, so the difference is very small, i guess just different floating point arithmetics.)
any idea what's going on? scissor, depth and stencil tests are disabled, near and far planes of the camera are fine, backface culling is disabled. Feel free to ask for more detail...