EGL在Linux上运行,但在Android上运行

时间:2022-03-05 18:54:51

I have EGL/GLES 2.0 code, which I try to run on Linux (via Mesa) and Android (iOS to come). On Linux it works fine and renders like expected. Running on Android (Phone, tablet and emulator - all 4.01) it passes fine but displays nothing (screen stays black). The code is 99% the same for all 3 - with some special handling for Android. Following my EGL attributes:

我有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
};

Following the EGL creation code:

遵循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;
}

Could someone shed a light, what to test or how to find the problem?

有人可以解决问题,测试什么或如何找到问题?

EDIT:

编辑:

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

我修复了一些其他的错误,现在它在Android模拟器和HP触控板(Cyanogenmod 9 alpha)中工作正常,但仍然导致我的三星Galaxy S1上的黑屏与Cyanogenmod 9 *叹*。

1 个解决方案

#1


0  

First, just a remark: you don't need two EGL_NONE to end your attribute definitions.

首先,只需注释:您不需要两个EGL_NONE来结束您的属性定义。

Second, your issue comes from the fact that eglGetConfigs() returns the available configs, but eglChooseConfig(...,1,..) will not necessarily return the config that exactly matches the one you requested. Thus, you have to scan the configs to find the closest to your needs.

其次,你的问题来自于eglGetConfigs()返回可用的配置这一事实,但eglChooseConfig(...,1,..)不一定会返回与你请求的配置完全匹配的配置。因此,您必须扫描配置以找到最接近您需求的配置。

You have to call eglGetConfigAttrib() to compare, for instance, EGL_RED_SIZE, EGL_GREEN_SIZE,EGL_BLUE_SIZE, EGL_ALPHA_SIZE, EGL_RENDERABLE_TYPE, EGL_DEPTH_SIZE, EGL_STENCIL_SIZE.

您必须调用eglGetConfigAttrib()来比较,例如,EGL_RED_SIZE,EGL_GREEN_SIZE,EGL_BLUE_SIZE,EGL_ALPHA_SIZE,EGL_RENDERABLE_TYPE,EGL_DEPTH_SIZE,EGL_STENCIL_SIZE。

See eglChooseConfig() for further details.

有关更多详细信息,请参阅eglChooseConfig()。

#1


0  

First, just a remark: you don't need two EGL_NONE to end your attribute definitions.

首先,只需注释:您不需要两个EGL_NONE来结束您的属性定义。

Second, your issue comes from the fact that eglGetConfigs() returns the available configs, but eglChooseConfig(...,1,..) will not necessarily return the config that exactly matches the one you requested. Thus, you have to scan the configs to find the closest to your needs.

其次,你的问题来自于eglGetConfigs()返回可用的配置这一事实,但eglChooseConfig(...,1,..)不一定会返回与你请求的配置完全匹配的配置。因此,您必须扫描配置以找到最接近您需求的配置。

You have to call eglGetConfigAttrib() to compare, for instance, EGL_RED_SIZE, EGL_GREEN_SIZE,EGL_BLUE_SIZE, EGL_ALPHA_SIZE, EGL_RENDERABLE_TYPE, EGL_DEPTH_SIZE, EGL_STENCIL_SIZE.

您必须调用eglGetConfigAttrib()来比较,例如,EGL_RED_SIZE,EGL_GREEN_SIZE,EGL_BLUE_SIZE,EGL_ALPHA_SIZE,EGL_RENDERABLE_TYPE,EGL_DEPTH_SIZE,EGL_STENCIL_SIZE。

See eglChooseConfig() for further details.

有关更多详细信息,请参阅eglChooseConfig()。