I had the following situation:
In the cross-platform rendering library for iOS and Android (written in c (++)), I have two threads, each of which needs its own EGLContext: Thread A is the main thread; It displays a window. Thread B is a generator thread that performs various calculations and displays the results in textures, which are later used by thread A.
Since I cannot use EGL in iOS, the library uses function pointers for static Obj.-C functions to create a new context and set it to current. This already works, I create a context for thread A using
EAGLContext *contextA = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
Context for thread B is created using
EAGLContext *contextB = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2 sharegroup:[contextA sharegroup]];
Then I can set either of two current ones:
[EAGLContext setCurrentContext:context]
To use the same logic (function pointers passed to the library) on Android, I want to do this on the C side of JNI bindings, this time using real EGL instead of Apple EAGL. I can easily create contextA using WindowSurface and my own window, I can create contextB and pass contextA to the shareContext parameter of the eglCreateContext call.
But when I want to create currentB current, I have to pass the surface to the eglMakeCurrent call, and I'm trying to figure out which surface should go there.
- I cannot use WindowSurface for contextA, because the spec says in section 3.7 that “no more than one context for each supported API client can be current for a particular thread at a given time, and no more than one context can be attached to a specific surface in a given point in time.
- I cannot specify EGL_NO_SURFACE because this will result in an EGL_BAD_MATCH error in the eglMakeCurrent call.
- It seems that I could use the PBuffer surface, but I hesitate because I will need to specify the width and height when I create such a surface, and stream B can create textures of different sizes. In addition, the “OpenGL ES 2.0 Programming Guide” by Munshi, Ginsburg, and Shreiner says in section 3.8 that “Pbuffers are most often used to create texture maps. If all you want to do is display the texture, we recommend using objects framebuffer [...] instead of pbuffers because they are more efficient, "which is exactly what I want to do in stream B.
I don’t understand what Munshi, Ginsurg and Schreiner mean by this sentence, how will the framebuffer object replace the pbuffer surface? What if I create a very small (say 1x1px) pbuffer surface to make the context current - can I then map to arbitrarily large FBOs? Are there any other features that I still don't know about?
Many thanks for your help!