【问题标题】:Is there a way to check if Android device supports openGL ES 2.0?有没有办法检查 Android 设备是否支持 openGL ES 2.0?
【发布时间】:2017-03-23 18:12:54
【问题描述】:

我需要动态检查使用的设备是否支持 openGL ES 2.0。 我该怎么做?

【问题讨论】:

  • GLES20 是在 API 级别 8 上添加的,难道只需要对其进行检查就足够了吗?
  • harism:这不是真的。我有 Android 2.2.1 的 HTC Wildfire。它不支持 OpenGL ES 2.0。

标签: android opengl-es opengl-es-2.0


【解决方案1】:

是的。以下代码可以解决问题:

final ActivityManager activityManager = 
    (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
final ConfigurationInfo configurationInfo = 
    activityManager.getDeviceConfigurationInfo();
final boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000;

阅读本文了解更多信息: http://www.learnopengles.com/android-lesson-one-getting-started/

您可能还需要通过将以下内容添加到清单中来限制不支持 2.0 的设备在市场上看到您的应用:

<uses-feature android:glEsVersion="0x00020000" android:required="true" />

另见the doc of uses-feature

【讨论】:

  • getDeviceConfigurationInfo() 返回一个 ConfigurationInfo,根据规范是:'您可以检索有关应用程序声明的硬件配置首选项的信息。这对应于从 AndroidManifest.xml 的 标记收集的信息。 ' 因此,这些似乎是您添加到应用中的设备要求,而不是有关设备的信息。
  • @jeroent 这就是“ConfigurationInfo”类在其规范中声明的内容,但在“getSystemService”中使用“ACTIVITY_SERVICE”上下文会检索“ActivityManager”以与全局系统状态交互。
  • 请问?以及如何检查是否支持 3.0
  • @user718559 您只需将0x00020000 替换为0x00030000
【解决方案2】:

除了以其他人提到的方式签入代码之外,如果您想在市场上将其限制为仅具有 2.0 的设备,那么在清单中:

    <uses-feature android:glEsVersion="0x00020000" android:required="true" />

你应该两者都做,我已经让人们将 apk 直接安装到不合适的设备上,并且不得不处理奇怪的异常。现在我抛出一个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");
    }

【讨论】:

    【解决方案3】:

    确定 OpenGL 扩展:

    根据支持的 OpenGL ES API 扩展,OpenGL 的实现因 Android 设备而异。这些扩展包括纹理压缩,但通常还包括对 OpenGL 功能集的其他扩展。

    要确定特定设备支持哪些纹理压缩格式和其他 OpenGL 扩展:

    在您的目标设备上运行以下代码以确定支持哪些纹理压缩格式:

      String extensions = javax.microedition.khronos.opengles.GL10.glGetString(GL10.GL_EXTENSIONS);
    

    警告:此调用的结果因设备而异!您必须在多个目标设备上运行此调用以确定通常支持哪些压缩类型。 查看此方法的输出以确定设备支持哪些 OpenGL 扩展。

    【讨论】:

    • 这个方法很复杂。如果你打算使用 glGetString() 你不会用 GL_EXTENSIONS 调用它,你会用 GL_VERSION 调用它然后解析字符串。 ConfigurationInfo 类旨在快速轻松地解决此问题。
    【解决方案4】:

    您可以在代码中使用此代码:

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

    【讨论】:

      【解决方案5】:

      从未使用过 OpenGL ES,但看到它具有与 OpenGL 相同的glGetString 方法。它应该可以解决问题:

      http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGetString.xml

      【讨论】:

        【解决方案6】:

        这段代码运行良好..

             // 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;
            }
        

        【讨论】:

          【解决方案7】:

          一段时间以来,我也一直在寻找相同的答案。但不幸的是,我找不到合适的描述。一分钟前我自己找到了一个方法,我觉得我想和大家分享一下。

          @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();
          }
          

          【讨论】:

            猜你喜欢
            • 2014-10-24
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2012-03-15
            相关资源
            最近更新 更多