Is there a way to check if Android device supports openGL ES 2.0?

29,865

Solution 1

Yes. The following code will do the trick:

final ActivityManager activityManager = 
    (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
final ConfigurationInfo configurationInfo = 
    activityManager.getDeviceConfigurationInfo();
final boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000;

Read this for more info: http://www.learnopengles.com/android-lesson-one-getting-started/

You may also require want to restrict devices that don't support 2.0 from seeing your app in the marketplace by adding the following to your manifest:

<uses-feature android:glEsVersion="0x00020000" android:required="true" />

See also the doc of uses-feature.

Solution 2

In addition to checking in code in the ways that others have mentioned, if you want to restrct it in market to ONLY those devices with 2.0 then in manifest:

    <uses-feature android:glEsVersion="0x00020000" android:required="true" />

You should do both, I've had people install the apk directly on to unsuitable devices and had to deal with strange exceptions. Now I throw a runTime:

private boolean detectOpenGLES20() {
        ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        ConfigurationInfo info = am.getDeviceConfigurationInfo();
        return (info.reqGlEsVersion >= 0x20000);
    }

      //in activity onCreate    
    if (!detectOpenGLES20()) {
        throw new RuntimeException("Open GL ES 2.0 was not found on device");
    }

Solution 3

You can use this code in your code:

            int result;
            ActivityManager activityManager =
                    (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
            ConfigurationInfo configInfo = activityManager.getDeviceConfigurationInfo();
            if (configInfo.reqGlEsVersion != ConfigurationInfo.GL_ES_VERSION_UNDEFINED) {
                result= configInfo.reqGlEsVersion;
            } else {
                result= 1 << 16; // Lack of property means OpenGL ES version 1
            }

            Log.e("reqGlEsVersion", String.valueOf(result));
            Log.e("getGlEsVersion", configInfo.getGlEsVersion());

Solution 4

Determining OpenGL extensions :

Implementations of OpenGL vary by Android device in terms of the extensions to the OpenGL ES API that are supported. These extensions include texture compressions, but typically also include other extensions to the OpenGL feature set.

To determine what texture compression formats, and other OpenGL extensions, are supported on a particular device:

Run the following code on your target devices to determine what texture compression formats are supported:

  String extensions = javax.microedition.khronos.opengles.GL10.glGetString(GL10.GL_EXTENSIONS);

Warning: The results of this call vary by device! You must run this call on several target devices to determine what compression types are commonly supported. Review the output of this method to determine what OpenGL extensions are supported on the device.

Share:
29,865

Related videos on Youtube

Erik Sapir
Author by

Erik Sapir

Updated on March 24, 2020

Comments

  • Erik Sapir
    Erik Sapir over 4 years

    I need to check dynamically if the used device supports openGL ES 2.0. How can i do that?

    • harism
      harism over 12 years
      GLES20 is added on API level 8, shouldn't it be enough to check against it instead?
    • petrnohejl
      petrnohejl about 11 years
      harism: That is not true. I have HTC Wildfire with Android 2.2.1. It doesn't support OpenGL ES 2.0.
  • Foggzie
    Foggzie over 12 years
    This method is convoluted. If you're going to use glGetString() you wouldn't call it with GL_EXTENSIONS, you would call it with GL_VERSION and then parse the string afterwards. The ConfigurationInfo class is designed to solve this problem quickly and easily.
  • jeroent
    jeroent almost 10 years
    getDeviceConfigurationInfo() returns a ConfigurationInfo, which according to the specs is: 'Information you can retrieve about hardware configuration preferences declared by an application. This corresponds to information collected from the AndroidManifest.xml's <uses-configuration> and <uses-feature> tags. ' So it seems these are device requirments you added to your app instead of it being info about the device.
  • Foggzie
    Foggzie almost 10 years
    @jeroent That is what the 'ConfigurationInfo' class states in its specs but using the 'ACTIVITY_SERVICE' context in 'getSystemService' retrieves an 'ActivityManager' for interacting with the global system state.
  • Aaron Lee
    Aaron Lee over 7 years
    Excuse me? And how to check if support 3.0
  • Foggzie
    Foggzie over 7 years
    @user718559 You would just replace 0x00020000 with 0x00030000.