有没有办法检查Android设备是否支持openGL ES 3.0?

时间:2014-08-30 15:36:28

标签: android opengl-es opengl-es-3.0

我需要动态检查所用设备是否支持openGL ES 3.0。

我该怎么做?

我在谷歌或这里找不到任何东西......

4 个答案:

答案 0 :(得分:4)

我要扩展this answer。这个答案的初始部分包含配置信息并获取reqGlEsVersion。请注意,它会获得设备的实际OpenGL版本,在清单中声明的​​所需版本,如某些评论中所建议的那样。

但是,我在名为ConfigurationInfo的{​​{1}}类中偶然发现了一个相当明显的方法。它依赖于ConfigurationInfo类中的getGlEsVersion系统,并返回String值。通过一些小小的设置,我制作了一个简单的测试片段:

reqGlEsVersion

我测试的设备支持并使用GLES 3.2,测试应用程序在清单中声明GLES3.0

Runnig打印:

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));

这三个印刷陈述的全部内容是表明两种方式都有效。它打印设备支持的版本,而不是某些注释中提到的清单中声明的​​版本。

因此,您可以使用以下任一方法检查给定设备上的OpenGL ES版本。就个人而言,我用这个:

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

但这也有效(并且内存效率稍高):

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");

当然,如果用户不满足要求,您可以显示祝酒和退出,对话,活动,片段等。你也应该这样做,因为如果它来自第三方网站,那么就有机会要求被绕过了。我只是抛出异常,因为我在清单中声明了GLES3的使用,这意味着抛出不应该首先发生。

清单标签:

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

如果他们从APK文件或通过USB调试直接安装实例,这不会阻止GLES2或更低版本的应用程序安装它。它是告诉Google Play(或任何其他存在并检查存储的商店)GLES&lt; (在这种情况下)3不受支持,Google Play会阻止安装。但任何人都可以从忽略这类内容的镜像中安装它,因此标签本身并不是防止GLES2和较低设备安装它的方法。

当然还有<uses-feature android:glEsVersion="0x00030000" android:required="true" /> 方法,但这只适用于本机系统。它不适用于LibGDX或使用单独渲染器的任何东西,因为它会创建一个与库不同的上下文。

假设该方法得到库/框架的支持,eglCreateContext()几乎可以在任何地方工作。它本身已集成到GLES2中,并且需要首先实际创建OpenGL上下文。在Android上使用第一种方法似乎是更好的选择。但是,这当然取决于你。

答案 1 :(得分:1)

我认为此代码可以帮助您

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/

答案 2 :(得分:1)

Android SDK文档中记录了这一点:

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

你基本上有3个选择:

  1. 如果您的应用仅适用于ES 3.0,则可以在清单中请求该版本:

    <uses-feature android:glEsVersion="0x00030000" android:required="true" />
    
  2. 您尝试使用eglCreateContext()创建ES 3.0上下文,并检查它是否成功。

  3. 您创建ES 2.0上下文,然后使用glGetString(GL_VERSION)检查支持的版本。

  4. 上面的链接包含解决方案2和3的示例代码。

答案 3 :(得分:0)

是下载CPU-Z,手机的每条信息都在此应用中。

它在Play商店中:CPU-Z。