Off-screen/screen rendering on different threads


I’m posting this here because I’m really don’t know OpenGL, I just started to look at it as a result of some integration problems. Possibly, there may be a better forum for it. Any suggestions, or pointers, including forums where to post this would be very much appreciated.

I’m working with some existent code, that does off-screen rendering of an object, it uses glut and glew to set OpenGL context and buffer objects. This code is working well in isolation, I can get renderings of my object in different configurations at a rate of 30fps.

However, it arrive the moment to combine this with an application that uses Qt for the GUI, in particular it uses a QGLViewer to visualise some OpenGL objects. This QGLViewer is some third-party viewer that allows to manipulate the OpenGL objects with the mouse. Here it started a nightmare :frowning:

My off-screen rendering works in a thread that is different from the GUI thread, and conflicts with the operation of the QGLViewer. I get to see on the screen what is supposed to be rendered off-screen and the other way round, then crash, a bit random really.

I have tried to do all the off-screen rendering in a different OpenGL context, and make this context current each time I need to render something off-screen, then I recover the prior context (that will be used for the screen rendering). I got this to work, but I had to use some locking mechanism between the GUI thread and the off-screen rendering thread so that only one of them is doing OpenGL instructions at one time (to avoid the GL instructions go to the wrong context). However, it’s very slow, and a bit temperamental, some times you stop seeing the screen rendering.

I also have tried to do the off-screen rendering in the GUI thread and start it with some signal/slot mechanism from the thread where I use to do the off-screen rendering. This works and seems more stable but the result is also quite slow too, maybe because of the delay in serving the signal in the GUI thread.

My problem is that I need to be able to do the off-screen rendering at 30fps and I can do that atm if I use off-screen rendering in isolation, without the QGLViewer.

I wonder if anybody knows a better way of getting this off-screen rendering working simultaneously with other OpenGL rendering on screen happening in another thread.