qpainter performance



  • 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();
    


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


  • Qt Champions 2018

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



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



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



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



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