在两个glsurfaceview之间共享EGL2.0上下文,导致Android平板上的EGL_BAD_ACCESS。

时间:2020-12-20 18:55:54

I try to share EGL context bwteen 2 GLSurfaceViews by following code:

我试图通过以下代码来共享EGL上下文bwteen 2 glsurfaceview:

createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig) {
    EGLContext shared = ...; // a cached egl context
    int[] attrib_list = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE };
    EGLContext context = egl.eglCreateContext(display, eglConfig, shared == null ? EGL10.EGL_NO_CONTEXT : shared,
        attrib_list);
    return context;
  }
}

The code works on most of the android phones (OS>=2.2) but failed on all the tested tablets.

这段代码在大多数android手机上运行(OS>=2.2),但在所有测试的平板电脑上都失败了。

01-12 18:33:35.381: E/AndroidRuntime(12171): FATAL EXCEPTION: GLThread 11

E/AndroidRuntime(12171):致命异常:GLThread 11。

01-12 18:33:35.381: E/AndroidRuntime(12171): java.lang.RuntimeException: eglMakeCurrent failed: EGL_BAD_ACCESS

01-12 18:33:35.381:E / AndroidRuntime(12171):. lang。RuntimeException:eglMakeCurrent失败:EGL_BAD_ACCESS

01-12 18:33:35.381: E/AndroidRuntime(12171): at android.opengl.GLSurfaceView$EglHelper.throwEglException(GLSurfaceView.java:1146)

在android.opengl.GLSurfaceView$EglHelper.throwEglException(GLSurfaceView.java:1146)。

Since I declared the LOCAL_LDLIBS: = -lGLESv2, the EGL is a 2.0 context.

因为我声明了LOCAL_LDLIBS: = -lGLESv2,所以EGL是2.0环境。

Why it failed on tablets(xoom, galaxy, lg, sony, etc)

为什么它在平板电脑(xoom, galaxy, lg,索尼等)上失败了

Any insight is appreciated.

任何观点都是感激。

2 个解决方案

#1


1  

Two possible reasons for this failure (from the EGL spec):

这次失败的两个可能的原因(来自EGL规范):

  • If ctx is current to some other thread, or if either draw or read are bound to contexts in another thread, an EGL_BAD_ACCESS error is generated.
  • 如果ctx在其他线程上是当前的,或者在另一个线程中绑定到上下文,则生成EGL_BAD_ACCESS错误。
  • If binding ctx would exceed the number of current contexts of that client API type supported by the implementation, an EGL_BAD_ACCESS error is generated.
  • 如果绑定ctx将超过实现所支持的客户端API类型的当前上下文的数量,将生成EGL_BAD_ACCESS错误。

It could also be that the GPU you are using on tablets does not support shared context.

也可能是你在平板电脑上使用的GPU不支持共享上下文。

#2


0  

Most probably following lines are reason for the error in GLSurfaceView.

最可能的原因是在GLSurfaceView中出现错误的原因。

public GL createSurface(SurfaceHolder holder) {
    ....

    /*
     * Before we can issue GL commands, we need to make sure
     * the context is current and bound to a surface.
     */
    if (!mEgl.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext)) {
         throwEglException("eglMakeCurrent");
    }

}

#1


1  

Two possible reasons for this failure (from the EGL spec):

这次失败的两个可能的原因(来自EGL规范):

  • If ctx is current to some other thread, or if either draw or read are bound to contexts in another thread, an EGL_BAD_ACCESS error is generated.
  • 如果ctx在其他线程上是当前的,或者在另一个线程中绑定到上下文,则生成EGL_BAD_ACCESS错误。
  • If binding ctx would exceed the number of current contexts of that client API type supported by the implementation, an EGL_BAD_ACCESS error is generated.
  • 如果绑定ctx将超过实现所支持的客户端API类型的当前上下文的数量,将生成EGL_BAD_ACCESS错误。

It could also be that the GPU you are using on tablets does not support shared context.

也可能是你在平板电脑上使用的GPU不支持共享上下文。

#2


0  

Most probably following lines are reason for the error in GLSurfaceView.

最可能的原因是在GLSurfaceView中出现错误的原因。

public GL createSurface(SurfaceHolder holder) {
    ....

    /*
     * Before we can issue GL commands, we need to make sure
     * the context is current and bound to a surface.
     */
    if (!mEgl.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext)) {
         throwEglException("eglMakeCurrent");
    }

}