Texture Sharing.

I am looking to implement texture sharing between two EGL contexts in two different threads. One thread to do the drawing, and one to load the textures.

Are there any examples of how to do this?

If I am just loading a texture from a context do I need to call:

eglMakeCurrent(currentDisplay, localSurface, localSurface, localContext);

do I need a surface at all? or is calling:

eglCreateContext(currentDisplay, currentConfig, currentContext, null);

enough?

Regards,
Keean.

Yes, you do need to make the context current to the thread to operate on it, and unfortunately the EGL spec also requires a surface for it, which may not currently be in use by another thread.

Are there any requirements for the surface? Would a pbuffer be the best type to use?

When I run the following:

In OpenGL rendering thread:

currentDisplay = eglGetCurrentDisplay();
currentContext = eglGetCurrentContext();
currentConfig = // config used to select display

In Texture loading thread:

localContext = eglCreateContext(currentDisplay, currentConfig, currentContext, null);
localSurface = eglCreatePbufferSurface(currentDisplay, currentConfig, surfaceAttribs);
eglMakeCurrent(currentDisplay, localSurface, localSurface, localContext);

I am getting the error “validate_display_context:475 error 3006 (EGL_BAD_CONTEXT)” from the “eglMakeCurrent” call. Any idea why this is?

Regards,
Keean.

I should point out I test the localContext returned from eglCreateContext like this:

    errc = eglGetError();
    if (errc != EGL10.EGL_SUCCESS) {
        // log error
    }
    if (localContext == EGL_NO_CONTEXT) {
        // log error
    }

So it appears “eglCreateContext” is returning a valid context, but that “eglMakeCurrent” thinks it is a “EGL_BAD_CONTEXT” when passed a shared-context.

Right now I suspect this is an implementation dependent issue, but if I am doing anything wrong, please let me know.

why do you need to different contexts…? I mean you can use one context only for texture sharing. And threads can share the context, only the condition is that while using shared context, you have to use some mutex / semaphores for synchronization as 1 context can be current to only one thread at a time.

You can create eglimage and attach texture to it in first thread. And use this eglimage texture directly in another thread.

If you want to keep two CPU cores busy or upload textures in the background, having multiple contexts are useful.

A 1x1 pbuffer surface is usually a good choice.

That looks correct, it’s possible your platform doesn’t support shared contexts. They’re not the most typical use-case and often support for them can get left for last.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.