Results 1 to 5 of 5

Thread: QGLWidget + QEventDispatcherGlib::processEvents performance problem!

  1. #1
    Join Date
    Jan 2006
    Posts
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11

    Exclamation QGLWidget + QEventDispatcherGlib::processEvents performance problem!

    greetings trollers,
    Abstract
    I have problem with QGLWidget and its Event loop or related (QEventDispatcherGlib::processEvents).
    Introduction
    I am sub-classing QGLWidget (class ImgFrame) and use that class (ImgFrame) to paint a QImage. The problem is: although I use separate thread object for manipulating a temporary image prior to copying it to the image of ImgFrame, the main thread uses a lot of CPU time for dispatching internal events not related to my code.
    As a proof of this issue I sub-classed ImgFrame from QWidget instead and the processing speed became 50 folds faster.
    Why Use QGLWidget?
    Well, Intend to use this application mainly for real-time multi-threaded video processing and when painting in 30 frames per sec, drawing on QGLWidget has better performane than QWidget (see the 2dpainting example that comes with QT4.3)
    Attachments
    I attached the source code (Kdevelop project) and Valgrind performance analysis snapshot for further clearance.
    thank you,
    firas
    Attached Files Attached Files

  2. #2
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGLWidget + QEventDispatcherGlib::processEvents performance problem!

    I don' see that your problem has anything to do with QGLWidget. I am testing on Windows, though so there could be some differences.

    I guess you are wondering why the grayscale conversion takes forever.
    Firstly don't use pixel() and setPixel() they are really inefficient!
    Secondly, don't post more events than you need! That way it's no wonder that the event loop gets busy.

    Just as a test try the following:
    Qt Code:
    1. if(y%100==0)
    2. QCoreApplication::postEvent(anaPen,new IplikEvent(4,mesajStr.setNum((100*y)/height)) );
    3. QRgb* rgbLine = (QRgb*)crntImg->scanLine(y);
    4. QRgb* grayLine = (QRgb*)sonucImg->scanLine(y);
    5. for (uint x=0 ; x<width; ++x)
    6. {
    7. QRgb rgb = *rgbLine++;
    8. uchar graylevelNTSC = (11 * qRed(rgb) + 16 * qGreen(rgb) + 5 * qBlue(rgb) )/32;
    9. *grayLine++ = qRgb(graylevelNTSC,graylevelNTSC,graylevelNTSC);
    To copy to clipboard, switch view to plain text mode 

    And as a matter of coding style, I suggest you encapsulate your classes better. There is no way GriYapIpligi.cpp should have to include all the header files in your project.

  3. #3
    Join Date
    Jan 2006
    Posts
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11

    Thumbs down Re: QGLWidget + QEventDispatcherGlib::processEvents performance problem!

    Quote Originally Posted by spud View Post
    I don' see that your problem has anything to do with QGLWidget. I am testing on Windows, though so there could be some differences.

    I guess you are wondering why the grayscale conversion takes forever.
    Firstly don't use pixel() and setPixel() they are really inefficient!
    Secondly, don't post more events than you need! That way it's no wonder that the event loop gets busy.
    Thanx spud, maybe you where too quick to comment on this:

    1. Check Callgrind output (profiling the application would be better though)
    2. In class ImgFrame sub-class it from QWidget instead compile run and test again and let me know
    3. I'm aware of the set/get pixel issue (although it is clearly not the problem)

    Quote Originally Posted by spud View Post
    And as a matter of coding style, I suggest you encapsulate your classes better. There is no way GriYapIpligi.cpp should have to include all the header files in your project.
    I'm aware of this, it is not an issue.

  4. #4
    Join Date
    Jan 2006
    Posts
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11

    Exclamation Re: QGLWidget + QEventDispatcherGlib::processEvents performance problem!

    No reasonable explanation yet, Wysota maybe you have a say on this, I recall that you did help me once with a related issue.
    thanx
    firas

  5. #5
    Join Date
    Jan 2006
    Posts
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11

    Thumbs up Re: QGLWidget + QEventDispatcherGlib::processEvents performance problem!

    Fixed, briefly instead of using qt based QGLWidget::paintEvent, I used directly OpenGL to draw my frames.
    sample would be:
    Qt Code:
    1. ::initializeGL(){
    2. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    3. }
    4.  
    5. ::paintGL(){
    6. glRasterPos2i(0,0);
    7. glDrawPixels(pImg->width(), pImg->height(), GL_BGRA, GL_UNSIGNED_BYTE, pImg->bits());
    8. glPixelZoom(1.0,-1.0);
    9. glFlush();
    10. }
    To copy to clipboard, switch view to plain text mode 

    For more interesting way google for "OpenGL programming guide (AKA OpenGL RedBook)"
    salutations a tous qui m'aider!!
    firas

Similar Threads

  1. QGLWidget Resize Problem
    By Sandip in forum Qt Programming
    Replies: 2
    Last Post: 28th February 2008, 06:47
  2. QGLWidget 2d painting performance
    By amnesiac in forum Qt Programming
    Replies: 15
    Last Post: 28th January 2008, 14:09
  3. QGLWidget resize problem.
    By anderl in forum Qt Programming
    Replies: 2
    Last Post: 22nd January 2008, 08:57
  4. why linking problem with QGLWidget???
    By Shuchi Agrawal in forum Newbie
    Replies: 17
    Last Post: 16th March 2007, 10:45
  5. Problem combining QWorkspace & QGLWidget
    By Nb2Qt in forum Qt Programming
    Replies: 1
    Last Post: 18th December 2006, 21:45

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.