I'm trying to play a video on GlSurfaceView by creating a custom class that extends GlSurfaceView and I've called that class in MainActivity but my app throws an error (glUseProgram: glError 1280). I'm a bit new to open-gl so I don't know much about it. I'm thankful if someone can able to help me to solve this issue.
Below are my fragment and vertex shader:
private final String mVertexShader = "uniform mat4 uMVPMatrix;\n" +
"uniform mat4 uSTMatrix;\n" +
"attribute vec4 aPosition;\n" +
"attribute vec4 aTextureCoord;\n" +
"varying vec2 vTextureCoord;\n" +
"void main() {\n " +
"gl_Position = uMVPMatrix * aPosition;\n" +
" vTextureCoord = (uSTMatrix * aTextureCoord).xy;\n" +
"}\n";
private final String mFragmentShader = "#extension GL_OES_EGL_image_external : require\n" +
"precision mediump float;\nvarying vec2 vTextureCoord;\n" +
"uniform samplerExternalOES sTexture;\n" +
"uniform sampler2D mLutID;\n" +
"void main() {\n " +
"vec4 texColor = texture2D(sTexture, vTextureCoord); texColor.g = clamp(texColor.g, 0.0, 0.98);\n " +
"mediump float blueColor = texColor.b * 24.0;\n " +
"mediump vec2 quad1;\n " +
"quad1.y = min(floor(blueColor), 24.0);\n " +
"quad1.x = 0.0;\n " +
"mediump vec2 quad2;\n " +
"quad2.y = min(ceil(blueColor), 24.0); quad2.x = 0.0;\n " +
"highp vec2 texPos1; \n " +
"texPos1.x = 0.5/25.0 + ((1.0 - 1.0/25.0) * texColor.r);\n " +
"texPos1.y = (quad1.y / 25.0) + 0.5/625.0 + ((1.0/25.0 - 1.0/625.0) * texColor.g);\n " +
"highp vec2 texPos2;\n " +
"texPos2.x = 0.5/25.0 + ((1.0 - 1.0/25.0) * texColor.r);\n " +
"texPos2.y = (quad2.y / 25.0) + 0.5/625.0 + ((1.0/25.0 - 1.0/625.0) * texColor.g);\n " +
"lowp vec4 newColor1 = texture2D(mLutID, texPos1);\n " +
"lowp vec4 newColor2 = texture2D(mLutID, texPos2);\n " +
"lowp vec4 newColor = mix(newColor1, newColor2, fract(blueColor));\n " +
"gl_FragColor = newColor;\n}";
And here is the onDrawFrame method:
public void onDrawFrame(GL10 glUnused) {
synchronized (this) {
if (this.updateSurface) {
this.mSurface.updateTexImage();
this.mSurface.getTransformMatrix(this.mSTMatrix);
this.updateSurface = false;
}
}
GLES20.glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
GLES20.glUseProgram(mProgram); //getting error on this
checkGlError("glUseProgram");
GLES20.glActiveTexture(GL_TEXTURE_EXTERNAL_OES);
GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, this.mTextureID);
if (this.change) {
GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, this.mLutID);
GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, GLES20.GL_ZERO, GLES20.GL_ZERO, GLES20.GL_ZERO, VideoSurfaceView.this.lut.getNumLevels(), VideoSurfaceView.this.lut.getNumLevels() * VideoSurfaceView.this.lut.getNumLevels(), GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, IntBuffer.wrap(this.dat));
}
GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, this.mLutID);
GLES20.glUniform1i(this.maLutHandle, GLES20.GL_LINE_STRIP);
this.mTriangleVertices.position(GLES20.GL_ZERO);
GLES20.glVertexAttribPointer(this.maPositionHandle, GLES20.GL_LINE_STRIP, GLES20.GL_FLOAT, false, 20, (Buffer) this.mTriangleVertices);
checkGlError("glVertexAttribPointer maPosition");
GLES20.glEnableVertexAttribArray(this.maPositionHandle);
checkGlError("glEnableVertexAttribArray maPositionHandle");
this.mTriangleVertices.position(3);
GLES20.glVertexAttribPointer(this.maTextureHandle, GLES20.GL_LINE_STRIP, GLES20.GL_FLOAT, false, 20, (Buffer) this.mTriangleVertices);
checkGlError("glVertexAttribPointer maTextureHandle");
GLES20.glEnableVertexAttribArray(this.maTextureHandle);
checkGlError("glEnableVertexAttribArray maTextureHandle");
Matrix.setIdentityM(this.mMVPMatrix, 0);
GLES20.glUniformMatrix4fv(this.muMVPMatrixHandle, GLES20.GL_LINES, false, this.mMVPMatrix, GLES20.GL_ZERO);
GLES20.glUniformMatrix4fv(this.muSTMatrixHandle, GLES20.GL_LINES, false, this.mSTMatrix, GLES20.GL_ZERO);
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, GLES20.GL_ZERO, GLES20.GL_TRIANGLES);
checkGlError("glDrawArrays");
GLES20.glFinish();
}