xcesco xcesco - 6 months ago 59
Android Question

GLSurfaceView with OpenGL ES 3.1 context

I'm working on Android with OpenGL. I known how to use

and its custom derivate classes to create OpenGL ES 2.0 context with method of


and OpenGL ES 3.0 context:


How can i create a context for OpenGL ES 3.1?


You can't explicitly request 3.1 when you create the context. Based on my understanding, 3.1 is not handled as a context type separate from 3.0. Essentially, a context supporting 3.1 is just a 3.0 context that also supports the additional 3.1 features.

This means that you can still use:


If you want to check/verify what version is supported by the context, you can query it once you have the context up and running:

int[] vers = new int[2];
GLES30.glGetIntegerv(GLES30.GL_MAJOR_VERSION, vers, 0);
GLES30.glGetIntegerv(GLES30.GL_MINOR_VERSION, vers, 1);
if (vers[0] > 3 || (vers[0] == 3 && vers[1] >= 1)) {
    // We have at least ES 3.1.


The latest version of EGL, which is 1.5 [*], actually does have context creation attributes that allow specifying both a major and minor version (attributes EGL_CONTEXT_MAJOR_VERSION and EGL_CONTEXT_MINOR_VERSION). Versions up to and including 1.4 only have EGL_CONTEXT_CLIENT_VERSION, so they have no mechanism to specify the minor version when creating a context.

The latest released version of Android, which is 5.1.1 [*], still only supports EGL 1.4. So it's not only a question of GLSurfaceView not providing an interface. The lower native layers do not support specifying a minor version either. So adding 3.1 support to 3.0 contexts is really the only option.

[*] At the time this answer was written.