How to Activate OpenGLES 2.0 in Android Emulator

Most of the Application Developers who wants to learn basics of OpenGLES architecture will find and try to execute the Hello OpenGLES sample provided by Android.

And there are two variants of the sample, one for OpenGLES version 1 and the other, OpenGLES version 2. So, almost everyone try to use the version 1 will successfully run the sample, and nearly all will fails for version 2 on first try.

If you try to search in the net of how to resolve the version 2 problem, you will find there are many confusing stories, that will cause frustration and will believe that OpenGLES version 2 is not supported in the emulator.

There are also suggestion to call setEGLConfigChooser, but it requires right condition to be effective.

The key is to pay attention to the log file given by the emulator during start up. Here is the indication that something wrong for OpenGLES 2.0 support in the emulator:

ge01

Emulator can still be run at this condition, and this will have some effect at the Android application side, which some indication in the logcat as follows:

ge02

If the Android Framework is forced to use libGLES_android.so, then it is game over. You will be stuck in OpenGLES version 1 forever. The setEGLConfigChooser will useless, because the error will be triggered at Android GL java runtime before the setEGLConfigChooser is executed. Usually the error message is “No configs match configSpec”.

If you get the above error message, this indicated that your emulator is still using libGLES_android.so and only can operate in OpenGLES version 1.

Here, you should make sure that the emulator is capable to support version 2 by eliminating the above error message from emulator by supplying the requested DLL. But part of the difficulty lies in the error message from emulator which is rather un-informative.

The missing DLL is actually libOpenglRender.dll and this dll also requires other dll. So, please make sure that libGLES_V2_translator.dll, libGLES_CM_translator.dll and libOpenglRender.dll is present in the same directory as the emulator program.

Sign of healthy emulator that’s ready for OpenGLES 2.0 support is indicated by the log below:

ge03

You can notice that emulator now adds new switch called qemu.gles with 1 as its value. This will cause the Android Framework to use different library because it checks the presence of ro.kernel.qemu.gles and if the value is 1 it will use different library set as indicated by the log below:

ge04

But the Hello OpenGL ES 2.0 still have some problem with “no config chosen” error:

ge05

Let’s retrieve the logcat:

ge06

Here’s the logcat result:

ge07

To get more information about the nature of the error, I’ve created the Netbeans project for existing Android Java Framework as follows:

ge08

Adds the source package from starting at D:\Projects\Android\Frameworks\Base\opengl\java

ge09

Should set the application to stop execution waiting for debugger:

ge10

Execute the application, we will have this screen:

ge11

Examine the process attribute and noted down the PID:

ge12

Perform port forwarding for the noted PID value:

ge13

In Netbeans attach to the process:

ge14

Now it will stopped at intended breakpoint:

ge15

So the problems lies inside chooseConfig on GLSurfaceView.java which insist on getting config with satisfying mAlphaSize is zero. All of the available alpha size from the emulator is 8.

So why this mAlphaSize is created with zero value ? To find it, here is the call stack at the time of class instance call:

ge16

And the function call appears to be hardcoded:

ge17

Here the call to setEGLConfigChooser will get some effect this time, because it will override the default one given by the Framework:

ge18

Perform re-compilation:

ge19

Re-installation process:

ge20

See that it can be run this time:

ge21

Q.E.D šŸ™‚

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: