Android OpenGL ES 2.0 debug helper
在程式中的任何一個地方加入以下訊息
即可知道目前 OpenGL 有沒有任何 error
Log.e(TAG, "check_gl_error_and_print: " + GLES20.glGetError());
檢查 vertex shader 是否 build failed
int buf[] = new int[1];
IntBuffer intBuf = IntBuffer.wrap(buf);
GLES20.glGetShaderiv(vertexShader, GL_COMPILE_STATUS, intBuf);
Log.e(TAG, "vertexShader GL_COMPILE_STATUS = " + intBuf.get(0));
檢查 fragment shader 是否 build failed
GLES20.glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, intBuf);
Log.e(TAG, "fragmentShader GL_COMPILE_STATUS = " + intBuf.get(0));
如果 build failed, intBuf.get(0)就會是 0
可以用下列的 code 取得更詳細的資訊
if (0 == intBuf.get(0)) {
int length[] = new int[1024];
IntBuffer lengthBuf = IntBuffer.wrap(length);
GLES20.glGetShaderiv(fragmentShader, GL_INFO_LOG_LENGTH, lengthBuf);
String infoLog = GLES20.glGetShaderInfoLog(fragmentShader);
Log.e(TAG, "infoLog = " + infoLog);
}