I am trying to use multiple EGL contexts to load textures outside of my main thread. I'm getting an EGL_BAD_CONTEXT
error after my eglCreateContext
call.
Inside my 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 } );
}
The EGL_BAD_CONTEXT
lead me to the documentation here, that says
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.
That's why I added in the EGL_CONTEXT_CLIENT_VERSION
parameter, but it seems to have made no effect.
What I'm seeing is that, even though I'm getting this error, the context seems semi-valid. I'm able to use it on another thread
egl.eglMakeCurrent(display, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, context);
After this, creating textures on that thread does not cause an error. But I do see that the texture names are not shared, each thread seems to count up from 0 itself.
My next assumption was that I need to share the surface between contexts. But, if I pass through the same surface from the original context into my eglMakeCurrent
, but I fail completely with
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)
I feel as though I'm almost there, does somebody know what's missing?