Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share OpenGL frame buffer / render buffer between two applications

Let's say I have an application A which is responsible for painting stuff on-screen via OpenGL library. For tight integration purposes 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 belong to OpenGL contexts and contexts are not shareable 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.

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

like image 448
Thomas Vincent Avatar asked Jun 17 '11 14:06

Thomas Vincent


Video Answer


2 Answers

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

like image 198
datenwolf Avatar answered Oct 16 '22 14:10

datenwolf


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

like image 3
KayWang Avatar answered Oct 16 '22 14:10

KayWang