How to Compile Android’s libagl2

In the course of testing the emulator capabilities regarding the support for GLES 2.0 inside the Android, I’ve came across the error in eglChooseConfig.

At the native side, eglChooseConfig is implemented inside libGLES_android.so which is the compiled from libagl (see below).

It returns 0 (zero) config value, indicating that there are no possible configuration available for the requested one. This causes the underlying Android GL java routines throws the error.

By examining the native source code inside libagl (located in ANDROIDROOT$\Frameworks\Native\opengl\libagl), using techniques as described in my previous post, I realized that requested configuration is indeed not found.

All other configuration request values can be fulfilled except one, i.e. EGL_RENDERABLE_TYPE, which in original libagl, even with latest android source code (as of October 2014) is still defined as EGL_OPENGL_ES_BIT.

This definition is declared inside egl.cpp source file, which indicates, of all possible configuration options, it is only for GLES v1.0. Whereas for GLES v2.0, it should be EGL_OPENGL_ES2_BIT.

I’ve then search inside the forums and performed some googling for news or issue regarding some ‘upgrades’ regarding this libGLES_android.so, but surprisingly I found none.

It seems that the emulator for GLES is neglected for too long so that even Android developers already forgetting it. Well, I think this should be the norm of open source culture 🙂

Since there should be no upgrades, then I have to resort to obtain the source code of libagl2. But unfortunately, it is only found in older version of android frameworks, and it is not maintained anymore.

So, after performing some tweaking inside android make files, I’ve managed to creates the separate makefile to perform a prove of concept that the modules inside libagl2 still can be compiled along side with android version that I am currently used.

Some issues that is found is the missing header files, and duplicate declarations inside the header file, especially regarding ANativeWindow structure, which is moved from older android_natives_priv.h to the windows.h inside ANDROIDROOT$\system\core\include\system. Also I’ve found some deprecated functions inside egl.cpp such as dequeueBuffer, etc, and log functions such as LOGD, LOGE, which should be replace by ALOGD, etc.

The source code can be compiled using Android’s NDK infrastructure, and the version I’m currently using is NDKROOT$/toolchains/arm-linux-androideabi-4.7/prebuilt/windows/bin/arm-linux-androideabi-g++.exe

After settling each of the issues, I can obtain the object files, ready to be linked to create the library:

agl01

It should be noted that there are many steps followed after this one, especially building the necessary shared libraries that linked into it.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: