Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPainter's performance:begin and end , fps <= 60
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
12 Posts 2 Posters 6.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wade-J
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      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

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • W Offline
        W Offline
        wade-J
        wrote on last edited by
        #3

        [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.

        1 Reply Last reply
        0
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          [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?

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0
          • W Offline
            W Offline
            wade-J
            wrote on last edited by
            #5

            [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.

            1 Reply Last reply
            0
            • JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by
              #6

              [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?

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              0
              • W Offline
                W Offline
                wade-J
                wrote on last edited by
                #7

                [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.

                1 Reply Last reply
                0
                • W Offline
                  W Offline
                  wade-J
                  wrote on last edited by
                  #8

                  Thr "VSyn":http://www.androidpolice.com/2012/07/12/getting-to-know-android-4-1-part-3-project-butter-how-it-works-and-what-it-added/ is impressing and explains why my test is 60 fps at most.Thanks.

                  1 Reply Last reply
                  0
                  • JKSHJ Offline
                    JKSHJ Offline
                    JKSH
                    Moderators
                    wrote on last edited by
                    #9

                    [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.

                    Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                    1 Reply Last reply
                    0
                    • W Offline
                      W Offline
                      wade-J
                      wrote on last edited by
                      #10

                      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.

                      1 Reply Last reply
                      0
                      • W Offline
                        W Offline
                        wade-J
                        wrote on last edited by
                        #11

                        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.

                        1 Reply Last reply
                        0
                        • W Offline
                          W Offline
                          wade-J
                          wrote on last edited by
                          #12

                          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.

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved