我在Android上使用open gl es来显示用透明色替换的黑色视频。但是当我使用我的特定着色器GL_INVALID_OPERATION错误代码时。
这是我的着色器:
protected final String mFragmentShader =
"#extension GL_OES_EGL_image_external : require\n" +
"uniform samplerExternalOES sTexture;\n" +
"varying vec2 vTextureCoord;\n" +
"vec4 color;\n" +
"\n" +
"void main(){\n" +
" color = texture2D(sTexture, vTextureCoord);\n" +
" if(color.r < 0.1 && color.g < 0.1 && color.b < 0.1){\n" +
" gl_FragColor = vec4(0.0,0.0,0.0,0.0);\n" +
" } else{\n" +
" gl_FragColor = color;\n" +
" }\n" +
"}";
当我使用下一个着色器时 - 一切都显示良好(当然透明度除外)
protected final String mFragmentShader =
"#extension GL_OES_EGL_image_external : require\n" +
"precision mediump float;\n" +
"varying vec2 vTextureCoord;\n" +
"uniform samplerExternalOES sTexture;\n" +
"void main() {\n" +
" gl_FragColor = texture2D(sTexture, vTextureCoord);\n" +
"}\n";
这是我的onDrawFrame代码:
public void onDrawFrame(GL10 glUnused) {
if(!mMediaPlayer.isPlaying())
return;
synchronized (this) {
if (updateSurface) {
mSurface.updateTexImage();
mSurface.getTransformMatrix(mSTMatrix);
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);
checkGlError("glUseProgram");
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTextureID);
mTriangleVertices.position(TRIANGLE_VERTICES_DATA_POS_OFFSET);
GLES20.glVertexAttribPointer(maPositionHandle, 3, GLES20.GL_FLOAT, false,
TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mTriangleVertices);
checkGlError("glVertexAttribPointer maPosition");
GLES20.glEnableVertexAttribArray(maPositionHandle);
checkGlError("glEnableVertexAttribArray maPositionHandle");
mTriangleVertices.position(TRIANGLE_VERTICES_DATA_UV_OFFSET);
GLES20.glVertexAttribPointer(maTextureHandle, 3, GLES20.GL_FLOAT, false,
TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mTriangleVertices);
checkGlError("glVertexAttribPointer maTextureHandle");
GLES20.glEnableVertexAttribArray(maTextureHandle);
checkGlError("glEnableVertexAttribArray maTextureHandle");
Matrix.setIdentityM(mMVPMatrix, 0);
GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0);
GLES20.glUniformMatrix4fv(muSTMatrixHandle, 1, false, mSTMatrix, 0);
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
checkGlError("glDrawArrays");
GLES20.glFinish();
}
可能是什么问题?
答案 0 :(得分:1)
问题在于浮动精度。当我在第一个着色器中设置precision mediump float
时,一切都运行良好
答案 1 :(得分:-1)
在您的第一个着色器中,当您使用color.r
时,您正在使用color.x
,依此类推。 vec4
对象是成员x,y,z,w