本文介绍了为什么eglMakeCurrent()与EGL_BAD_MATCH失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在使用opengl / egl开发Android。我的应用程序需要第二个上下文从第二个线程加载纹理。

I am developing for Android using opengl/egl. My app requires a second context for loading textures from a second thread.

我的代码在Android 2.3上正常工作,但是当我尝试在4.0.3 Android设备上的代码或模拟器,eglMakeCurrent()失败与EGL_BAD_MATCH。

My code works fine on android 2.3, but when I try the code on a 4.0.3 android device or emulator, eglMakeCurrent() fails with EGL_BAD_MATCH.

第二个上下文的初始化和它的像素缓冲区都工作正常,所以我不知道从哪里开始寻找此错误。

The initialization of the second context and it's pixel buffer all works fine too, so I am not sure where to begin looking for this error.

这是初始化代码:

ANativeWindow *window = (ANativeWindow*)displaySurface;

EGLint dummy, format;

display = eglGetDisplay(EGL_DEFAULT_DISPLAY);

eglInitialize(display, 0, 0);

EGLint contextAttribs[] =
{
    EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE
};

const EGLint configAttribs[] =
{
    EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
    EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
    EGL_BLUE_SIZE, 8,
    EGL_GREEN_SIZE, 8,
    EGL_RED_SIZE, 8,
    EGL_ALPHA_SIZE, 8,
    EGL_BUFFER_SIZE, 32,
    EGL_DEPTH_SIZE, 24,
    EGL_NONE
};

EGLint numConfigs;
EGLConfig config;

eglChooseConfig(display, configAttribs, &config, 1, &numConfigs);
eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
ANativeWindow_setBuffersGeometry(window, 0, 0, format);

surface = eglCreateWindowSurface(display, config, window, NULL);
if(surface == NULL)
    Trace("error creating window surface: " + GetEglError());

context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs);
if(context == NULL)
    Trace("error creating main context: " + GetEglError());

const EGLint auxConfigAttribs[] =
{
    EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
    EGL_BLUE_SIZE, 8,
    EGL_GREEN_SIZE, 8,
    EGL_RED_SIZE, 8,
    EGL_ALPHA_SIZE, 8,
    EGL_DEPTH_SIZE, 0,
    EGL_STENCIL_SIZE, 0,
    EGL_NONE
};

EGLint pbufferAttribs[] =
{
    EGL_WIDTH, 1,
    EGL_HEIGHT, 1,
    EGL_TEXTURE_TARGET, EGL_NO_TEXTURE,
    EGL_TEXTURE_FORMAT, EGL_NO_TEXTURE,
    EGL_NONE
};

EGLint auxNumConfigs;
EGLConfig auxConfig;

eglChooseConfig(display, auxConfigAttribs, &auxConfig, 1, &auxNumConfigs);

auxSurface = eglCreatePbufferSurface(display, auxConfig, pbufferAttribs);
if(auxSurface == NULL)
    Trace("error creating pbuffer surface: " + GetEglError());

auxContext = eglCreateContext(display, auxConfig, context, contextAttribs);
if(auxSurface == NULL)
    Trace("error creating auxilliary context: " + GetEglError());

if(!eglMakeCurrent(display, surface, surface, context))
    Trace("could not make main context current: " + GetEglError());

在我的Android 2.3设备(HTC Desire)上,上面的初始化代码工作得很好,

On my Android 2.3 device(HTC Desire), the above initialization code works perfectly, and I can make the auxContext current, and load textures just fine.

在我的Android 4.0.3设备(三星Nexus S)和我的Android 4.1设备(Galaxy Note 2)eglMakeCurrent

BUT, on my android 4.0.3 device(Samsung Nexus S) and my Android 4.1 device (Galaxy Note 2) eglMakeCurrent() fails with EGL_BAD_MATCH after a successful initialization.

有人知道我为什么会收到这个错误吗?

Does anyone know why I may be getting this error?

推荐答案

啊,我真的知道一些东西。 ;)[花了5年的最好的一部分工作在各种EGL实现]。

Ah, something I actually know something about. ;) [Having spent best part of 5 years working on various EGL implementations].

我很确定您的 surface 是与实际显示表面不同的格式。我不知道确切的区别是什么,或你需要改变。可能是EGL_DEPTH_SIZE?你可以尝试枚举可用的模式,看看是否有可能。我知道,这有点痛苦,但我已经在那里做了几次在过去 - 不同的是,我可以通常看看EGL源代码,弄清楚我做错了... ;)

I'm pretty certain your surface is a different format to the actual display surface. I'm not sure exactly WHAT the difference would be, or what you need to change. EGL_DEPTH_SIZE perhaps? You could try enumerating the modes that are available and see if any look "likely". I know, it's a bit of a pain, but I've been there done that a few times in the past - with the difference that I could usually look through the EGL source code and figure out what I'd done wrong... ;)

这篇关于为什么eglMakeCurrent()与EGL_BAD_MATCH失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 07:58