simonescu
simonescu

Reputation: 482

Mixing OpenGL ES 2.0 and 3.0

I'm trying to port an iOS project to Android (java). I've however encountered a few ES 2.0 extension functions (OES), which do not appear in the Android GLES20 API:

glGenVertexArraysOES glBindVertexArrayOES glDeleteVertexArraysOES

It appears I have to call these functions from NDK, dynamically bind the extensions at runtime and check for support od devices. Not something I'd love to do.

While googling I found these functions in the GLES30 api. So my question is: - is it possible to mix GLES20 and GLES30 calls? - are these functions basically calls to the same api or is this completely different? - any other sugggestions?

Upvotes: 3

Views: 5086

Answers (3)

keaukraine
keaukraine

Reputation: 5364

As @vadimvolk explained, you will need to check whether OpenGL driver supports OES_vertex_array_object extension. More info here: http://www.khronos.org/registry/gles/extensions/OES/OES_vertex_array_object.txt

If you just stick to use OpenGL ES 3.0, you can use these methods after checking that you've got OpenGL ES 3.0 context. In Android, you can mix calls to GLES20 and GLES30 because these APIs are backwards-compatible. All you need is to create OpenGL ES 2.0 context and check if returned context version is 3.0 by reading GL_VERSION string. If it is 3.0, you can use mix both GLES20 and GLES30 functions. Additional info: https://plus.google.com/u/0/+RomainGuy/posts/iJmTjpUfR5E

Upvotes: 2

Reto Koradi
Reto Koradi

Reputation: 54572

Just looking at the API entry points, ES 3.0 is a superset of ES 2.0. So the transition is mostly smooth. You request API version 3 when making the GLSurfaceView.setEGLContextClientVersion() call, and your ES 2.0 code should still work. Then you can start using methods from GLES30 on top of the GLES20 methods.

There are some very subtle differences, e.g. related to slight differences in cube map sampling, but you're unlikely to run into them. If you want details, see appendix F.2 of the spec document. Some features like client side vertex arrays have been declared legacy, but are still supported.

The only thing you're likely to encounter are differences in GLSL. You can still use ES 2.0 shaders as long as you keep the #version 100 in the shader code. But if you want to use the latest GLSL version (#version 300 es), there are incompatible changes. The necessary code changes are simple, it's mostly replacing attribute and varying with in and out, and not using the built-in gl_FragColor anymore. You have to switch over to the new GLSL version if you want to take advantage of certain new ES 3.0 features, like multiple render targets.

The downside of using ES 3.0 is of course that you're much more restricted in the devices your software runs on. While the latest higher-end devices mostly support ES 3.0, there are still plenty of devices out there that only support 2.0, and will stay at that level. According to the latest data from Google (http://developer.android.com/about/dashboards/index.html), 18.2% of all devices support ES 3.0 as of July 7, 2014.

Upvotes: 6

vadimvolk
vadimvolk

Reputation: 711

Functions are same. In GLES20 they are exists only on some devices as not mandatory extensions. In GLES30 they are mandatory.

If you use them from GLES30 your application will work only on devices supports GLES30 (only devices made for android 4.4).

Upvotes: 1

Related Questions