Results 1 to 3 of 3

Thread: Multithreaded OpenGL

  1. #1
    Join Date
    Nov 2008
    Posts
    38
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Multithreaded OpenGL

    I managed to hunt down this article from the qt3 days (http://lists.trolltech.com/qt-intere.../msg00940.html) but I remain confused and unconvinced...

    I need several threads which are making native OpenGL calls on independent QGLPixelBuffer objects, looping and issuing drawing commands at unpredictable times. If one thread calls makeCurrent() and issues half its drawing commands before another calls makeCurrent() and starts its own work, won't one threads drawing commands apply to another's rendering context?

    I'm at a loss as to how anyone can call the library "thread safe". Can someone please enlighten me?

    P.S. is that XInitThreads() call still necessary? I'm at version 4.4.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Multithreaded OpenGL

    Quote Originally Posted by spraff View Post
    I need several threads which are making native OpenGL calls on independent QGLPixelBuffer objects, looping and issuing drawing commands at unpredictable times. If one thread calls makeCurrent() and issues half its drawing commands before another calls makeCurrent() and starts its own work, won't one threads drawing commands apply to another's rendering context?
    I don't think that's safe. You'd have to do proper synchronization using wait conditions or plain mutexes.

    I'm at a loss as to how anyone can call the library "thread safe". Can someone please enlighten me?
    Qt4 is not thread safe. Some parts of it are thread safe, but not all.

    P.S. is that XInitThreads() call still necessary? I'm at version 4.4.
    I don't see a word about multithreading in the OpenGL module docs, so I'd say it's still necessary, but I doubt it will save your day.

  3. #3
    Join Date
    May 2009
    Posts
    21
    Thanks
    4
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Multithreaded OpenGL

    If one thread calls makeCurrent() and issues half its drawing commands before another calls makeCurrent() and starts its own work, won't one threads drawing commands apply to another's rendering context?
    You will need to create a different open gl context for each thread. But then the OpenGL context is thread-specific and makeCurrent on the context will only affect the thread you are calling from. So it is okay to do parallel open gl drawing from different threads.

    Yes you still have to call XInitThreads() before any drawing.

    Regards

    Lodorot

    Concurrency and OpenGL
    Parallel OpenGL FAQ
    Last edited by Lodorot; 5th March 2010 at 17:04.

Similar Threads

  1. OpenGL and Qt Question
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 18th April 2009, 18:04
  2. QT + OpenGL + Thread => aaaahhhhh !
    By anthibug in forum Qt Programming
    Replies: 7
    Last Post: 26th July 2008, 13:36
  3. openGL in Qtopia core
    By sar_van81 in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 18th July 2008, 11:26
  4. Qtopia Core & OpenGL ES?
    By zelko in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 28th May 2007, 07:21
  5. multithreaded OpenGL Qt application
    By yuriy in forum Qt Programming
    Replies: 2
    Last Post: 1st September 2006, 17:54

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.