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

20,856

Solution 1

I'm going to expand on this answer. There's the initial part in that answer with the configuration info and getting the reqGlEsVersion. Note that it gets the actual OpenGL version of the device, not the required one declared in the manifest as suggested in some comments.

However, I stumbled over a fairly obvious method in the ConfigurationInfo class called getGlEsVersion. It relies on the reqGlEsVersion system in the ConfigurationInfo class, and returns a String value. With some tiny setup, I made a simple test snippet:

ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();

System.out.println(Double.parseDouble(configurationInfo.getGlEsVersion()));
System.out.println(configurationInfo.reqGlEsVersion >= 0x30000);
System.err.println(String.format("%X", configurationInfo.reqGlEsVersion));

The device I tested on supports and uses GLES 3.2, and the test app declares GLES3.0 in the manifest

Runnig this prints:

3.2
true
30002 //A note about this one: It doesn't print as 0x30002 because of the printing method. But it is the same as 0x30002

The entire point of those three print statements was to show that either way works. It prints the version supported of the device, and not that declared in the manifest as mentioned in some comments.

So you can use either of these ways to check the version of OpenGL ES on a given device. Personally, I use this:

double version = Double.parseDouble(configurationInfo.getGlEsVersion());
System.out.println("Version: " + version);//Optional obviously, but this is the reason I use the String and parse it to a double
if(version < 3)
    throw new RuntimeException("Unsupported GLES version");

but this also works (and is slightly more memory efficient):

int version = configurationInfo.getGlEsVersion();
//format and print here if wanted
if(version < 0x30000)
    throw new RuntimeException("Unsupported GLES version");

you could of course show a toast and quit, a dialog, an activity, a fragment, whatever you feel like if the user doesn't meet the requirement. You also should, because if it comes from a third party site, there's a chance requirements were bypassed. I just throw an exception because I declare the usage of GLES3 in the manifest, meaning that throw shouldn't happen in the first place.

As for the manifest tag:

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

This doesn't prevent apps with GLES2 or lower from installing it if they got for an instance a direct install from an APK file or through USB debugging. It's a flag that tells Google Play (or any other stores that exist and check for that) that GLES < (in this case) 3 isn't supported and Google Play would prevent the install. But anyone could install it from a mirror that ignores things like that, so the tag itself isn't a way of preventing GLES2 and lower devices from installing it.

And there's of course the eglCreateContext() method, but that only works with the native system. It does not work with things like LibGDX or anything that uses a separate renderer since it would create a different context than the library would use.

And glGetString(GL_VERSION) would work mostly anywhere, assuming the method is supported by the library/framework. It's natively integrated into GLES2 though, and requires actually creating the OpenGL context first. Using the first methods seem like a better choice on Android. However, this is, of course, up to you.

Solution 2

yes download CPU-Z and every piece of info of your phone is in this app.

its on the play store as: CPU-Z.

Solution 3

I think this code will help you

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

this article can help you more

http://www.learnopengles.com/android-lesson-one-getting-started/

Solution 4

This is documented here in the Android SDK documentation:

http://developer.android.com/guide/topics/graphics/opengl.html#version-check

You basically have 3 options:

  1. If your app only works with ES 3.0, you request that version in your manifest:

    <uses-feature android:glEsVersion="0x00030000" android:required="true" />
    
  2. You try to create an ES 3.0 context using eglCreateContext(), and check if it succeeds.

  3. You create an ES 2.0 context, and then check the supported version with glGetString(GL_VERSION).

The link above has sample code for solutions 2 and 3.

Share:
20,856
NullPointerException
Author by

NullPointerException

Updated on July 09, 2022

Comments

  • NullPointerException
    NullPointerException almost 2 years

    I need to check dynamically if the used device supports openGL ES 3.0.

    How can I do that?

    I can't find anything in google or here...