我有 EGL/GLES 2.0 代码,我尝试在 Linux(通过 Mesa)和 Android(即将推出 iOS)上运行。在 Linux 上,它工作正常并且呈现出预期的效果。在 Android(手机、平板电脑和模拟器 - 所有 4.01)上运行它可以正常运行,但不显示任何内容(屏幕保持黑色)。所有 3 的代码 99% 相同 - 对 Android 进行了一些特殊处理。遵循我的 EGL 属性:
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
};
遵循 EGL 创建代码:
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;
}
有人可以阐明,要测试什么或如何找到问题吗?
编辑:
我修复了一些其他错误,现在它在 Android 模拟器和HP 触摸板(Cyanogenmod 9 alpha)中运行良好,但仍然导致我的三星 Galaxy S1与Cyanogenmod 9 *sigh*出现黑屏。