有没有办法检查Android设备是否支持openGL ES 3.0?
我觉得这个代码将有助于你
final ActivityManager activityManager =
(ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
final ConfigurationInfo configurationInfo =
activityManager.getDeviceConfigurationInfo();
final boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x30000;
这篇文章可以帮助您更
http://www.learnopengles.com/android-lesson-one-getting-started/
我不认为这给出了所需的信息。基于'ConfigurationInfo'文档,听起来像这样会在应用程序清单中给出应用程序所请求的版本,而不是设备支持的版本。 – 2014-08-30 15:52:28
这不会检查设备支持的版本,但会检查您配置应用的方式。 – crazypeter 2017-11-29 21:45:44
这是在Android SDK docume中记录的ntation:
http://developer.android.com/guide/topics/graphics/opengl.html#version-check
你基本上有3种选择:
-
如果你的应用程序只与ES 3.0的作品,你要求的版本在你的清单:
<uses-feature android:glEsVersion="0x00030000" android:required="true" />
你尝试使用
eglCreateContext()
创建一个ES 3.0上下文,并检查它是否成功。您创建ES 2.0上下文,然后使用
glGetString(GL_VERSION)
检查支持的版本。
上面的链接有解决方案2每一件你的手机信息是在此应用程序示例代码和3
我打算扩展this answer。这个答案的最初部分是配置信息并获得reqGlEsVersion
。它获取设备的实际GL版本,而不是在某些评论中建议的清单中声明的必需版本。
但是,我偶然发现了ConfigurationInfo
类中一个相当明显的方法,叫做getGlEsVersion
。它依赖于ConfigurationInfo类中的reqGlEsVersion
系统,并返回一个String值。与一些微小的安装,我做一个简单的试验片段:
ActivityManager activityManager =
(ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
ConfigurationInfo configurationInfo =
activityManager.getDeviceConfigurationInfo();
System.err.println(Double.parseDouble(configurationInfo.getGlEsVersion()));
System.err.println(configurationInfo.reqGlEsVersion >= 0x30000);
System.err.println(String.format("%X", configurationInfo.reqGlEsVersion));
我上运行测试GLES 3.2和应用程序在清单
声明GLES3.0的装置即打印,在各自的顺序:
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
这三个打印语句的全部内容都表明这两种方法都有效。它打印支持该设备的版本,而不是在某些注释中提到的清单中声明的版本。
因此,您可以使用以下任一方法检查给定设备上的OpenGL ES版本。就个人而言,我用这个:
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");
,但是这也适用:
int version = configurationInfo.reqGlEsVersion;
//format and print here if wanted
if(version < 0x30000)
throw new RuntimeException("Unsupported GLES version");
你当然可以显示一个面包和退出,一个对话框,一个活动,一个片段,不管你觉得像。我只是抛出一个异常,因为我在manifest中声明了GLES3的用法,这意味着抛出不应该发生在第一位。
而对于清单标签:
<uses-feature android:glEsVersion="0x00030000" android:required="true" />
这不会阻止安装,如果他们已经有了例如与GLES2或应用更低从APK文件或USB调试直接安装。这是一个标志,告知Google Play(或任何其他存在并检查该商店的商店),GLES <(在这种情况下)3不受支持,Google Play将阻止安装。但任何人都可以从一个忽略这种事情的镜像安装它,所以标签本身不是阻止GLES2和更低级设备安装的方式。
当然有eglCreateContext()
方法,但只适用于本机系统。它不适用于诸如LibGDX之类的东西或任何使用单独渲染器的东西,因为它会创建与库所使用的不同的上下文。
和glGetString(GL_VERSION)
大多数情况下都可以工作,假设该方法受库/框架支持。尽管它本地集成到GLES2中。
http://*.com/questions/9198293/is-there-a-way-to-check-if-android-device-supports-opengl-es-2-0 google on google ... – TheWhiteLlama 2014-08-30 15:40:36
除了这个问题上的最高票数和被接受的答案没有真正地回答它。 – 2014-08-30 16:03:06
ohhhh你就像爱因斯坦,兄弟,这个问题是为opengl 2.0 – NullPointerException 2014-08-30 16:03:37