View Full Version : Sharing textures between processes (linux)

10-20-2016, 11:11 AM

I have a linux-based Qt program that, as Qt does, runs in its own thread.
I set up an opengl context and some openGL textures (*) in the Qt widgets and start running the Qt thread.

Now I have another independent thread or process that decodes video .. and I would like to dump the decoded frames into the openGL textures (*).

I have done some research and concluded that this can be achieved with multithreading.
How about multiprocessing? I.e. in posix, calling the fork system call to differentiate a new process, having its own memory space.
How do openGL contexts behave over fork ? Any chance to get such a thing working or is it a plain dead end..?

At least in X11 you can pass window id numbers around to achieve this kind of things..

10-20-2016, 12:21 PM
If the implementation supports theEXT_import_context extension, you can use indirect rendering contexts across processes by using glXGetContextIDEXT (https://www.opengl.org/sdk/docs/man2/xhtml/glXGetContextIDEXT.xml) to get the XID for the server-side portion of the context, passing it to another process, and using glXImportContextEXT (https://www.opengl.org/sdk/docs/man2/xhtml/glXImportContextEXT.xml) to create a GLXContext which shares the same server-side context.

Note that:

1. The contexts don't share client-side state (e.g. pixel transfer modes).
2. This doesn't work for direct rendering contexts (and direct rendering contexts can't share data with indirect rendering contexts, so using this feature effectively precludes the use of direct rendering).
3. You probably shouldn't bet the farm on this feature working at all, even when the implementation claims to support it.