EGL works on Linux, but not on Android

I have EGL / GLES 2.0 code that I am trying to run on Linux (via Mesa) and Android (iOS to exit). On Linux, it works fine and looks as expected. Running on Android (phone, tablet and emulator - all 4.01) is going fine, but it doesn't display anything (the screen remains black). The code is 99% the same for all 3 - with some special handling for Android. Following my EGL attributes:

EGLint attribList[] = { EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, //EGL_ALPHA_SIZE, (flags & ES_WINDOW_ALPHA) ? 8 : EGL_DONT_CARE, //EGL_DEPTH_SIZE, (flags & ES_WINDOW_DEPTH) ? 8 : EGL_DONT_CARE, //EGL_STENCIL_SIZE, (flags & ES_WINDOW_STENCIL) ? 8 : EGL_DONT_CARE, EGL_SAMPLE_BUFFERS, (flags & ES_WINDOW_MULTISAMPLE) ? 1 : 0, // For Android this is extremely important - eglCreateContext will fail without it EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_NONE, EGL_NONE }; 

Following the EGL creation code:

 EGLint numConfigs; EGLint majorVersion; EGLint minorVersion; EGLDisplay display; EGLContext context; EGLSurface surface; EGLConfig config; EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE, EGL_NONE }; // Get Display display = eglGetDisplay((EGLNativeDisplayType)x_display); if ( display == EGL_NO_DISPLAY ) { esLogMessage("eglGetDisplay failed %d\n", eglGetError()); return EGL_FALSE; } // Initialize EGL if ( !eglInitialize(display, &majorVersion, &minorVersion) ) { esLogMessage("eglInitialize failed %d\n", eglGetError()); return EGL_FALSE; } static const size_t CONFIG_COUNT = 128; EGLConfig configs[CONFIG_COUNT]; // Get configs if ( !eglGetConfigs(display, configs, CONFIG_COUNT, &numConfigs) ) { esLogMessage("eglGetConfigs failed %d\n", eglGetError()); return EGL_FALSE; } else if( numConfigs == 0 ) { esLogMessage("eglGetConfigs found no configs for the display\n"); return EGL_FALSE; } EGLint chosenConfigCount = 0; // Choose config if ( !eglChooseConfig(display, attribList, &config, 1, &chosenConfigCount) ) { esLogMessage("eglChooseConfig failed %d\n", eglGetError()); return EGL_FALSE; } else if( chosenConfigCount == 0 ) { esLogMessage("eglChooseConfig found no matching configs (%d available)\n", numConfigs); return EGL_FALSE; } EGLint format; /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is * guaranteed to be accepted by ANativeWindow_setBuffersGeometry(). * As soon as we picked a EGLConfig, we can safely reconfigure the * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */ if( !eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format) ) { esLogMessage("eglGetConfigAttrib failed %d\n", eglGetError()); return EGL_FALSE; } #ifdef ANDROID if( ANativeWindow_setBuffersGeometry(hWnd, 0, 0, format) ) { esLogMessage("ANativeWindow_setBuffersGeometry failed\n"); return EGL_FALSE; } #endif // Create a surface surface = eglCreateWindowSurface(display, config, (EGLNativeWindowType)hWnd, NULL); if ( surface == EGL_NO_SURFACE ) { esLogMessage("eglCreateWindowSurface failed %d\n", eglGetError()); return EGL_FALSE; } // Create a GL context context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs ); if ( context == EGL_NO_CONTEXT ) { esLogMessage("eglCreateContext failed %d\n", eglGetError()); return EGL_FALSE; } // Make the context current if ( !eglMakeCurrent(display, surface, surface, context) ) { esLogMessage("eglMakeCurrent failed %d\n", eglGetError()); return EGL_FALSE; } 

Can someone shed light on what to check or how to find a problem?

EDIT:

I fixed some other errors, and now it works fine in Android Emulator and HP Touchpad (Cyanogenmod 9 alpha), but still leads to a black screen on my Samsung Galaxy S1 with Cyanogenmod 9 * sigh *.

+4
source share
1 answer

First, just a note: you do not need two EGL_NONE to complete attribute definitions.

Secondly, your problem is that eglGetConfigs() returns the available configurations, but eglChooseConfig(...,1,..) will not necessarily return a configuration that exactly matches the one you requested. Therefore, you should scan configurations to find the ones closest to your needs.

You need to call eglGetConfigAttrib() to compare e.g. EGL_GREEN_SIZE , EGL_BLUE_SIZE , EGL_ALPHA_SIZE , EGL_RENDERABLE_TYPE , EGL_DEPTH_SIZE , EGL_STENCIL_SIZE .

See eglChooseConfig () for more details.

0
source

All Articles