我需要GLSurfaceView来渲染一些东西,这里让我感到困惑: 我首先调用setEGLContextClientVersion(2),但是在onSurfaceCreated()中,我调用gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT,GL10.GL_FASTEST),仅获得glError,如下所示:
这是代码:
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);
gl.glClearColor(0.5f, 0.5f, 0.5f, 1);
gl.glShadeModel(GL10.GL_FLAT);
gl.glDisable(GL10.GL_DEPTH_TEST);
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glDisable(GL10.GL_DITHER);
gl.glDisable(GL10.GL_LIGHTING);
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glGenTextures(1, mTextureNameWorkspace, 0);
int textureName = mTextureNameWorkspace[0];
gl.glBindTexture(GL10.GL_TEXTURE_2D, textureName);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);
gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_REPLACE);
final int internalFormat = GL10.GL_RGBA;
final int type = GL10.GL_UNSIGNED_BYTE;
gl.glTexImage2D(GL11.GL_TEXTURE_2D, 0, internalFormat, mCameraPreviewSprite.textureWidth, mCameraPreviewSprite.textureHeight, 0, internalFormat, type, (ByteBuffer) null);
mCameraPreviewSprite.setTextureName(textureName);
}
以下是错误消息:
E/MALI(22964): gles_state_set_error_internal:57: GLES error code:0x500
E/MeizuSource_Algo_Af(239): DEBUG: gyroinform(0, 0, 0)
E/AndroidRuntime(22964): FATAL EXCEPTION: GLThread 1335
E/AndroidRuntime(22964): Process: de.renard.glcamera, PID: 22964
E/AndroidRuntime(22964): android.opengl.GLException: invalid enum
E/AndroidRuntime(22964): at android.opengl.GLErrorWrapper.checkError(GLErrorWrapper.java:62)
E/AndroidRuntime(22964): at android.opengl.GLErrorWrapper.glHint(GLErrorWrapper.java:387)
E/AndroidRuntime(22964): at de.renard.glcamera.CameraPreviewRenderer.onSurfaceCreated(CameraPreviewRenderer.java:75)
E/AndroidRuntime(22964): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1547)
E/AndroidRuntime(22964): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1285)
然而,当我删除glHint时,会发生以下gl调用的其他类似错误,是由gl es版本引起的吗?谢谢!
以下是活动中onCreate()
函数中的代码:
if(supportsEs2)
mGlSurfaceView.setEGLContextClientVersion(2);
mGlSurfaceView.setRenderer(mRenderer);
mGlSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
mGlSurfaceView.setDebugFlags(GLSurfaceView.DEBUG_CHECK_GL_ERROR);
setContentView(mGlSurfaceView);