Android uses OpenGL for rendering. Android SDK libraries include the OpenGL libraries, specially optimized for Android. Android started supporting OpenGL from API level 4 and then increased its support as the level increased. Currently, the maximum supported version of OpenGL is OpenGL ES 3.1 from API level 21.
Different OpenGL versions have a different set of features. Versions 1.0 and 2.0 have a lot of differences in terms of coding style, API convenience, functionality, and feature support. Let's discuss the following OpenGL ES versions that are significant to Android development:
OpenGL version 1.x has been supported from Android API level 4 with a shared OpenGL ES 1.x library, libGLESv1.so
. The headers gl.h
and glext.h
contain all the necessary APIs for OpenGL functionality.
In the current industry, a developer prefers to use OpenGL ES 2.0 for games, because almost every device supports this OpenGL version, and it provides vertex and fragment shaders useful for games. OpenGL ES 2.0 can be used in Android native development projects by including the libGLESv2.so
shared library in the project, as follows:
LOCAL_LDLIBS := -lGLESv2
The headers are gl2.h
and gl2ext.h
. OpenGL ES 2.0 is supported from Android API level 5.
From Android API level 21, OpenGL ES 3.0 is supported. The developer can include libGLESv3.so
to use OpenGL 3.1, as follows:
LOCAL_LDLIBS := -lGLESv3
The headers are gl3.h
and gl3ext.h
.
From Android API level 21, OpenGL ES 3.1 is supported. The developer can include libGLESv3.so
to use OpenGL 3.1, as follows:
LOCAL_LDLIBS := -lGLESv3
The headers are gl31.h
and gl3ext.h
.
OpenGL ES 3.0 and OpenGL ES 3.1 are not supported by many Android devices. If a developer intends to use them, then there should be an OpenGL version check before using the version. Also, proper version of OpenGL ES must be used to run the game on that particular device. The latest Android N has support for OpenGL ES 3.2.
This piece of Android Java code can be used to implement proper OpenGL ES support for an Android game:
private GLSurfaceView glSurfaceView; void setOpenGLVersion() { final boolean supportOpenGLEs3 = configurationInfo.reqGlEsVersion >= 0x30000; if (supportOpenGLEs3) { glSurfaceView = new GLSurfaceView(this); glSurfaceView.setEGLContextClientVersion(3); glSurfaceView.setRenderer(new RendererWrapper()); setContentView(glSurfaceView); } else { final boolean supportOpenGLEs2 = configurationInfo.reqGlEsVersion >= 0x20000; if (supportsOpenGLEs2) { glSurfaceView = new GLSurfaceView(this); glSurfaceView.setEGLContextClientVersion(2); glSurfaceView.setRenderer(new RendererWrapper()); setContentView(glSurfaceView); } else { glSurfaceView = new GLSurfaceView(this); glSurfaceView.setEGLContextClientVersion(1); glSurfaceView.setRenderer(new RendererWrapper()); setContentView(glSurfaceView); } } }
Texture compression has a significant effect on the rendering process handled by OpenGL. It can increase or decrease performance for different types of texture compression. Let's have a quick look at some of the important texture compression formats:
ATI texture compression is often called ATITC. This compression supports RGB with and without an alpha channel. This is the most common and widely used compression technique for Android.
Android requires the version definition of OpenGL used in the application, along with other required options.
Here is the version declaration syntax for OpenGL ES:
<uses-feature android:glEsVersion=<Target version goes here> android:required="true" />
Here are the target version options:
0x00010000
for version 1.00x00010001
for version 1.10x00020000
for version 2.00x00030000
for version 3.00x00030001
for version 3.10x00030002
for version 3.2Here is the optional setting for texture compression declaration:
<supports-gl-texture android:name=<Compression support type goes here> />
These are the compression type options:
GL_OES_compressed_ETC1_RGB8_texture
GL_OES_compressed_paletted_texture
GL_EXT_texture_compression_s3tc
GL_IMG_texture_compression_pvrtc
GL_EXT_texture_compression_dxt1
GL_EXT_texture_compression_dxt2
GL_EXT_texture_compression_dxt3
GL_EXT_texture_compression_dxt4
GL_EXT_texture_compression_dxt5
GL_AMD_compressed_3DC_texture
GL_EXT_texture_compression_latc
GL_AMD_compressed_ATC_texture
GL_ATI_texture_compression_atitc
However, not all texture compressions are supported by every device. The developer should always choose the target texture compression depending on the hardware and Android version requirement.
As you have already learned, not all devices support all OpenGL versions. So, it is very important to choose the correct OpenGL version before developing the game. Here are a few factors that should be evaluated while choosing the OpenGL version:
It is noticed that OpenGL version 3.x is faster than OpenGL version 2.x, which is way faster than OpenGL 1.x. So, it is always better to use the latest possible version in the game.
Texture compression support varies with OpenGL versions. Older versions support older texture compression factors. Also, Android version support is not universal for all OpenGL versions. Again, it is better to use the latest possible version for texture support.
This constraint keeps a developer's feet on the ground. The latest versions of OpenGL are not supported by all devices. So, in order to target a bigger range of devices, the user should change the OpenGL version to 2.0 as most devices support this version.
3.133.142.2