QOpenGLShaderProgram in different Threads and QOpenGLContexts [SOLVED]

  • Hi together,

    I am using QOpenGLShaderProgram objects to compile, link and bind my OpenGL shaders which works pritty awesome!
    The thing is that i have more than one rendering thread with different QOpenGLContexts each.

    Now the problem:
    Each thread needs to have the shaders (which are mostly the same!) and i encapsulated the compile and link step into a separate method which is part of my derived QOpenGLShaderProgram class. This method will be called if the renderer accesses the shader the first time. But the renderer is in a different thread. So i get this message:
    QObject: Cannot create children for a parent that is in a different thread.
    (Parent is QOpenGLShaderProgram(0x5e0884), parent's thread is QThread(0x6e9d98), current thread is QThread(0x5d1860) )

    So i guess that QOpenGLShader program is instantiating new QOpenGLShader instances and sets itself as the parent!?

    Now my question:
    Is there a possibility to either deactivate adding new child objects in QOpenGLShader program or can i somehow share the shaders between different QOpenGLContexts? Thus, that the graphics card has to compile the shader only once and each thread just has to call QOpenGLShaderProgram::bind()!?

    The second solution would be the finest! But i don't know if it is possible or how to make it!

    Thanks in advance.

  • I solved the problem. I just create a new QOpenGLShader program instance for each thread once it renders the object the first time.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.