Q:

Android OpenGL ES Fragement Shader 1282 error

I built video effect application using OpenGl ES fragment shader.
But, this application had 1282 error and that occurred at glUniformMatrix4fv() in my case.
GLES20.glViewport(0, 0, getWidth(), getHeight());
GLES20.glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
GLES20.glUseProgram(program);
GLToolbox.checkGlError("glUseProgram");

GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textureID[0]);

triangleVertices.position(TRIANGLE_VERTICES_DATA_POS_OFFSET);
GLES20.glVertexAttribPointer(aPositionHandle, 3, GLES20.GL_FLOAT, false,
                             TRIANGLE_VERTICES_DATA_STRIDE_BYTES, triangleVertices);
GLToolbox.checkGlError("glVertexAttribPointer aPosition");

GLES20.glEnableVertexAttribArray(aPositionHandle);
GLToolbox.checkGlError("glEnableVertexAttribArray aPositionHandle");

triangleVertices.position(TRIANGLE_VERTICES_DATA_UV_OFFSET);
GLES20.glVertexAttribPointer(aTextureHandle, 3, GLES20.GL_FLOAT, false,
                             TRIANGLE_VERTICES_DATA_STRIDE_BYTES, triangleVertices);
GLToolbox.checkGlError("glVertexAttribPointer aTextureHandle");

GLES20.glEnableVertexAttribArray(aTextureHandle);
GLToolbox.checkGlError("glEnableVertexAttribArray aTextureHandle");

Matrix.setIdentityM(mVPMatrix, 0);
GLES20.glUniformMatrix4fv(uMVPMatrixHandle, 1, false, mVPMatrix, 0);
GLToolbox.checkGlError("uMVPMatrixHandle glUniformMatrix4fv");
GLES20.glUniformMatrix4fv(uSTMatrixHandle, 1, false, sTMatrix, 0);
GLToolbox.checkGlError("uSTMatrixHandle glUniformMatrix4fv");
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
GLToolbox.checkGlError("glDrawArrays");

GLES20.glFinish();

I found problem at the gl_FragColor = vec4(color.rgb * weight, color.a); in my fragment shader source.
String shader = "#extension GL_OES_EGL_image_external : require\n"
        + "precision mediump float;\n"
        + "vec2 seed;\n"
        + "varying vec2 vTextureCoord;\n"
        + "uniform samplerExternalOES tex_sampler_0;\n"
        + "uniform samplerExternalOES tex_sampler_1;\n\n"
        + "float scale;\n"
        + "float stepX;\n"
        + "float stepY;\n\n"
        + "float rand(vec2 loc) {\n"
        + " float theta1 = dot(loc, vec2(0.9898, 0.233));\n"
        + " float theta2 = dot(loc, vec2(12.0, 78.0));\n"
        + " float value = cos(theta1) * sin(theta2) + sin(theta1) * cos(theta2);\n"
        + " float temp = mod(197.0 * value, 1.0) + value;\n"
        + " float part1 = mod(220.0 * temp, 1.0) + temp;\n"
        + " float part2 = value * 0.5453;\n"
        + " float part3 = cos(theta1 + theta2) * 0.43758;\n"
        + " float sum = (part1 + part2 + part3);\n" +
        "\n"
        + " return fract(sum)*scale;\n"
        + "}\n"
        + "\n"
        + "void main() {\n"
        + seedString[0]
        + seedString[1]
        + scaleString
        + stepX
        + stepY
        + "\n"
        + " float noise = texture2D(tex_sampler_1, vTextureCoord + vec2(-stepX, -stepY)).r * 0.224;\n"
        + " noise += texture2D(tex_sampler_1, vTextureCoord + vec2(-stepX, stepY)).r * 0.224;\n"
        + " noise += texture2D(tex_sampler_1, vTextureCoord + vec2(stepX, -stepY)).r * 0.224;\n"
        + " noise += texture2D(tex_sampler_1, vTextureCoord + vec2(stepX, stepY)).r * 0.224;\n"
        + " noise += 0.4448;\n"
        + " noise *= scale;\n"
        + "\n"
        + " vec4 color = texture2D(tex_sampler_0, vTextureCoord);\n"
        + " float energy = 0.33333 * color.r + 0.33333 * color.g + 0.33333 * color.b;\n"
        + " float mask = (1.0 - sqrt(energy));\n"
        + " float weight = 1.0 - 1.333 * mask * noise;\n"
        + "\n"
        + " gl_FragColor = vec4(color.rgb * weight, color.a);\n"
        + "}\n";

