13
votes

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).

3
Is real-time updating required? You could write the rendered image to a file and load it in B. Other than that, sharing FBO's in OpenGL is not that simple. Maybe you can share the buffers on GPU level. - Jeroen Baert
@Jeroen Real-time is required ... I was trying to limit the scope of the question to not tackle the sync problem too soon but your are right it's important :) - Thomas Vincent

3 Answers

6
votes

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).

2
votes

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

0
votes

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.