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

发布于 2025-01-03 21:33:22 字数 51 浏览 3 评论 0原文

我需要动态检查所使用的设备是否支持 openGL ES 2.0。 我怎样才能做到这一点?

I need to check dynamically if the used device supports openGL ES 2.0.
How can i do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

就是爱搞怪 2025-01-10 21:33:22

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

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" />

另请参阅uses-feature<的文档/a>.

Yes. The following code will do the trick:

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

Read this for more info:
http://www.learnopengles.com/android-lesson-one-getting-started/

You may also require want to restrict devices that don't support 2.0 from seeing your app in the marketplace by adding the following to your manifest:

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

See also the doc of uses-feature.

莫言歌 2025-01-10 21:33:22

除了以其他人提到的方式检查代码之外,如果您想将其限制在市场上仅适用于具有 2.0 的设备,则在清单中:

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

您应该同时执行这两项操作,我已经让人们将 apk 直接安装到不合适的设备上并且必须处理奇怪的异常。现在我抛出一个运行时间:

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

In addition to checking in code in the ways that others have mentioned, if you want to restrct it in market to ONLY those devices with 2.0 then in manifest:

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

You should do both, I've had people install the apk directly on to unsuitable devices and had to deal with strange exceptions. Now I throw a 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");
    }
坏尐絯 2025-01-10 21:33:22

确定 OpenGL 扩展:

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

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

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

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

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

Determining OpenGL extensions :

Implementations of OpenGL vary by Android device in terms of the extensions to the OpenGL ES API that are supported. These extensions include texture compressions, but typically also include other extensions to the OpenGL feature set.

To determine what texture compression formats, and other OpenGL extensions, are supported on a particular device:

Run the following code on your target devices to determine what texture compression formats are supported:

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

Warning: The results of this call vary by device! You must run this call on several target devices to determine what compression types are commonly supported.
Review the output of this method to determine what OpenGL extensions are supported on the device.

不知所踪 2025-01-10 21:33:22

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

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

You can use this code in your code:

            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());
岁月打碎记忆 2025-01-10 21:33:22

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

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

Never used OpenGL ES, but saw it has the same glGetString method as OpenGL. It should do the trick:

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

温暖的光 2025-01-10 21:33:22

这段代码工作正常..

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

This code working Fine..

     // 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;
    }
┾廆蒐ゝ 2025-01-10 21:33:22

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

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

For a while, I've been looking for the same answer, too. But unfortunately, I couldn't find a proper description for that. I just found a way a minute ago by myself, and I feel like I'd like to share it with everyone.

@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();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文