Problem is.. original fragment shader was working in android 4.4. however, that was not working in android 6.0.
So I changed gl_FragColor = vec4(color.rgb * weight, color.a); in my fragment shader source.
String shader = "#extension GL_OES_EGL_image_external : require\n"
        + "precision mediump float;\n"
        + "vec2 seed;\n"
        + "varying vec2 vTextureCoord;\n"
        + "uniform samplerExternalOES tex_sampler_0;\n"
        + "uniform samplerExternalOES tex_sampler_1;\n\n"
        + "float scale;\n"
        + "float stepX;\n"
        + "float stepY;\n\n"
        + "float rand(vec2 loc) {\n"
        + " float theta1 = dot(loc, vec2(0.9898, 0.233));\n"
        + " float theta2 = dot(loc, vec2(12.0, 78.0));\n"
        + " float value = cos(theta1) * sin(theta2) + sin(theta1) * cos(theta2);\n"
        + " float temp = mod(197.0 * value, 1.0) + value;\n"
        + " float part1 = mod(220.0 * temp, 1.0) + temp;\n"
        + " float part2 = value * 0.5453;\n"
        + " float part3 = cos(theta1 + theta2) * 0.43758;\n"
        + " float sum = (part1 + part2 + part3);\n" +
        "\n"
        + " return fract(sum)*scale;\n"
        + "}\n"
        + "\n"
        + "void main() {\n"
        + seedString[0]
        + seedString[1]
        + scaleString
        + stepX
        + stepY
        + "\n"
        + " float noise = texture2D(tex_sampler_1, vTextureCoord + vec2(-stepX, -stepY)).r * 0.224;\n"
        + " noise += texture2D(tex_sampler_1, vTextureCoord + vec2(-stepX, stepY)).r * 0.224;\n"
        + " noise += texture2D(tex_sampler_1, vTextureCoord + vec2(stepX, -stepY)).r * 0.224;\n"
        + " noise += texture2D(tex_sampler_1, vTextureCoord + vec2(stepX, stepY)).r * 0.224;\n"
        + " noise += 0.4448;\n"
        + " noise *= scale;\n"
        + "\n"
        + " vec4 color = texture2D(tex_sampler_0, vTextureCoord);\n"
        + " float energy = 0.33333 * color.r + 0.33333 * color.g + 0.33333 * color.b;\n"
        + " float mask = (1.0 - sqrt(energy));\n"
        + " float weight = 1.0 - 1.333 * mask * noise;\n"
        + "\n"
        + " // gl_FragColor = vec4(color.rgb * weight, color.a);\n"
        + " gl_FragColor = vec4(color.rgb, color.a);\n"
        + " gl_FragColor = gl_FragColor\n"
        + "     + vec4(rand(vTextureCoord + seed),\n"
        + "            rand(vTextureCoord + seed),\n"
        + "            rand(vTextureCoord + seed), 1);\n"
        + "}\n";

I want to know this problem's cause and solution.
Thank you.

A:

Well 1282 in your case is probably GL_INVALID_OPERATION.
I think your Uniform location is invalid in your line
GLES20.glUniformMatrix4fv(uMVPMatrixHandle, 1, false, mVPMatrix, 0);
//or
GLES20.glUniformMatrix4fv(uSTMatrixHandle, 1, false, sTMatrix, 0);

check your glGetUniformLocation() method where you get your uMVPMatrixHandle as well as uSTMatrixHandle and the problem might be there. Make sure the name matches the one in your vertex shader.

