I need to check dynamically if the used device supports openGL ES 2.0. How can i do that?
-
GLES20 is added on API level 8, shouldn't it be enough to check against it instead? – harism Feb 08 '12 at 17:46
-
2harism: That is not true. I have HTC Wildfire with Android 2.2.1. It doesn't support OpenGL ES 2.0. – petrnohejl Jun 19 '13 at 12:56
7 Answers
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
.
-
1getDeviceConfigurationInfo() 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
and – jeroent Aug 09 '14 at 22:07tags. ' So it seems these are device requirments you added to your app instead of it being info about the device. -
1@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. – Foggzie Aug 13 '14 at 05:00
-
-
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");
}

- 54,145
- 21
- 145
- 203
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());

- 1,871
- 1
- 17
- 15
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.

- 1,714
- 6
- 28
- 57
-
1This 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. – Foggzie Feb 08 '12 at 17:41
This code working Fine..
// 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) {
Log.i("JO", "configurationInfo.reqGlEsVersion:"
+ configurationInfo.reqGlEsVersion + "supportsEs2:"
+ supportsEs2);
// Request an OpenGL ES 2.0 compatible context.
myGlsurfaceView.setEGLContextClientVersion(2);
final DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
// Set the renderer to our demo renderer, defined below.
myRenderer = new MyRenderer(this, myGlsurfaceView);
} 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.
return;
}

- 1,985
- 4
- 32
- 63
For a while, I've been looking for the same answer, too. But unfortunately, I couldn't find a proper description for that. I just found a way a minute ago by myself, and I feel like I'd like to share it with everyone.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FeatureInfo[] list = this.getPackageManager()
.getSystemAvailableFeatures();
Toast.makeText(this,
"OpenGL ES Version: " + list[list.length - 1].getGlEsVersion(),
Toast.LENGTH_LONG).show();
}

- 1,360
- 11
- 18
Never used OpenGL ES, but saw it has the same glGetString
method as OpenGL. It should do the trick:
http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGetString.xml

- 6,429
- 2
- 34
- 49