I am trying to draw a textured square on the screen, but whenever I try to use glGetAttribLocation
it gives me a runtimeException
and glError 1280
. I have no clue why when tested on a new end device, such as Samsung Galaxy S 3, no error was found. But on the rest of my testing devices this error kept appearing.
Here is my Vertex Shader:
uniform mat4 uMVPMatrix;
attribute vec4 aPosition;
attribute vec2 aTextureCoord;
varying vec2 vTextureCoord;
void main() {
gl_Position = uMVPMatrix * aPosition;
vTextureCoord = aTextureCoord;
}
and my Fragment Shader:
precision mediump float;
varying vec2 vTextureCoord;
uniform sampler2D sTexture;
void main() {
gl_FragColor = texture2D(sTexture, vTextureCoord);
}
and this is where the error occurs:
private void initProgram() {
mProgram = createProgram(mVertexShader, mFragmentShader);
if (mProgram == 0) {
return;
}
maPositionHandle = GLES20.glGetAttribLocation(mProgram, "aPosition");
checkGlError("glGetAttribLocation aPosition");
if (maPositionHandle == -1) {
throw new RuntimeException(
"Could not get attrib location for aPosition");
}
maTextureHandle = GLES20.glGetAttribLocation(mProgram, "aTextureCoord");
checkGlError("glGetAttribLocation aTextureCoord");
if (maTextureHandle == -1) {
throw new RuntimeException(
"Could not get attrib location for aTextureCoord");
}
muMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
checkGlError("glGetUniformLocation uMVPMatrix");
if (muMVPMatrixHandle == -1) {
throw new RuntimeException(
"Could not get attrib location for uMVPMatrix");
}
}
when checking for GLError i get the following exceptions:
12-31 21:07:56.836: E/ChizEngine(27809): glGetAttribLocation aPosition: glError 1280
12-31 21:07:56.856: W/dalvikvm(27809): threadid=9: thread exiting with uncaught exception (group=0x4001d560)
12-31 21:07:56.856: E/AndroidRuntime(27809): FATAL EXCEPTION: GLThread 10
12-31 21:07:56.856: E/AndroidRuntime(27809): java.lang.RuntimeException: glGetAttribLocation aPosition: glError 1280
12-31 21:07:56.856: E/AndroidRuntime(27809): at test.projects.ogc.util.GLHelper.checkGlError(GLHelper.java:13)
12-31 21:07:56.856: E/AndroidRuntime(27809): at test.projects.ogc.objects.GameObject.initProgram(GameObject.java:168)
12-31 21:07:56.856: E/AndroidRuntime(27809): at test.projects.ogc.objects.GameObject.Draw(GameObject.java:206)
12-31 21:07:56.856: E/AndroidRuntime(27809): at test.projects.ogc.util.ChizRenderer.drawObjects(ChizRenderer.java:110)
12-31 21:07:56.856: E/AndroidRuntime(27809): at test.projects.ogc.util.ChizRenderer.onDrawFrame(ChizRenderer.java:42)
12-31 21:07:56.856: E/AndroidRuntime(27809): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1363)
12-31 21:07:56.856: E/AndroidRuntime(27809): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)
It appears when I call glGetAttribLocation
, any idea why?
If any more information is needed, please tell me, I'm trying to figure it out for few hours by now with no success at all, also, its weird that I don't get any error AT ALL on the galaxy s 3
BTW i call the initProgram
function on the onSurfaceCreated
function in my renderer.
apparently the error was the checkGLError
itself (code below), after removing every call of the function from the app it worked as its supposed to on every device i checked on!
checkGLError
function:
public static void checkGlError(String op) {
int error;
while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) {
Log.e(TAG, op + ": glError " + error);
throw new RuntimeException(op + ": glError " + error);
}
}
my hypothesis is that something in the function is made for a higher api which is not supported by the 2.3 android devices that the app was checked on and that's why it worked fine on a 4.1.3 android device.
Should i just exclude the function from my app completely?