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 performance
Forum Update on Monday, May 27th 2025

qpainter performance

Scheduled Pinned Locked Moved Solved General and Desktop
qpainterperformanceopengl
7 Posts 3 Posters 1.5k Views
  • 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.
  • D Offline
    D Offline
    dalishi
    wrote on 26 Jul 2019, 05:23 last edited by dalishi
    #1

    Hi Im drawing using OpenGL for 3D and qpainter for 2D and text. In my OpenGL widget paintGL(), i have qpainter to draw a sequence of texts on respective positions (e.g. 100 positions with 100 texts). I just realize that those draw calls are killing the performance. Since my OpenGL app is refreshing at ~30Hz, so i try to restrict each frame draw within ~30milliseconds. However, these qpainter draws here would normally cost more than 10milliseconds.

    How should I optimize this? Is there any batch processing/draws for qpainter so that I no need issue a draw call in a loop? Thanks.

    m_painter.begin(this);
    for (int i = 0; i<100; ++i) {
        ...
        m_painter.drawText(pose, text);
        ...
    }
    m_painter.end();
    
    J 1 Reply Last reply 26 Jul 2019, 05:57
    0
    • K Offline
      K Offline
      Kent-Dorfman
      wrote on 26 Jul 2019, 05:52 last edited by
      #2

      use openGL for text rendering as well. The facilities exist. Mixing the two in one viewport will be problematic.

      D 1 Reply Last reply 26 Jul 2019, 07:18
      0
      • D dalishi
        26 Jul 2019, 05:23

        Hi Im drawing using OpenGL for 3D and qpainter for 2D and text. In my OpenGL widget paintGL(), i have qpainter to draw a sequence of texts on respective positions (e.g. 100 positions with 100 texts). I just realize that those draw calls are killing the performance. Since my OpenGL app is refreshing at ~30Hz, so i try to restrict each frame draw within ~30milliseconds. However, these qpainter draws here would normally cost more than 10milliseconds.

        How should I optimize this? Is there any batch processing/draws for qpainter so that I no need issue a draw call in a loop? Thanks.

        m_painter.begin(this);
        for (int i = 0; i<100; ++i) {
            ...
            m_painter.drawText(pose, text);
            ...
        }
        m_painter.end();
        
        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 26 Jul 2019, 05:57 last edited by
        #3

        @dalishi Do these text strings change all the time or their positions?
        If not I would paint them on a pixmap each time something changes and then only paint this pixmap in paint event.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        D 1 Reply Last reply 26 Jul 2019, 07:22
        2
        • K Kent-Dorfman
          26 Jul 2019, 05:52

          use openGL for text rendering as well. The facilities exist. Mixing the two in one viewport will be problematic.

          D Offline
          D Offline
          dalishi
          wrote on 26 Jul 2019, 07:18 last edited by
          #4

          @kent-dorfman Hi do you mind share what facilities you referred to? Like FreeType library?

          K 1 Reply Last reply 27 Jul 2019, 03:36
          0
          • J jsulm
            26 Jul 2019, 05:57

            @dalishi Do these text strings change all the time or their positions?
            If not I would paint them on a pixmap each time something changes and then only paint this pixmap in paint event.

            D Offline
            D Offline
            dalishi
            wrote on 26 Jul 2019, 07:22 last edited by
            #5

            @jsulm Hi the position and text are not changed but just increased in amount, meaning the position and text vectors are increasing in size. Now I just redraw the whole vector every frame. And it also has operations like zoom in/out, and translation on screen. I will try to explore more on your methods. Thanks.

            1 Reply Last reply
            0
            • D dalishi
              26 Jul 2019, 07:18

              @kent-dorfman Hi do you mind share what facilities you referred to? Like FreeType library?

              K Offline
              K Offline
              Kent-Dorfman
              wrote on 27 Jul 2019, 03:36 last edited by
              #6

              @dalishi
              See [this link] for several methods of inserting text directly into a GL visual. Mixing QPainter and GL in a single visual seems problematic to me...unless you make a raster bitmap the target of the QPainter and then blast that bitmap into the GL viewport.

              D 1 Reply Last reply 29 Jul 2019, 05:44
              0
              • K Kent-Dorfman
                27 Jul 2019, 03:36

                @dalishi
                See [this link] for several methods of inserting text directly into a GL visual. Mixing QPainter and GL in a single visual seems problematic to me...unless you make a raster bitmap the target of the QPainter and then blast that bitmap into the GL viewport.

                D Offline
                D Offline
                dalishi
                wrote on 29 Jul 2019, 05:44 last edited by
                #7

                @kent-dorfman Thanks and will try out those methods also.

                1 Reply Last reply
                0

                1/7

                26 Jul 2019, 05:23

                • Login

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