QPainter's performance:begin and end , fps <= 60



  • my window type:
    @class MyWindow : public QGLWidget{...}@
    when I use QPainter to draw on MyWindow like this:
    @QPainter p;
    MyWindow w;
    p.begine(w);
    p.drawImage(0,0,myImage);
    p.end();@
    The fps is 60 at most and I test p.begin and p.end, it costs about 16ms absolutely on different platform,Desktop, Android and IOS.As if the painter is strictly-timed.I do not know the mechanism underly.


  • Moderators

    Hi,

    What is your question?

    QPainter uses CPU rendering. OpenGL uses GPU rendering. If you want high-performance and/or 3D graphics, use OpenGL instead of QPainter.

    EDIT: Actually, QPainter makes OpenGL calls in a QGLWidget



  • [quote author="JKSH" date="1407386095"]Hi,

    What is your question?

    QPainter uses CPU rendering. OpenGL uses GPU rendering. If you want high-performance and/or 3D graphics, use OpenGL instead of QPainter.

    [/quote]

    Why CPU rendering has same rendering speed even on different platforms? In my test , the fps could not be higher than 60 even the loop is driven 100 times per second.

    Since the QGLWidget class is a widget for rendering OpenGL graphics, is it strange to use QGLWidget as QPainter's paint device? And if I need higher performance in qt, where should I go?

    Thanks a lot.


  • Moderators

    [quote author="wade-J" date="1407395369"]Why CPU rendering has same rendering speed even on different platforms? In my test , the fps could not be higher than 60 even the loop is driven 100 times per second.[/quote]"VSync":http://www.androidpolice.com/2012/07/12/getting-to-know-android-4-1-part-3-project-butter-how-it-works-and-what-it-added/ synchronizes painting operations with your screen's refresh rate. Your screens have a refresh rate of 60 Hz, so you get a maximum frame rate 60 fps.

    If your screen refreshes at 60 Hz but you force your program to paint 100 times a second, then you might get screen tearing because you change the pixel data when the screen is still in the middle of updating itself.

    [quote author="wade-J" date="1407395369"]Since the QGLWidget class is a widget for rendering OpenGL graphics, is it strange to use QGLWidget as QPainter's paint device? And if I need higher performance in qt, where should I go?[/quote]What are you trying to do? What performance do you need?



  • [quote author="JKSH" date="1407397166"]What are you trying to do? What performance do you need?[/quote]
    I am writing a game which use QPainter to draw images on MyWindow which inherits from QGLWindow.My frame is like this:

    @loop(){
    painter.begin(mywindow);
    for(){
    //draw a lot of images
    }
    painter.end();
    }@

    The performance is not satisfying, only 30 fps.So I test the performance of @painter.begin(mywindow);
    painter.end();@
    and I found it is 60 fps at most.


  • Moderators

    [quote author="wade-J" date="1407421016"]The performance is not satisfying, only 30 fps.So I test the performance of @painter.begin(mywindow);
    painter.end();@
    and I found it is 60 fps at most.[/quote]That is not a valid test. VSync makes sure that your frame rate never exceeds your refresh rate.

    [quote author="wade-J" date="1407421016"]I am writing a game which use QPainter to draw images on MyWindow which inherits from QGLWindow.My frame is like this:

    @loop(){
    painter.begin(mywindow);
    for(){
    //draw a lot of images
    }
    painter.end();
    }@
    [/quote]I don't think QPainter is optimized for drawing lots of images.

    What do your images look like?

    Have you tried drawing them with raw OpenGL functions?

    Have you looked at Qt Quick?

    Is this a 2D or 3D game?



  • [quote author="JKSH" date="1407424457"]

    What do your images look like?

    Have you tried drawing them with raw OpenGL functions?

    Have you looked at Qt Quick?

    Is this a 2D or 3D game?[/quote]

    It is a 2D game and the images are small .jpg and .png images.
    I have looked at Qt QML and tried qml canvas to draw iamges. The performance is not satisfied, so I am trying using the QPainter directly.

    I haven't try Open GL functions now. I will have a try. Maybe it works in my situation.




  • Moderators

    [quote author="wade-J" date="1407463047"]It is a 2D game and the images are small .jpg and .png images.
    I have looked at Qt QML and tried qml canvas to draw iamges. The performance is not satisfied, so I am trying using the QPainter directly.

    I haven't try Open GL functions now. I will have a try. Maybe it works in my situation.[/quote]When you said "small .jpg and .png images", do you mean Particles? QML has a dedicated particle system, which is designed to draw and animate lots of small images. See http://qt-project.org/doc/qt-5/qtquick-particles-system-example.html

    From what you've posted so far, it's not clear what is reducing your performance.

    I recommend that you profile your code first, to understand where the bottlenecks are. (e.g. http://qt-project.org/doc/qtcreator-3.1/creator-qml-performance-monitor.html )

    Then, start 2 new threads: In the 1st thread, post your QML code. In the 2nd thread, post your QPainter code. Then, ask people to review your code and see if there's a way to improve their efficiency.



  • oh,it is not particle program,just some picture about 100*100 pixels.,like this game(http://www.7k7k.com/swf/59258.htm)
    The fps is not satisfying on mobile platforms, only about 30 fps on iphone4(iphone4s is 60 fps).
    And the fps is not stable.I wander it is because the garbage collection,but I have not found way to test.Do you have any suggestion?

    ok,I will try your suggestion.Thanks so much.



  • Is there articles to explain the meaning of qml profiler? I get the profile file, but not clear with some of the meaning, such as "time in percent" in the Event tab,Timeline tab.And the JavaScript tab is empty.



  • I finally found the reason:the Timer in QML is not suitable for my case,because the drawing time is not included in the interval of the Timer.I changed to use QTimer instead and setTimerType to Qt::PreciseTimer.The fps increases a lot.

    Thanks again.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.