Hi all,
I have a similar problem of sharing OpenGL ES textures between two
threads on Honeycomb device (Motorola Xoom).
According to EGL 1.4 specification it should be possible by using
EGLContext from the main thread as "share_context" parameter to
eglCreateContext during creation of the second EGLContext on the
second thread.
The problem is no matter what I do calling eglMakeCurrent on second
thread always fails with EGL_BAD_ACCESS.
I want to be able to take a texture id generated on one thread (main
thread), bind it and construct it (for example by glTexImage2D,
GLUtils.texImage2D) on second thread and then use it on the main
thread.
Main thread is a rendering thread in android.view.GLSurfaceView.java
(but I can create a custom class for that if any behavior of the
default one needs to be changed) so it calls:
- eglInitialize with a default display,
- eglChooseConfig to obtain config that I'll call mainEGLConfig,
- eglCreateWindowSurface to create a window surface from
android.view.Surface it is using,
- eglCreateContext to create mainEGLContext (EGL_NO_CONTEXT is used
as "share_context" parameter),
- eglMakeCurrent,
- creates some GL objects (including textures via glGenTextures),
- renders scene in onDrawFrame etc.
Second thread obtains mainEGLConfig and mainEGLContext from the main
thread and calls:
- eglInitialize with a default display,
- eglCreatePbufferSurface to create a pixel buffer surface that will
not be used anyway (mainEGLConfig used as config),
- eglCreateContext with mainEGLConfig as "share_context" parameter
(mainEGLConfig used as config),
- eglMakeCurrent fails with EGL_BAD_ACCESS.
Above error is not generated if EGL_NO_CONTEXT is used as
"share_context" but textures are not shared this way of course.
EGL spec gives three conditions when such error can be generated by
eglMakeCurrent but in my opinion none of them apply here.
On the other hand Android implementation of eglMakeCurrent (at least
in Gingerbread sources) generates EGL_BAD_ACCESS in case an unknown
error occured.
I hope that my logic is fundamentally wrong somewhere above and a fix
is easy - any help appreciated :)
On Mar 16, 7:40 am, Romain Guy <
romain...@android.com> wrote:
> Using EGLImage you can generate textures from another thread (that's what
> the Browser does) but you cannot draw using multiple threads, even if only
> one thread draws at a time. The EGL context is associated to a single
> thread.
This sounds interesting, could you give some examples how to use
EGLImage extension in this case?
I've read its description in Khronos EGL registry but I'm still not
sure how to use it properly to share textures in the first part of my
post.
http://www.khronos.org/registry/egl/extensions/KHR/EGL_KHR_image_base.txt
http://www.khronos.org/registry/egl/extensions/KHR/EGL_KHR_image.txt
Thanks,
Wiktor