Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect if OpenGl ES 2.0 is available or not

I'm creating an application for Android for API levels >= 7. One screen uses a GLSurfaceView with OpenGL ES 2.0 through the ndk. How can I detect if opengl 2.0 is available? I can't use android:glEsVersion="0x00020000" in my AndroidManifest.xml because I have to support all phones with API levels >= 7. If there is no support for 2.0, I will be showing a static screen.

I'm using similar code from the hello-gl2 sample app that comes with the ndk. In GL2JNIView, when it sets the Opengl context, if it doesn't find an appropriate opengl config (in my case a config that requires opengl es 2.0) it throws an IllegalArgumentException("No configs match configSpec") and the app crashes. I can't find a way to intercept that exception and do something else on that screen. Any ideas?

like image 402
Catalin Morosan Avatar asked Jun 23 '11 07:06

Catalin Morosan


2 Answers

Here's what I found in internets:

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

like image 189
bezmax Avatar answered Oct 05 '22 19:10

bezmax


Maybe this can 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.

  }
}
like image 38
DiegoVargasg Avatar answered Oct 05 '22 18:10

DiegoVargasg