如果检测的OpenGL ES 2.0是否可用OpenGL、ES

2023-09-05 07:14:29 作者:一刀斩到你桃花开

我创建为Android应用程序的API等级> = 7.一个屏幕采用与OpenGL ES 2.0的一个GLSurfaceView通过NDK。我如何检测的OpenGL 2.0可用?我不能使用安卓glEsVersion =0x00020000我在AndroidManifest.xml中,因为我要支持所有的手机与API等级> = 7,如果没有为不支持2.0,我将展示静态画面。

I'm creating an application for Android for API levels >= 7. One screen uses a GLSurfaceView with OpenGL ES 2.0 through the ndk. How can I detect if opengl 2.0 is available? I can't use android:glEsVersion="0x00020000" in my AndroidManifest.xml because I have to support all phones with API levels >= 7. If there is no support for 2.0, I will be showing a static screen.

我使用的是从HELLO-GL2示例应用程序自带的NDK类似code。在GL2JNIView,当设置OpenGL的背景下,如果它没有找到一个合适的OpenGL配置(在我的情况下,配置需要的OpenGL ES 2.0),它抛出一个抛出:IllegalArgumentException(没有的configs匹配configSpec) 键,应用程序崩溃。我无法找到一个方法来截获该异常并做别的东西,屏幕上。任何想法?

I'm using similar code from the hello-gl2 sample app that comes with the ndk. In GL2JNIView, when it sets the Opengl context, if it doesn't find an appropriate opengl config (in my case a config that requires opengl es 2.0) it throws an IllegalArgumentException("No configs match configSpec") and the app crashes. I can't find a way to intercept that exception and do something else on that screen. Any ideas?

推荐答案

下面是我发现在网际网路:

Here's what I found in internets:

private boolean checkGL20Support( Context context )
{
    EGL10 egl = (EGL10) EGLContext.getEGL();       
    EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    int[] version = new int[2];
    egl.eglInitialize(display, version);

    int EGL_OPENGL_ES2_BIT = 4;
    int[] configAttribs =
    {
        EGL10.EGL_RED_SIZE, 4,
        EGL10.EGL_GREEN_SIZE, 4,
        EGL10.EGL_BLUE_SIZE, 4,
        EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
        EGL10.EGL_NONE
    };

    EGLConfig[] configs = new EGLConfig[10];
    int[] num_config = new int[1];
    egl.eglChooseConfig(display, configAttribs, configs, 10, num_config);     
    egl.eglTerminate(display);
    return num_config[0] > 0;
} 

来源:http://www.badlogicgames.com/word$p$pss/?p=343