[Fixed] GLES2.0 on Android

I tested this code on Android devices (Fly), and it works.

This line :
gLSurfaceView.setEGLConfigChooser(8 , 8, 8, 8, 16, 0);

should only be applied on simulator environments for compatibility and performance reasons IMHO.

Hi guys,

Is there any other possible solution as I tried it on my Mac and it does not work and I still see the error

Romain TISSERAND wrote:

This line :
gLSurfaceView.setEGLConfigChooser(8 , 8, 8, 8, 16, 0);
>
should only be applied on simulator environments for compatibility and performance reasons IMHO.

Sure.
While this line makes emulator run, it won’t work on some phones like ZTE Blade (Aderno 200). If you try, the image is heavily meshed up, mostly in yellow tones.
It works on a HTD Desire S though (Adreno 205).

So I won’t recommend distributing a game with this fix.

It seems still no fix for new cocos2dx. Here is my modification:

// TODO: this should only used for emulator, should comment it out before release
this.mGLSurfaceView.setEGLConfigChooser(8 , 8, 8, 8, 16, 0);

My version is cocos2d-2.1beta3-x-2.1.1

I can’t find the this line :“gLSurfaceView.setCocos2dxRenderer(new Cocos2dxRenderer());” in Cocos2dxActivity.java
.The line: “this.mGLSurfaceView.setCocos2dxRenderer(new Cocos2dxRenderer());” is found.Where is Cocos2dxActivity.java
?And Where is the line in Cocos2dxActivity.java
?Thank you.

I had the same problem as described by @Petr Bodnar.
The suggested fix worked for me.

Is there a way to detect that the code is being executed by an emulator?

Tks.

Sure. Add this method to org/cocos2dx/lib/Cocos2dxActivity :

private final static boolean isAndroidEmulator() {
            String model = Build.MODEL;
            Log.d(TAG, "model=" + model);
            String product = Build.PRODUCT;
            Log.d(TAG, "product=" + product);
            boolean isEmulator = false;
            if (product != null) {
                isEmulator = product.equals("sdk") || product.contains("_sdk") || product.contains("sdk_");
            }
            Log.d(TAG, "isEmulator=" + isEmulator);
            return isEmulator;
        } 

then patch the init() method as following :

       // Cocos2dxGLSurfaceView
        this.mGLSurfaceView = this.onCreateView();

        // ...add to FrameLayout
        framelayout.addView(this.mGLSurfaceView);

        // Switch to supported OpenGL (ARGB888) mode on emulator
        if (isAndroidEmulator())
                this.mGLSurfaceView.setEGLConfigChooser(8 , 8, 8, 8, 16, 0);

        // Init GLSurfaceView
        this.mGLSurfaceView.setCocos2dxRenderer(new Cocos2dxRenderer());

Thanks Romain, it worked like a charm :slight_smile:

Romain TISSERAND wrote:

Sure. Add this method to org/cocos2dx/lib/Cocos2dxActivity :
[…]
then patch the init() method as following :
[…]

Since it’s a common issue, and the patch is being reported as working fine, maybe it should be merged into master ?

Romain TISSERAND wrote:

Since it’s a common issue, and the patch is being reported as working fine, maybe it should be merged into master ?

Hi, First post.
I’m just getting started in cocos2d-x. I used your fix and it worked (although I needed to add some includes). Thanks!

I created a pull request from this (with your credit in the commit message)
https://github.com/mchinen/cocos2d-x/commit/5ee55f6f8dcb88f194f224b24ad1866c28fa42ae

Setting EGL config/context (mGLSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);) to A8R8G8B8 with 16bits for depth when running on an (Intel with HAXM) x86 emulator (4.1.1) did not seem to work.

Build.FINGERPRINT was unknown for me.
Checking Build.PRODUCT.contains("sdk") in detectOpenGLES20() might work across more emulators.
Anyway, users might want to trace values for the static members of Build using the following:
gist:5370884
to choose a workaround most suitable for their environment.

These workarounds should be removed before creating a production build.

PAT RZ2 wrote:

Setting EGL config/context (mGLSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);) to A8R8G8B8 with 16bits for depth when running on an (Intel with HAXM) x86 emulator (4.1.1) did not seem to work.
>
Build.FINGERPRINT was unknown for me.
Checking Build.PRODUCT.contains("sdk") in detectOpenGLES20() might work across more emulators.
Anyway, users might want to trace values for the static members of Build using the following:
gist:5370884
to choose a workaround most suitable for their environment.
>
These workarounds should be removed before creating a production build.

Works for me on OSX 10.8.3, Intel HAXM 1.0.4, Android 4.2.2, using Host GPU checked.
Did you enabled “Use Host GPU” on your config ?
What is your dev environment ?

While we could adjust the algorithm to detect emulator environment, we need to play safe in order not to enable it by error on real devices.

when you create the AVD,must set the Emulation Options to Use Host GPU
http://www.eoeandroid.com/thread-155072-1-1.html

冰 王 wrote:

when you create the AVD,must set the Emulation Options to Use Host GPU
http://www.eoeandroid.com/thread-155072-1-1.html

Use Host GPU worked for me. Thanks.
could anybody explain me what was the issue and how did Use Host GPU resolve it

i checked that other components and setting explained earlier were already there in my version of cocos2dx
e.g.
if (isAndroidEmulator())
this.mGLSurfaceView.setEGLConfigChooser(8 , 8, 8, 8, 16, 0);