如果不在代码中使用,只是想知道你手头Android设备所使用的GLES的版本,可以用如下1)和2)中的个方法:
1) 查询系统属性ro.opengles.version
可以直接使用adb shell 命令getprop ro.opengles.version来查询gles版本号。
这个属性在ActivityManagerService中有用到,ams有一个final成员变量GL_ES_VERSION, 它是在ActivityManagerService的构造函数中被赋值的:
public class ActivityManagerService extends IActivityManager.Stub
implements Watchdog.Monitor, BatteryStatsImpl.BatteryCallback {
.....
/**
* Hardware-reported OpenGLES version.
*/
final int GL_ES_VERSION;
......
// Note: This method is invoked on the main thread but may need to attach various
// handlers to other threads. So take care to be explicit about the looper.
public ActivityManagerService(Context systemContext) {
......
GL_ES_VERSION = SystemProperties.getInt("ro.opengles.version",
ConfigurationInfo.GL_ES_VERSION_UNDEFINED);
......
}
.......
}
所以只读属性ro.opengles.version就保存着当前Android设备的gles版本;同时查看ams中对GL_ES_VERSION的使用可知,ams的getDeviceConfigurationInfo方法返回的ConfigurationInfo对象中的字段reqGlEsVersion也是使用的GL_ES_VERSION的值,所以用如下代码可以在应用内获取当前设备的gles版本号:
private int getGLESVersion(){
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
ConfigurationInfo ci = am.getDeviceConfigurationInfo();
return ci.reqGlEsVersion;
}
2) 查看开机log
原生Android SurfaceFlinger初始化过程中会在logcat中打印如下信息:
从这里也可以看到GLES的版本号。
gl接口也提供了查询其版本号的接口,在代码中查询时可以这样使用:
#include <GLES/gl.h>
#include <log/log.h>
void getGlVersion() {
const char* version = (const char*)glGetString(GL_VERSION);
ALOGI("GL_VERSION: %s", version);
}