Why Gles20.glgetattriblocation Returns Different Values For Different Devices?
Solution 1:
Why GLES20.glGetAttribLocation returns different valuesfor different devices?
... because different devices will have different hardware for setting up binding tables, and in some cases may completely optimize out redundant computations and repack the used attributes to save space. This is exactly why the API has a function call for getting binding locations on the device at runtime; if they were deterministic constants you wouldn't need a run-time call at all ...
The fact it returns -1 isn't an error; it is just showing that the attribute isn't needed (e.g. defined, but can optimized out because it doesn't contribute to the fragment pixel color), so this shouldn't cause any problems.
However it does mean that you can't safely assume (e.g.) that a_Position
is always attribute 0, a_Color
is always 1, a_Normal
is always 2, etc. If you've hard coded that in your code then it's entirely possible you are uploading the wrong data to each attribute. You must query the binding locations to get the binding numbers to use (or use the shader-side static binding added in OpenGL ES 3.x).
Which actual GL API call is setting the GL error state?
Solution 2:
The Solution - multiplying with -1 value
... = GLES20.glGetAttribLocation(cubeProgram1, "a_Normal") * -1;
or
int value;
if( GLES20.glGetAttribLocation(cubeProgram1, "a_Normal") < 0){
value = -1;
}
else {
value = 1;
}
... = GLES20.glGetAttribLocation(cubeProgram1, "a_Normal") * value;
Is not the best solution, but now it works.
Post a Comment for "Why Gles20.glgetattriblocation Returns Different Values For Different Devices?"