3

I am working on a project that will use OpenCL to render graphics for display in a QOpenGLWidget. The recommended way to do this seems to be creating a second QOpenGLContext beside the one already present in the QOpenGLWidget, then create a thread where this secondary context can live together with the OpenCL code.

This way Qt can go about it's day as usual with the eventloop running in the main thread. And whenever the QOpenGLWidget decides to paint it will simply fetch data from a buffer prepared in the second thread by the secondary context and the OpenCL inter-op set up there.

This all sounds great on paper, but I am having some problems getting this to work. My question is about how to make the secondary QOpenGLContext "current" in the thread. Because QOpenGLContext::makeCurrent() takes a mandatory QSurface as parameter, and the only surface I have is the one that is available from my QOpenGLWidget, but using that in the secondary thread does not work. I get the following error:

Cannot make QOpenGLContext current in a different thread

So what surface should I use? Or, is there something I missed, or should do differently?

user2399321
  • 605
  • 7
  • 13
Mr. Developerdude
  • 9,118
  • 10
  • 57
  • 95
  • If you have an OpenCL based renderer, why do you even need a GL context? Also, if your renderer runs in a second thread and provides an image whenever it's ready, why don't you simply notify your GUI that it can get the finished new frame? No OpenGL needed for that at all. Or am I missing something? Are you doing GL/CL interop? – thokra Sep 23 '16 at 11:16
  • Yes, interop :) sorry I should have mentioned it. The output is used in the gl context – Mr. Developerdude Sep 23 '16 at 11:17

1 Answers1

3

You can create and use a QOffscreenSurface for this purpose.

peppe
  • 21,934
  • 4
  • 55
  • 70