glGetString(GL_VERSION) returns “OpenGL ES-CM 1.1” but my phone supports OpenGL 2

前端 未结 2 675
情深已故
情深已故 2021-01-22 18:37

I\'m trying to make an NDK based OpenGL application. At some point in my code, I want to check the OpenGL version available on the device.

I\'m using the following code

相关标签:
2条回答
  • 2021-01-22 19:18

    What version you get from glGetString(GL_VERSION) depends on which library you've linked the code against, either libGLESv1_CM.so or libGLESv2.so. Similarly for all the other common GL functions. This means that in practice, you need to build two separate .so files for your GL ES 1 and 2 versions of your rendering, and only load the right one once you know which one of them you can use (or load the function pointers dynamically). (This apparently is different when having compatibility between GL ES 2 and 3, where you can check using glGetString(GL_VERSION).)

    You didn't say where you tried using EGL_CONTEXT_CLIENT_VERSION - it should be used in the parameter array to eglCreateContext (which you only call once you actually have chosen a config). The attribute array given to eglChooseConfig should have the pair EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT to get a suitable config.

    0 讨论(0)
  • 2021-01-22 19:19

    Thanks to the hints given by mstorsjo, I managed to have the correct initialisation code, shown here if other people struggle with this.

    const EGLint attrib_list[] = {
            // this specifically requests an Open GL ES 2 renderer
            EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, 
            // (ommiting other configs regarding the color channels etc...
            EGL_NONE
    };
    
    EGLConfig config;
    EGLint num_configs;
    eglChooseConfig(display, attrib_list, &config, 1, &num_configs);
    
    // ommiting other codes 
    
    const EGLint context_attrib_list[] = { 
            // request a context using Open GL ES 2.0
            EGL_CONTEXT_CLIENT_VERSION, 2, 
            EGL_NONE 
    };
    EGLContext context = eglCreateContext(display, config, NULL, context_attrib_list);
    
    0 讨论(0)
提交回复
热议问题