Share OpenGL frame buffer / render buffer between two applications

11,484

Solution 1

Framebuffer Objects can not be shared between OpenGL contexts, be it that they belong to the same process or not. But textures can be shared and textures can be used as color buffer attachment to a framebuffer objects.

Sharing OpenGL contexts between processes it actually possible if the graphics system provides the API for this job. In the case of X11/GLX it is possible to share indirect rendering contexts between multiple processes. It may be possible in Windows by emplyoing a few really, really crude hacks. MacOS X, no idea how to do this.

So what's probably the easiest to do is using a Pixel Buffer Object to gain performant access to the rendered picture. Then send it over to the other application through shared memory and upload it into a texture there (again through pixel buffer object).

Solution 2

In MacOS,you can use IOSurface to share framebuffer between two application.

Solution 3

In my understanding, you won't be able to share the objects between the process under Windows, unless it's a kernel mode object. Even the shared textures and contexts can create performance hits also it has give you the additional responsibility of syncing the SwapBuffer() calls. Especially under windows platform the OpenGL implementation is notorious.

In my opinion, you can relay on inter-process communication mechanisms like Events, mutex, window messages, pipes to sync the rendering. but just realize that there's a performance consideration on approaching in this way. Kernel mode objects are good but the transition to kernel each time has a cost of 100ms. Which is damns costly for a high performance rendering application. In my opinion you have to reconsider the multi-process rendering design.

Share:
11,484
Thomas Vincent
Author by

Thomas Vincent

Updated on June 20, 2022

Comments

  • Thomas Vincent
    Thomas Vincent almost 2 years

    Let's say I have an application A witch is responsible for painting stuff on screen via OpenGL library. For tight integration purpose I would like to let this application A do its job, but render in a FBO or directly in a render buffer and allow an application B to have read-only access to this buffer to handle the display on screen (basically rendering it as a 2D texture).

    It seems FBOs belongs to OpenGL contexts and contexts are not share-able between processes.I definitely understand that allowing several processes two mess with the same context is evil. But in my particular case I think it's reasonable to think it could be pretty safe.

    NOTE:

    Application A is a QApplication and the application B is a native win32 one

    EDIT:

    Render size is near full screen, I was thinking of a 2048x2048 32bits buffer (I don't use the alpha channel for now but why not latter).