Results 1 to 6 of 6

Thread: Drawing to an offscreen buffer

  1. #1

    Default Drawing to an offscreen buffer

    The application I'm working on has several animating objects (rotating in a circle) and I'm looking to lower the CPU consumed. I'm using the graphicsview framework and most objects on the screen, including the animating objects are derived from QGraphicsWidget.

    I do set the viewport to QGLWidget so I get some OpenGL acceleration but that isn't lowering the CPU enough.

    I see setting the viewport to QGLWidget changes the paint engine to QOpenGLPaintEngine and translates a lot of the painter calls to OpenGL calls. Looking through the source and stepping through in debug, I come across this function of particular interest:

    Qt Code:
    1. void QGLDrawable::setDevice(QPaintDevice *pdev)
    2. {
    3. ...
    4. if (pdev->devType() == QInternal::Widget)
    5. widget = static_cast<QGLWidget *>(pdev);
    6. else if (pdev->devType() == QInternal::Pbuffer)
    7. buffer = static_cast<QGLPixelBuffer *>(pdev);
    8. else if (pdev->devType() == QInternal::FramebufferObject)
    9. fbo = static_cast<QGLFramebufferObject *>(pdev);
    10. else if (pdev->devType() == QInternal::UnknownDevice)
    11. ...
    12. }
    To copy to clipboard, switch view to plain text mode 

    It looks like this paint engine has the ability to render into a framebuffer object and this would probably give me a nice gain in performance (platform does support framebuffer objects).

    The only problem is I don't see how to change an object's PaintDevice. For all my objects the PaintDevice is of type Widget, which is expected.

    Does anyone know how I can change the PaintDevice to FramebufferObject?

    I've thought of changing this file to always use frame buffers but it seems there should be a way to set this.

  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: Drawing to an offscreen buffer

    Don't mess with such low level solutions. Instead turn on caching for your items - it will result in a performance boost which will probably be even better than using a framebuffer.
    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.


  3. #3

    Default Re: Drawing to an offscreen buffer

    Quote Originally Posted by wysota View Post
    Don't mess with such low level solutions. Instead turn on caching for your items - it will result in a performance boost which will probably be even better than using a framebuffer.
    I already use ItemCoordinateCache for all of my items.

    The problem is the animations are sucking a lot of CPU.

    To give you an idea of the application, it has 36 rotating images at 25 frames per second along with other static widgets and buttons.

    My target hardware is a 1 GHZ netbook with a via unichrome graphics chip.

    The above uses 90+% CPU.

    I can run Qt's framebufferobject2 example, texturing the quads with the same image used above and rotating them in the same way at 50 frames per second. And this uses only 15% or so CPU.

    That is the kind of gain I am looking for and the reason I thought getting frame buffers enabled would improve performance.
    Last edited by Dutch112; 5th May 2009 at 22:16.

  4. #4
    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: Drawing to an offscreen buffer

    Quote Originally Posted by Dutch112 View Post
    I already use ItemCoordinateCache for all of my items.
    Using the framebuffer won't help then. You might switch to DeviceCoordinateCache but I wouldn't expect miracles.

    To give you an idea of the application, it has 36 rotating images at 25 frames per second along with other static widgets and buttons.
    Are you performing the animation using QGraphicsScene::advance()?

    I can run Qt's framebufferobject2 example, texturing the quads with the same image used above and rotating them in the same way at 50 frames per second. And this uses only 15% or so CPU.
    It doesn't involve Graphics View, so no collision detection or transformations.

    That is the kind of gain I am looking for and the reason I thought getting frame buffers enabled would improve performance.
    Try profiling your application to see what is causing the slowdowns. I think the bottleneck is not rendering.
    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.


  5. #5

    Default Re: Drawing to an offscreen buffer

    Quote Originally Posted by wysota View Post
    Are you performing the animation using QGraphicsScene::advance()?
    No, right now the animations are each a QGraphicsWidget that use the QGraphicsItemAnimation.

    Quote Originally Posted by wysota View Post
    It doesn't involve Graphics View, so no collision detection or transformations.
    Could I disable collision detection?


    Quote Originally Posted by wysota View Post
    Try profiling your application to see what is causing the slowdowns. I think the bottleneck is not rendering.
    What profilers do you recommend?

  6. #6
    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: Drawing to an offscreen buffer

    Quote Originally Posted by Dutch112 View Post
    No, right now the animations are each a QGraphicsWidget that use the QGraphicsItemAnimation.
    Try switching to advance, it should be faster.


    Could I disable collision detection?
    If you're not moving the items too much then it's enough to set the "interactive" property of the view to false. If you are moving items but you don't care about collisions, disable indexing for the scene.

    What profilers do you recommend?
    Callgrind (part of Valgrind package) or gprof if you're running a supported platform. I don't profile on Windows so I can't recommend anything there.
    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. Replies: 5
    Last Post: 21st March 2009, 10:10
  2. Problems with QString
    By cyberboy in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2008, 09:18
  3. QImage buffer
    By rafaelsegundo in forum Qt Programming
    Replies: 3
    Last Post: 24th June 2008, 07:48
  4. Drawing graphs
    By steg90 in forum Newbie
    Replies: 4
    Last Post: 9th May 2007, 14:37
  5. Drawing on QWidget - strech & resize
    By kemp in forum Qt Programming
    Replies: 5
    Last Post: 22nd January 2007, 15:39

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.