Sharing textures between contexts

Is there a way to share textures between several contexts? I want to load textures in the background with a “loader” thread while rendering continues in the main rendering thread (rendering without the textures that are not available yet, obviously). Since an OpenGL context cannot be shared by other threads, I tried to create a loader context using the “sharing” feature mentioned in the context creation documentation but this does not seem to work. It doesn’t even work in a single-thread design – textures loaded in one context are not available to the other context. Any working example using either glx or wxwidgets would be most appreciated!


AFAIK context sharing is the best/easiest/most portable way to acomplish this and textures should be shareable among contexts.

I used this in an applicaton several years ago, where a resource loading thread loaded (among other things) textures while the main rendering thread kept rendering, but unfortunately I no longer have access to that source code. However, I can confirm that this works (after a bit of tinkering, especially for shaders).

How do you diagnose that it does not work for you? Do you get a gl error or is the texture blank? Could you post a few source code snippets of how you try to do this?

Here’s how to do it with GLX:

In main thread Init function :


renderingContext = glXCreateContext( Display*, XVisualInfo*, NULL, True);
workerContext = glXCreateContext( Display*, XVisualInfo*, renderingContext, True );
glXMakeCurrent(Display*, GLXDrawable, renderingContext);

In worker thread init function :

glXMakeCurrent(Display*, GLXDrawable, workerContext);

Finally, don’t forget to call glFinish() before using the loaded resources in the main thread

Also while you’re studying up, be sure to read up on the new GL extension:

just released. Good to know about this even if you decide you don’t need it.

Thanks a lot! Turns out that this is pretty much what I did, my problems where mostly threads-related. Also forgot to call XInitThreads().

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