OpenGL ES 2.0 Support for Android?

2019-02-06 06:09发布

I've seen multiple takes on this topic and its starting to confuse me. I really hope someone can give me a definitive answer! :)

I guess to be blunt: 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)

I will say I am not an expert on this at all and this is my first experience with OpenGL. If anybody has any ideas of what I can do to fix this, I would be forever grateful. :) Thank you!

3条回答
孤傲高冷的网名
2楼-- · 2019-02-06 06:55

Got the same problem. Original Buggy Code:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(this.getClass().getName(), "Into onCreate Draw triangle");
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  WindowManager.LayoutParams.FLAG_FULLSCREEN);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    if (detectOpenGLES20()){
        Log.d("GLES20", "GL ES 2.0 Supported..............!");
    } else {
        Log.d("GLES20", "GL ES 2.0 Not Supported...............!");
    }

    view = new GLSurfaceView(this);
    view.setEGLContextClientVersion(2);
    view.setEGLConfigChooser(true);
    view.setRenderer(new TriangleRenderer(view));
    setContentView(view);
}


Solved by :

a.) Replacing this code line

view.setEGLConfigChooser(true);

with

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


b.) Setting -gpu on via Eclipse --> Run as ---> Target ---> Additional Emulator Command Line Options

Adding a little more to the above discussion:
There were two different Exception messages I came across while working with the above piece of code

FATAL EXCEPTION: GLThread 75 java.lang.IllegalArgumentException: No configs match configSpec

and

java.lang.IllegalArgumentException: No config chosen

A more detailed case study narrated at http://on-android-opengl2.blogspot.in/2013/05/android-opengl-es-20-emulator.html

查看更多
我命由我不由天
3楼-- · 2019-02-06 07:03

I just fixed the problem without adding any new lines to my source code. In the avd-manager i set "Use Host GPU" for my emulator device. Works now perfectly fine on my Geforce GTX 570.

API Level on emulator device is 16, and min-SDK in Manifest is 15.

查看更多
The star\"
4楼-- · 2019-02-06 07:09

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

查看更多
登录 后发表回答