Results 1 to 9 of 9

Thread: Performance issues when using QWidget::render with a QGLWidget's painter

  1. #1

    Default Performance issues when using QWidget::render with a QGLWidget's painter

    I'm currently drawing widgets to a QGLWidget using render() inside of the QGLWidget's paintEvent. The problem I have occurs when I use setOpacity() on the painter, the performance tanks and the app becomes unusably slow until the widget is hidden.

    During this time I notice that my CPU spikes, which I didn't expect because I thought this technique would make use of QOpenGLPaintEngine and thus be hardware accelerated.

    Why is this not being accelerated and what can I do to speed this up?

  2. #2

    Default Re: Performance issues when using QWidget::render with a QGLWidget's painter

    After some experimentation I've found that each widget rendered in this manner causes a noticeable hit to performance and so a widget with several children (a frame with 8 buttons, an image, and some labels in my case) together cause the slowdown.

    Is it possible for me optimize this? Rendering without transparency to an intermediary pixmap and then drawing that with transparency to the QGLWidget doesn't seem to help, which is counterintuitive to me.

  3. #3

    Default Re: Performance issues when using QWidget::render with a QGLWidget's painter

    After further experimentation I've found that images used in the UI severely hurt performance, possibly because images are copied to an intermediary pixmap by QOpenGLPaintEngine before they are drawn.

    I greatly appreciate any advice for optimization.

  4. #4

    Default Re: Performance issues when using QWidget::render with a QGLWidget's painter

    According to a co-worker these performance issues were less problematic when using a QGraphicsScene, is that rendering pipeline really so different?

  5. #5
    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: Performance issues when using QWidget::render with a QGLWidget's painter

    Yes, it's completely different. With every update of QGLWidget the whole widget is redrawn from scratch. With regular widgets and graphics item only the portions that changed are getting redrawn. At least by default.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6

    Default Re: Performance issues when using QWidget::render with a QGLWidget's painter

    Quote Originally Posted by wysota View Post
    Yes, it's completely different. With every update of QGLWidget the whole widget is redrawn from scratch. With regular widgets and graphics item only the portions that changed are getting redrawn. At least by default.
    Sorry I wasn't clear, I didn't mean the difference between drawing a QGLWidget and a regular QWidget, I am well aware of that. I meant the difference between rendering a widget to to a GL context in a QGraphicsScene versus rendering the same widget to a QGLWidget. Why is former performant and the latter slow?

  7. #7
    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: Performance issues when using QWidget::render with a QGLWidget's painter

    Again, if you render an item that doesn't change in the graphics scene, it is likely there is a clean copy of it available and your paint() implementation for it (that calls render()) will not be called. With a pure widget if you don't do any caching yourself, render() will be called for every widget involved during every repaint. Calling render() is generally expensive so you want to avoid it if you can - cache everything you can in pixmaps. And if the only reason for doing all this is that you want to have semi-transparent widgets on a GL scene, find a better approach than this, you'll have tons of trouble making your "widget stamps" work like real widgets (i.e. focus handling). It's easiest to go through GraphicsScene, it handles such a situation and has everything required for it to work already implemented.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8

    Default Re: Performance issues when using QWidget::render with a QGLWidget's painter

    cache everything you can in pixmaps.
    Even when doing caching and only updating the pixmaps when something changes each change causes a noticeable hiccup in the QGLWidget as well as the rest of the application. I am curious as to why this does not occur when using a QGraphicsScene, how are the pixmaps being managed and utilized in such a way that don't cause this hiccup?

    find a better approach than this
    Unfortunately, due to the nature of the target platform (weak intel integrated graphics), most easy solutions fail due to driver issues or their own performance problems. (What I would give to simply be able to have `-graphicssystem opengl` work)

    you'll have tons of trouble making your "widget stamps" work like real widgets (i.e. focus handling).
    Not if the widget is actually above the QGLWidget, but left undrawn (by Qt's normal drawing) using clip masks.

    It's easiest to go through GraphicsScene
    This requires the current drawing done in the several QGLWidgets involved to be rewritten for the QGraphicsScene context, which is not insignificant. I am trying to get a good handle on the various avenues available to me to determine where best to put my efforts.

    I'm not saying our current implementation was the right choice, but we're trying to solve this in a way that minimizes modifications to the existing app's architecture.

  9. #9
    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: Performance issues when using QWidget::render with a QGLWidget's painter

    Quote Originally Posted by Bjartr View Post
    Even when doing caching and only updating the pixmaps when something changes each change causes a noticeable hiccup in the QGLWidget as well as the rest of the application. I am curious as to why this does not occur when using a QGraphicsScene, how are the pixmaps being managed and utilized in such a way that don't cause this hiccup?
    I'd have to see your code to be able to say anything.


    Unfortunately, due to the nature of the target platform (weak intel integrated graphics), most easy solutions fail due to driver issues or their own performance problems. (What I would give to simply be able to have `-graphicssystem opengl` work)
    I would go through graphics view. And I would try -graphicssystem raster too.


    Not if the widget is actually above the QGLWidget, but left undrawn (by Qt's normal drawing) using clip masks.
    Clipping is slooooo(o...)ow.

    This requires the current drawing done in the several QGLWidgets involved to be rewritten for the QGraphicsScene context, which is not insignificant. I am trying to get a good handle on the various avenues available to me to determine where best to put my efforts.
    If your OpenGL implementation supports pixel buffers, you can render to a pixel buffer using OpenGL and display the results on graphics items.

    I'm not saying our current implementation was the right choice, but we're trying to solve this in a way that minimizes modifications to the existing app's architecture.
    Sometimes it's faster to scrap everything and go the right way instead of working around broken code.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Render QWidget within QGLWidget
    By crazymonkey in forum Newbie
    Replies: 29
    Last Post: 26th September 2010, 13:54
  2. Replies: 1
    Last Post: 7th May 2010, 17:20
  3. QGLWidget Render Text in the foreground
    By arpspatel in forum Qt Programming
    Replies: 1
    Last Post: 11th April 2010, 11:35
  4. Replies: 0
    Last Post: 1st April 2010, 07:47
  5. QWidget::render() and sharedPainter
    By faldzip in forum Qt Programming
    Replies: 0
    Last Post: 10th November 2008, 20:04

Tags for this Thread

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.