5

我尝试通过以下代码共享 EGL 上下文 bwteen 2 GLSurfaceViews:

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

该代码适用于大多数 android 手机(OS>=2.2),但在所有经过测试的平板电脑上都失败了。

01-12 18:33:35.381:E/AndroidRuntime(12171):致命异常:GLThread 11

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

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

由于我声明了 LOCAL_LDLIBS: = -lGLESv2,因此 EGL 是 2.0 上下文。

为什么它在平板电脑上失败(xoom、galaxy、lg、sony 等)

任何见解都值得赞赏。

4

2 回答 2

2

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

  • 如果 ctx 对于某个其他线程是当前的,或者如果 draw 或 read 绑定到另一个线程中的上下文,则会生成 EGL_BAD_ACCESS 错误。
  • 如果绑定 ctx 将超过实现支持的该客户端 API 类型的当前上下文数,则会生成 EGL_BAD_ACCESS 错误。

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

于 2012-01-13T07:52:17.147 回答
0

以下几行很可能是 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");
    }

}
于 2012-01-13T04:24:13.540 回答