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
QtWS25 Last Chance

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 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();
    
    jsulmJ 1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on 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
      0
      • D dalishi

        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();
        
        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on 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
        2
        • Kent-DorfmanK Kent-Dorfman

          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 last edited by
          #4

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

          Kent-DorfmanK 1 Reply Last reply
          0
          • jsulmJ jsulm

            @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 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

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

              Kent-DorfmanK Offline
              Kent-DorfmanK Offline
              Kent-Dorfman
              wrote on 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
              0
              • Kent-DorfmanK Kent-Dorfman

                @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 last edited by
                #7

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

                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