在 Android 平板电脑上,在 2 个 GLSurfaceView 之间共享 EGL2.0 上下文会导致 EGL_BAD_ACCESS

发布于 2024-12-26 13:58:22 字数 990 浏览 3 评论 0原文

我尝试通过以下代码共享 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 手机(操作系统>=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 等)

任何见解都值得赞赏。

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

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.

01-12 18:33:35.381: E/AndroidRuntime(12171): FATAL EXCEPTION: 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): at android.opengl.GLSurfaceView$EglHelper.throwEglException(GLSurfaceView.java:1146)

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

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

Any insight is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

§普罗旺斯的薰衣草 2025-01-02 13:58:22

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

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

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

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

  • 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.
  • 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.

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

将军与妓 2025-01-02 13:58:22

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

}

Most probably following lines are reason for the error in 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");
    }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文