OpenGL ES 2.0 Support for Android?

Thanizer picture Thanizer · Dec 5, 2012 · Viewed 15k times · Source

Does the Android emulator support OpenGL ES 2.0? I've seen some people say "Yes, but you have to change a few settings." and I've also seen "No, it doesn't support it, period." Here's what I've done to try and correct the problem, including some error messages that I got.

First, I modified the AndroidManifest.xml to contain the following code:

<uses-feature 
    android:glEsVersion="0x00020000" />

<uses-sdk
    android:minSdkVersion="15"
    android:targetSdkVersion="17" />

Then, when I want to instantiate my GLSurfaceView, I use this sequence of code to instantiate it:

super(context);

setEGLContextClientVersion(2);

setRenderer(new MyRenderer());
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

Then, everywhere I looked said that you must go into the AVD Manager, select the emulator, go to "Hardware", add "GPU emulation" and set the boolean to "yes". However, here is what I see when I look at mine:

Screenshoot of my Android 4.2 emulator window.

What's peculiar is that I have another emulator in my AVD Manager of which I do have the "Hardware" table:

What does my Android 2.2 emulator have the hardware table?

And just to show you exactly what I'm doing, here's some code that does some stuff I want to do in OpenGL ES 2.0 (I mainly got this from Android's own tutorials):

int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode);
int fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode);

program = GLES20.glCreateProgram();
GLES20.glAttachShader(program, vertexShader);
GLES20.glAttachShader(program, fragmentShader);
GLES20.glLinkProgram(program);

I don't want to change my code back to work with OpenGL ES 1.0 because that will require a lot of headaches and if I can avoid it, I will.

Finally, when I try running my program, the program closes with the window: "Unfortunately, has stopped." This is what LogCat told me:

12-05 06:16:27.165: E/AndroidRuntime(936): FATAL EXCEPTION: GLThread 81
12-05 06:16:27.165: E/AndroidRuntime(936): java.lang.IllegalArgumentException: No config chosen
12-05 06:16:27.165: E/AndroidRuntime(936):  at    android.opengl.GLSurfaceView$BaseConfigChooser.chooseConfig(GLSurfaceView.java:874)
12-05 06:16:27.165: E/AndroidRuntime(936):  at android.opengl.GLSurfaceView$EglHelper.start(GLSurfaceView.java:1024)
12-05 06:16:27.165: E/AndroidRuntime(936):  at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1401)
12-05 06:16:27.165: E/AndroidRuntime(936):  at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)

Answer

Petr picture Petr · Dec 5, 2012

I can say Yes on your question. Android emulator supports OpenGL ES 2.0. I created an app with cocos2d-x v.2 (which uses OpenGL ES 2.0). I had same FATAL EXCEPTION: GLThread 81 error with same stack. I solved this issue by adding

gLSurfaceView.setEGLConfigChooser(8 , 8, 8, 8, 16, 0);

before setting renderer setRenderer:

gLSurfaceView.setCocos2dxRenderer(new Cocos2dxRenderer());

Now I can run my app on Android emulator.

See my question and answer at https://stackoverflow.com/a/13719983/307547. My post on this link contains screenshot with AVD settings:

http://www.cocos2d-x.org/boards/6/topics/12563?r=19274#message-19274