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. Most efficient way to approach lots of polygons in QML/C++?
Qt 6.11 is out! See what's new in the release blog

Most efficient way to approach lots of polygons in QML/C++?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 3.5k Views 2 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.
  • J Offline
    J Offline
    j_omega
    wrote on last edited by j_omega
    #1

    I am struggling with getting my QML application to run smoothly. I have extended QQuickPaintedItem to make a 2D map page. I then use the painter to draw out all of my map components which are store in QPolygons. The problem is that there are a lot of items to draw on the page. For example, the following screenshot is composed of 695 polygons with a total of 363051 points.

    I tried setting the render target to QQuickPaintedItem::FramebufferObject but that seems to make it run slower...

    I know from the 40000 chips example that Qt is capable of handling such things. I think I just need to implement it differently.

    What design changes can I make to make this run smoother?

    1_1513951727892_efis map.png

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by sierdzio
      #2

      You can switch to QGraphicsView instead of QML.

      However, staying with QML is a good idea, but you probably need to forget about QQuickPainted item. Consider using raw OpenGL instead, or the QNanoPainter: http://kgronholm.blogspot.fi/2015/10/introducing-qnanopainter.html check out other blogs from this guy, a lot of performance-related information there.

      Also, this article might help you along the way.

      (Z(:^

      J 1 Reply Last reply
      1
      • sierdzioS sierdzio

        You can switch to QGraphicsView instead of QML.

        However, staying with QML is a good idea, but you probably need to forget about QQuickPainted item. Consider using raw OpenGL instead, or the QNanoPainter: http://kgronholm.blogspot.fi/2015/10/introducing-qnanopainter.html check out other blogs from this guy, a lot of performance-related information there.

        Also, this article might help you along the way.

        J Offline
        J Offline
        j_omega
        wrote on last edited by
        #3

        @sierdzio I originally wrote this project in only C++ with raw OpenGL calls. The whole reason that I switched to Qt was for the convience that the painter offered so I really want to stick with the painter. What are the big drawback to switching to QGraphicsView at this point?

        ? sierdzioS 2 Replies Last reply
        0
        • J j_omega

          @sierdzio I originally wrote this project in only C++ with raw OpenGL calls. The whole reason that I switched to Qt was for the convience that the painter offered so I really want to stick with the painter. What are the big drawback to switching to QGraphicsView at this point?

          ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          @j_omega "What design changes can I make to make this run smoother?

          Hi J, not an answer to your problem as such, but I'm currently reading this mind-blowing C++ book by Bob Nystrom, and it delves into such matters as shoveling polygons into the CPU and GPU. You may find it interesting. http://gameprogrammingpatterns.com/design-patterns-revisited.html

          1 Reply Last reply
          0
          • J j_omega

            @sierdzio I originally wrote this project in only C++ with raw OpenGL calls. The whole reason that I switched to Qt was for the convience that the painter offered so I really want to stick with the painter. What are the big drawback to switching to QGraphicsView at this point?

            sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #5

            @j_omega said in Most efficient way to approach lots of polygons in QML/C++?:

            What are the big drawback to switching to QGraphicsView at this point?

            Well, the code rewriting might be a drawback of course :-) QGraphicsView is based on widgets, not QML so it will require changes in the UI code. It also lacks some QML features like shader support, graphical effects etc.
            But it offers a lot when it comes to fine tuning the performance, and excellent support for custom shapes.

            Perhaps a good idea would be to wrtie a small test project/ benchmark with QGraphicsView, it will allow you to compare ease of maintenance, performance etc. of both solutions.

            Also, going back to your original question:

            What design changes can I make to make this run smoother?

            Here are a few general ideas on how to (potentially... I recommend checking with some benchmark) improve the performance. Some may not apply to your app:

            • make sure you only paint and keep in memory items which are visible on the screen - invisible parts of the map should be clipped
            • use lazy initialization - only load part of the scene initially, then continue loading more items only if needed
            • check out the QNanoPainter and other hints from the articles I linked before
            • use caching - this is potentially the biggest gain. For example, only paint your QPolygons in a single item once and store the result in an image. Then, when QML engine wants to paint the item, provide the image from cache instead of recalculating and repainting the whole QPainterPath
            • try to reuse components as much as possible - it looks like a lot of them are really similar so if the cache mentioned above can be shared between items, you could see even better results
            • if you use SVG images anywhere - don't :-) Rendering SVG is very slow
            • read through the official guidelines for QML performance http://doc.qt.io/qt-5/qtquick-performance.html
            • don't use QML Shape components - they are great but slow :-)
            • see if you can port some of the items to use shaders for example, so that they are painted by your GPU instead of CPU
            • try to minimize the load on QML engine - less bindings, more C++ (than JS), less timers and animations

            (Z(:^

            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