在不同的 GLSurfaceView 之间共享 GLES20 上下文和纹理? [英] Sharing the GLES20 context and textures between different GLSurfaceViews?

查看:49
本文介绍了在不同的 GLSurfaceView 之间共享 GLES20 上下文和纹理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在不同的 GLSurfaceView 之间(在一个 Activity 内)共享 GLES20 上下文?或者,如何在不同的 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?

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

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.

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

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

编辑1

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

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.

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

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?

推荐答案

以下代码适用于部分设备,但不是全部:

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

这篇关于在不同的 GLSurfaceView 之间共享 GLES20 上下文和纹理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