Detecting if OpenGl ES 2.0 is Available or Not

I am creating an Android application for API levels> = 7. One screen uses GLSurfaceView with OpenGL ES 2.0 via ndk. How to determine if opengl 2.0 is available? I can not use android:glEsVersion="0x00020000" in my AndroidManifest.xml because I need to support all phones with API levels> = 7. If there is no support 2.0, I will show a static screen.

I use the same code from the hello-gl2 sample application that comes with ndk. In GL2JNIView, when it sets the Opengl context, if it does not find a suitable opengl configuration (in my case config, which requires opengl es 2.0), it throws an IllegalArgumentException("No configs match configSpec") , and the application crashes. I cannot find a way to catch this exception and do something else on this screen. Any ideas?

+7
source share
3 answers

Here is what I found on the internet:

 private boolean checkGL20Support( Context context ) { EGL10 egl = (EGL10) EGLContext.getEGL(); EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); int[] version = new int[2]; egl.eglInitialize(display, version); int EGL_OPENGL_ES2_BIT = 4; int[] configAttribs = { EGL10.EGL_RED_SIZE, 4, EGL10.EGL_GREEN_SIZE, 4, EGL10.EGL_BLUE_SIZE, 4, EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL10.EGL_NONE }; EGLConfig[] configs = new EGLConfig[10]; int[] num_config = new int[1]; egl.eglChooseConfig(display, configAttribs, configs, 10, num_config); egl.eglTerminate(display); return num_config[0] > 0; } 

Source: http://www.badlogicgames.com/wordpress/?p=343

+7
source

Maybe this will help

 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Check if the system supports OpenGL ES 2.0. final ActivityManager activityManager = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE); final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); final boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000; if (supportsEs2) { // Request an OpenGL ES 2.0 compatible context. } else { // This is where you could create an OpenGL ES 1.x compatible // renderer if you wanted to support both ES 1 and ES 2. } } 
+7
source

From Android CTS (compatibility test suite) OpenGlEsVersionTest.java :

 private static int getVersionFromPackageManager(Context context) { PackageManager packageManager = context.getPackageManager(); FeatureInfo[] featureInfos = packageManager.getSystemAvailableFeatures(); if (featureInfos != null && featureInfos.length > 0) { for (FeatureInfo featureInfo : featureInfos) { // Null feature name means this feature is the open gl es version feature. if (featureInfo.name == null) { if (featureInfo.reqGlEsVersion != FeatureInfo.GL_ES_VERSION_UNDEFINED) { return getMajorVersion(featureInfo.reqGlEsVersion); } else { return 1; // Lack of property means OpenGL ES version 1 } } } } return 1; } /** @see FeatureInfo#getGlEsVersion() */ private static int getMajorVersion(int glEsVersion) { return ((glEsVersion & 0xffff0000) >> 16); } 

In fact, it provides several other ways, and the test verifies that they all return the same results.

+1
source

All Articles