天天看点

android的线程共享资源,java – 在Android上的OpenGL上下文之间共享资源

我试图使用多个EGL上下文来加载我的主线程之外的纹理.在我的eglCreateContext调用之后,我收到了一个EGL_BAD_CONTEXT错误.

在我的android.opengl.Renderer里面

public void onSurfaceCreated (javax.microedition.khronos.opengles.GL10 gl, EGLConfig config) {

// ...

EGLContext sharedContext = egl.getCurrentContext();

EGLDisplay display = eglGetCurrentDisplay();

eglCreateContext(display, config, sharedContext, new int[] { EGL_CONTEXT_CLIENT_VERSION, 2 } );

}

EGL_BAD_CONTEXT引导我阅读文档here

EGL_BAD_CONTEXT is generated if share_context is not an EGL rendering context of the same client API type as the newly created context and is not EGL_NO_CONTEXT.

这就是我在EGL_CONTEXT_CLIENT_VERSION参数中添加的原因,但它似乎没有起作用.

我所看到的是,即使我收到此错误,上下文似乎也是半有效的.我可以在另一个线程上使用它

egl.eglMakeCurrent(display, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, context);

在此之后,在该线程上创建纹理不会导致错误.但我确实看到纹理名称没有共享,每个线程似乎从0本身算起来.

我的下一个假设是我需要在上下文之间分享表面.但是,如果我从原始上下文中通过相同的表面进入我的eglMakeCurrent,但我完全失败了

E/AndroidRuntime(3210): java.lang.IllegalArgumentException

E/AndroidRuntime(3210): at com.google.android.gles_jni.EGLImpl._eglCreateContext(Native Method)

E/AndroidRuntime(3210): at com.google.android.gles_jni.EGLImpl.eglCreateContext(EGLImpl.java:54)

我觉得好像我几乎在那里,有人知道缺少什么吗?