Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GLSurfaceView with OpenGL ES 3.1 context

I'm working on Android with OpenGL. I known how to use GLSurfaceView and its custom derivate classes to create OpenGL ES 2.0 context with method of GLSurfaceView:

setEGLContextClientVersion(2); 

and OpenGL ES 3.0 context:

setEGLContextClientVersion(3); 

How can i create a context for OpenGL ES 3.1?

like image 200
xcesco Avatar asked Sep 24 '15 15:09

xcesco


People also ask

How do I upgrade to OpenGL ES 3.1 on Android?

If your phone's GPU doesn't support OpenGL ES 3.1, then there's no way to upgrade. You have to buy a new phone. You can check what GPU your phone has by installing CPU-Z from the Google Play Store. Then, search your GPU in your search engine and find its Web page.

Can I use OpenGL on Android?

The basics. Android supports OpenGL both through its framework API and the Native Development Kit (NDK).

What is GLSurfaceView?

GLSurfaceView is a new API class in Android 1.5. GLSurfaceView makes OpenGL ES applications easier to write by: Providing the glue code to connect OpenGL ES to the View system. Providing the glue code to make OpenGL ES work with the Activity life-cycle. Making it easy to choose an appropriate frame buffer pixel format.

What is the difference between OpenGL and OpenGL ES?

The main difference between the two is that OpenGL ES is made for embedded systems like smartphones, while OpenGL is the one on desktops. On the coding level, OpenGL ES does not support fixed-function functions like glBegin/glEnd etc... OpenGL can support fixed-function pipeline (using a compatibility profile).


1 Answers

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:

setEGLContextClientVersion(3);

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.
}

Background

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.

like image 155
Reto Koradi Avatar answered Sep 20 '22 19:09

Reto Koradi