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. QOpenGLWidget, high CPU usage from update()
Forum Updated to NodeBB v4.3 + New Features

QOpenGLWidget, high CPU usage from update()

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 4 Posters 1.2k 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.
  • O Offline
    O Offline
    Oen44
    wrote on last edited by
    #1

    I'm using QPainter to draw bunch of images on the OpenGL widget. Right now, OpenGLWidget is taking 25-30% of my CPU (Intel i5). Adding images doesn't change the CPU usage, however removing update() from paintGL() event does help and CPU usage is down to 2%.
    Using QPainter to draw these images.
    Here is how it looks like, that lighter gray area is OpenGL widget.
    screenshot
    As you can see, there are 2 Buttons which use the same image. Each Button size can be changed so the image is stretching (using 9-Slice function). Maybe I should change from QPainter to pure OpenGL? Not sure as CPU usage doesn't change if there are some images or there is none at all. It's something with that update().

    1 Reply Last reply
    0
    • O Offline
      O Offline
      Oen44
      wrote on last edited by Oen44
      #11

      Even if I call update when mouse is pressed and moved (which doesn't create any stuttering), CPU usage still goes up. So it doesn't matter if I call it in paintGL or anywhere else. The only advantage is that when nothing is touched, there is only 3% usage.
      I feel like I should drop that OpenGL widget and do something else to achieve same results as now.

      Edit

      So I just reused QTimer and it worked. 2-3% CPU usage, 60FPS.

      QTimer *pTimer = new QTimer(this);
      connect(pTimer, SIGNAL(timeout()), this, SLOT(update()));
      pTimer->start(1000 / 60.0);
      
      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        Out of curiosity, why reproduce a widget like interface in OpenGL ?

        Why not use standard widgets ?
        Maybe QtQuick depending on your application goal.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        O 1 Reply Last reply
        1
        • SGaistS SGaist

          Hi,

          Out of curiosity, why reproduce a widget like interface in OpenGL ?

          Why not use standard widgets ?
          Maybe QtQuick depending on your application goal.

          O Offline
          O Offline
          Oen44
          wrote on last edited by Oen44
          #3

          @SGaist said in QOpenGLWidget, high CPU usage from update():

          Hi,

          Out of curiosity, why reproduce a widget like interface in OpenGL ?

          Why not use standard widgets ?
          Maybe QtQuick depending on your application goal.

          I found that OpenGL is what I need to draw and manipulate things. That is drawing a lot of images, adding outlines, pivots to control resizing, moving images by dragging etc.
          Here is the source code (and example video of how the app works) https://github.com/Oen44/OTUIEditor

          What do you think should I change to then?

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #4

            No problem with doing stuff in OpenGL ! I was just wondering why also add all the work for clickable buttons and such stuff directly in OpenGL.

            But I may have missed the end goal of your designer application.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            O 1 Reply Last reply
            1
            • SGaistS SGaist

              No problem with doing stuff in OpenGL ! I was just wondering why also add all the work for clickable buttons and such stuff directly in OpenGL.

              But I may have missed the end goal of your designer application.

              O Offline
              O Offline
              Oen44
              wrote on last edited by
              #5

              Positioning and resizing is why. Each button, windows and all that stuff is saved in memory (position, size etc. matters) and then based on that, OTUI code is generated.
              It's just crazy how that CPU usage is so high and I would like to fix this, even if that means dropping OpenGL.

              kshegunovK 1 Reply Last reply
              0
              • O Oen44

                Positioning and resizing is why. Each button, windows and all that stuff is saved in memory (position, size etc. matters) and then based on that, OTUI code is generated.
                It's just crazy how that CPU usage is so high and I would like to fix this, even if that means dropping OpenGL.

                kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by
                #6

                Why would you call update in paintGL to begin with?

                Read and abide by the Qt Code of Conduct

                O 1 Reply Last reply
                2
                • kshegunovK kshegunov

                  Why would you call update in paintGL to begin with?

                  O Offline
                  O Offline
                  Oen44
                  wrote on last edited by Oen44
                  #7

                  @kshegunov Where should I call it then? Tried paintEvent already but that didn't help. Even QTimer inside constructor or initializeGL didn't change anything, well, setting timer to 1000 helps but I need at least 30FPS.

                  kshegunovK 1 Reply Last reply
                  0
                  • O Oen44

                    @kshegunov Where should I call it then? Tried paintEvent already but that didn't help. Even QTimer inside constructor or initializeGL didn't change anything, well, setting timer to 1000 helps but I need at least 30FPS.

                    kshegunovK Offline
                    kshegunovK Offline
                    kshegunov
                    Moderators
                    wrote on last edited by kshegunov
                    #8

                    @Oen44 said in QOpenGLWidget, high CPU usage from update():

                    Where should I call it then?

                    Everywhere else, basically when something's changed. What you're doing now is flooding the event loop with paint requests - while you process one (in paintGL) you issue a new one.

                    but I need at least 30FPS.

                    Eh, why? Is this some kind of game?

                    Read and abide by the Qt Code of Conduct

                    O 1 Reply Last reply
                    0
                    • kshegunovK kshegunov

                      @Oen44 said in QOpenGLWidget, high CPU usage from update():

                      Where should I call it then?

                      Everywhere else, basically when something's changed. What you're doing now is flooding the event loop with paint requests - while you process one (in paintGL) you issue a new one.

                      but I need at least 30FPS.

                      Eh, why? Is this some kind of game?

                      O Offline
                      O Offline
                      Oen44
                      wrote on last edited by Oen44
                      #9

                      @kshegunov said in QOpenGLWidget, high CPU usage from update():

                      Eh, why? Is this some kind of game?

                      No, but there is dragging using mouse involved. Please check this video https://www.youtube.com/watch?v=CQBn6jFqhlI
                      Imagine using Photoshop with 1FPS.

                      1 Reply Last reply
                      0
                      • Christian EhrlicherC Offline
                        Christian EhrlicherC Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by
                        #10

                        Calling update() explicitly somewhere is not needed in a normal use case. Don't do it.

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        1 Reply Last reply
                        1
                        • O Offline
                          O Offline
                          Oen44
                          wrote on last edited by Oen44
                          #11

                          Even if I call update when mouse is pressed and moved (which doesn't create any stuttering), CPU usage still goes up. So it doesn't matter if I call it in paintGL or anywhere else. The only advantage is that when nothing is touched, there is only 3% usage.
                          I feel like I should drop that OpenGL widget and do something else to achieve same results as now.

                          Edit

                          So I just reused QTimer and it worked. 2-3% CPU usage, 60FPS.

                          QTimer *pTimer = new QTimer(this);
                          connect(pTimer, SIGNAL(timeout()), this, SLOT(update()));
                          pTimer->start(1000 / 60.0);
                          
                          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