在不同的 GLSurfaceView 之间共享 GLES20 上下文和纹理?

发布于 2024-11-01 17:31:09 字数 580 浏览 1 评论 0原文

是否可以在不同的 GLSurfaceView 之间(在一个 Activity 内)共享 GLES20 上下文?或者,如何在不同的 GLSurfaceView 之间共享一组纹理?

在 iOS 上,如果您想节省内存并在不同的 CAEAGLLayer 支持的 UIView 中重用(大)纹理,您可以在它们之间传递 EAGLContext 对象,或者使用共享公共 EAGLSharegroup 对象的不同 EAGLContext。

我想知道如何在 Android 上实现这一点。有没有等效的技术?

Edit1

最初的建议是实现您自己的 EGLContextFactory(它将返回相同的 EGLContext),但它不起作用,因为每个 GLSurfaceViews 将渲染分派到它自己的私有 gl 渲染线程并在不同线程之间共享相同的 EGLContext是不可能的。

重新表述我最初的问题: 您在一个屏幕(一个 Activity)中有多个 GLSurfaceView,并且需要在每个表面的单独 EGLContext 中访问一组常见但较大的纹理,但多次加载纹理会超出设备的内存。那么你将如何在 GLSurfaceView 之间共享纹理呢?

Is it possible to share the GLES20 context between different GLSurfaceViews (within one Activity)? Alternatively, how would one share a set of texture between different GLSurfaceViews?

On iOS, if you want to conserve memory and reuse (large) textures in different CAEAGLLayer-backed UIViews, you can pass around a EAGLContext object between them or use different EAGLContexts which share a common EAGLSharegroup object.

I wonder how to accomplish this on Android. Is there any equivalent technique?

Edit1

The initial suggestion, to implement your own EGLContextFactory, which will return the same EGLContext, doesn't work since every GLSurfaceViews dispatches the rendering to it's own private gl render thread and sharing the same EGLContext between different threads is not possible.

To rephrase my initial question:
You have several GLSurfaceViews in one screen (one Activity) and you need to access a set of common but large texture in the individual EGLContext of every surfaces, but loading your textures multiple times exceeds the memory of your device. How would you share your textures between GLSurfaceViews then?

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

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

发布评论

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

评论(2

怎言笑 2024-11-08 17:31:09

以下代码适用于某些设备,但不适用于所有设备:

public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig) {
    EGLContext shared = .....;

    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 following code works on some of the devices, but not all of them:

public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig) {
    EGLContext shared = .....;

    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;
  }
}
温柔少女心 2024-11-08 17:31:09
  • GLSurfaceView setEGLContextFactory
  • < a href="http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=opengl/java/android/opengl/GLSurfaceView.java;h=41207f77285af1aafa3ebd67e9d9707709b0c2e3;hb =HEAD" rel="nofollow">GLSurfaceView.java

看来 setEGLContextFactory 可以在不同的 GLSurfaceView 之间使用相同的 GLES20 上下文。

伪代码:

private class MyEGLContextFactory implements EGLContextFactory {
    private static EGLContext mEGLContext;

    public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig config) {
        /* create EGLContext for GLES20 in first time */
        return mEGLContext;
    }

    public void destroyContext(EGL10 egl, EGLDisplay display,
            EGLContext context) {
    }
}

It seems that setEGLContextFactory enables to use the same GLES20 context between different GLSurfaceViews.

pseudo code:

private class MyEGLContextFactory implements EGLContextFactory {
    private static EGLContext mEGLContext;

    public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig config) {
        /* create EGLContext for GLES20 in first time */
        return mEGLContext;
    }

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