Important: Please read the Qt Code of Conduct -

What thread rules for Scene Graph with OpenGL?

  • Hi,
    I am trying to find out how threads works in the graphics scene .
    Using the "Scene Graph - OpenGL Under QML": example.
    It's a QQuickItem with OpenGL within its paint function.
    Reading the "Qt Quick Scene Graph": , it says that the rendering is done in a separate thread.
    So, I have monitored the threads during execution:
    [D] Ogl::handleWindowChanged:30 : 0x6c835740
    [D] Ogl::handleWindowChanged:38 : 0x6c835740
    [D] Ogl::handleWindowChanged:40 : 0x6c835740
    [D] Ogl::handleWindowChanged:44 : 0x6c835740
    [D] Ogl::sync:118 - sync: 0x67fffb40
    So, starting from the 'sync' function in my (QQuickItem based) ogl object, all is executed in another thread.
    Is this change caused by (win = the QQuickView object):
    @connect(win, SIGNAL(beforeSynchronizing()), this, SLOT(sync()), Qt::DirectConnection);@
    Forcing to run the sync slot in the new thread?
    More general: how do I know what is run in which thread?
    My final ogl object needs lots of data (from objects in the main/GUI thread) to be used during rendering...

  • beforeSynchronizing and beforeRendering are emitted on scenegraph's render thread. You are connected using DirectConnection and therefore sync() is called on that thread. This is how it should be, you cannot have the sync and painting function executed on your gui thread, they must be done on the render thread.

    Follow the pattern used in the example: in sync() copy the necessary data from the gui thread. In paint() perform drawing using the copy of the data.

  • That is clear. Thanks a lot!
    Data is to much to copy (textures, 3D and more).
    I'll have a look how serialize: force the GUI thread to wait.

Log in to reply