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?