Boris RAYMOND Boris RAYMOND - 1 year ago 159
C++ Question

Global OpenGL context for rendering in fbo to display in many QOpenGLWidget

I want to display a scene with different points of view in many QOpenGLWidget that are in the same window (separated with a QSplitter architecture).
The important thing is that I want to store my scene data (geometry and textures) only once on the GPU.
But, each QOpenGLWidget have there own QOpenGLContext.

My idea was to create an independant context that render scene into a FrameBufferObject (not QFrameBufferObject) and use the resulting texture in the concerned QOpenGLWidget.

More technically, my approach was to create a new QOpenGLContext and a QOffscreenSurface.
But when I want to use the resulting QOpenGLFunctions given by my QOpenGLContext, it stop with a segmentation fault even if I've checked that my created QOpenGlContext is valid.

In a more general way, it's hard to me to understand the role of the QOpenGLContext, the surface (QOffscreenSurface in my case) and the makeCurrent function.

My request is to understand what is the good way to do this and why I get a segmentation fault.

Answer Source

I come back with an answer of my problem.

In fact I've used my first initialized QOpenGLWidget's context as global context to avoid creating a new one.

The tricky part is to make the global context current everytime it's needed (adding data on GPU or using the fbo).

The paintGL steps are simple : - Make the global context current. - Start fbo recording. - Render the scene. - Stop the fbo recording. - Make the QOpenGLWidget context current. - Render the fbo result on the screen.

I've checked my memory using gDEBugger and all my memory is in the global context (and store only once).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download