我需要动态检查所使用的设备是否支持 openGL ES 3.0。
我该怎么做?
我在谷歌或这里找不到任何东西...
最佳答案
我要扩展 this answer .该答案的初始部分包含配置信息和获取 reqGlEsVersion
。请注意,它获取设备的实际 OpenGL 版本,不是一些评论中建议的在 list 中声明的必需版本。
但是,我在 ConfigurationInfo
类中偶然发现了一个相当明显的方法,名为 getGlEsVersion
。它依赖于 ConfigurationInfo 类中的 reqGlEsVersion
系统,并返回一个 String 值。通过一些微小的设置,我制作了一个简单的测试 fragment :
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));
我测试的设备支持并使用 GLES 3.2,测试应用在 list 中声明了 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
这三个 print 语句的全部意义在于表明任何一种方式都有效。它打印设备支持的版本,而不是某些评论中提到的 list 中声明的版本。
因此,您可以使用这些方法中的任何一种来检查给定设备上的 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.getGlEsVersion();
//format and print here if wanted
if(version < 0x30000)
throw new RuntimeException("Unsupported GLES version");
您当然可以显示 toast 和退出、对话、 Activity 、 fragment ,如果用户不满足要求,您可以随意显示。您也应该这样做,因为如果它来自第三方站点,则有可能绕过要求。我只是抛出一个异常,因为我在 list 中声明了 GLES3 的用法,这意味着抛出不应该首先发生。
至于 list 标签:
<uses-feature android:glEsVersion="0x00030000" android:required="true" />
这不会阻止具有 GLES2 或更低版本的应用程序安装它,例如,如果它们从 APK 文件或通过 USB 调试直接安装。这是一个标志,告诉 Google Play(或任何其他存在并检查它的商店)不支持 GLES <(在这种情况下)3,Google Play 会阻止安装。但是任何人都可以从忽略此类事情的镜像安装它,因此标签本身并不是阻止 GLES2 和更低版本设备安装它的方法。
当然还有 eglCreateContext()
方法,但它只适用于 native 系统。它不适用于 LibGDX 之类的东西或任何使用单独渲染器的东西,因为它会创建与库使用的上下文不同的上下文。
并且 glGetString(GL_VERSION)
几乎可以在任何地方使用,前提是库/框架支持该方法。虽然它原生集成到 GLES2 中,但实际上需要首先创建 OpenGL 上下文。在 Android 上使用第一种方法似乎是更好的选择。不过,这当然取决于您。
关于java - 有没有办法检查 Android 设备是否支持 openGL ES 3.0?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25584032/