问题
I have an app that I'm working on that uses openGL ES 2.0 on an android device. The app contains some buttons that are displayed using programmatic layout controls. This button pad is superimposed on a OpenGl Surface View. When I run the app on the tablet the buttons appear but the Surface View is grey, the color of the background for the 3d model I've created. This leads me to believe there's something wrong with my shaders. I use many uniform vec2's in my fragment shader. I'm looking at this web site:
http://www.shaderific.com/glsl-variables/
and it says there's a built in function that you can use to tell how many uniform vectors your implementations of GL uses. How do I run this code in android?
gl_MaxFragmentUniformVectors
I print out the contents of GLES20.GL_MAX_FRAGMENT_UNIFORM_VECTORS and I get the number 36349. My shader uses about 20.
If that doesn't lead to anything, this is the basic error. The app works on a Motorola Bionic, Android 4.1.2, but doesn't work on a Samsung Galaxy Tab/Pro, Android 4.4.2! Of course I would like it to work on both.
W/ApplicationPackageManager﹕ getCSCPackageItemText()
E/MoreInfoHPW_ViewGroup﹕ Parent view is not a TextView
below is a log for the Samsung device.
10-10 14:27:03.723 30456-30462/org.android.airplane D/dalvikvm﹕ Debugger has detached; object registry had 1 entries
10-10 14:38:55.833 1269-1269/org.android.airplane I/SELinux﹕ Function: selinux_android_load_priority [0], There is no sepolicy file.
10-10 14:38:55.833 1269-1269/org.android.airplane I/SELinux﹕ Function: selinux_android_load_priority , loading version is VE=SEPF_SM-T320_4.4.2_0018
10-10 14:38:55.833 1269-1269/org.android.airplane I/SELinux﹕ selinux_android_seapp_context_reload: seapp_contexts file is loaded from /seapp_contexts
10-10 14:38:55.843 1269-1269/org.android.airplane D/dalvikvm﹕ Late-enabling CheckJNI
10-10 14:38:55.943 1269-1269/org.android.airplane W/ApplicationPackageManager﹕ getCSCPackageItemText()
10-10 14:38:55.983 1269-1269/org.android.airplane E/MoreInfoHPW_ViewGroup﹕ Parent view is not a TextView
10-10 14:38:56.083 1269-1269/org.android.airplane I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: ()
OpenGL ES Shader Compiler Version: E031.24.00.07
Build Date: 01/22/14 Wed
Local Branch: base_au149_adreno_au169_patches
Remote Branch:
Local Patches:
Reconstruct Branch:
10-10 14:38:56.113 1269-1269/org.android.airplane D/OpenGLRenderer﹕ Enabling debug mode 0
10-10 14:38:58.823 1269-1269/org.android.airplane W/ApplicationPackageManager﹕ getCSCPackageItemText()
回答1:
GL_MAX_FRAGMENT_UNIFORM_VECTORS
is not the number of uniforms supported. It's an enum value that allows you to query that value. You get the actual value by calling:
int valA[] = new int[1];
GLES20.glGetIntegerv(GLES20.GL_MAX_FRAGMENT_UNIFORM_VECTORS, valA, 0);
int maxUniforms = valA[0];
The ES 2.0 spec requires implementations to support at least 16 uniform vectors. So it's theoretically possible that you're above the limit if you use 20. I would be surprised if the limit is really that low on a modern device, but you should definitely check.
As with any other kind of OpenGL problems, I'm sure that you already called glGetError()
, and checked the result.
Other than that, make sure that you check the result of shader compilations and linking with glGetShaderiv()
, glGetShaderInfoLog()
, glGetProgramiv()
, and glGetProgramInfoLog()
. Some GLSL compilers are stricter than others at enforcing standard compliance, so it's quite common that your shaders will work on some devices even though they contain errors.
Another thing you can try is to call glValidateProgram()
, and then check the result using glGetProgramiv()
with the GL_VALIDATE_STATUS
argument. This is best done after you set up all your state, immediately before making the first draw call. This can report problems with the program that could not be detected at compile/link time because they depend on the settings of other state.
回答2:
An update solved the problem. My Samsung device works now!
来源:https://stackoverflow.com/questions/26306567/android-gles20-works-on-bionic-4-1-2-but-not-on-samsung-4-4-2