4

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?

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
Richard Taylor
  • 2,702
  • 2
  • 22
  • 44

1 Answers1

0

Turns out, thanks to some help from this question:

My secondary context requires a surface. It is not the same as the original context's surface.

I needed to create that new surface using eglCreatePbufferSurface. The reason my attempts with this had failed before is that it defaults to a width and height of 0. By setting that to a 1x1 surface, it worked perfectly.

egl.eglCreatePbufferSurface(display, config, new int[] { EGL10.EGL_WIDTH, 1, EGL10.EGL_HEIGHT, 1, EGL10.EGL_NONE });
Ziad Akiki
  • 2,601
  • 2
  • 26
  • 41
Richard Taylor
  • 2,702
  • 2
  • 22
  • 44