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. Howto sync "openglwindow" example to the the refresh of my monitor on Windows 7?
QtWS25 Last Chance

Howto sync "openglwindow" example to the the refresh of my monitor on Windows 7?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 193 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.
  • C Offline
    C Offline
    cdwijs
    wrote on last edited by
    #1

    Hi All,

    I would like to write a program that animates rectangles. Therefore I'm looking for a way to let the GPU do the rendering, so the animation will be smooth.

    I've run the "openglwindow" example. [1] This looks ok, until I check with a timer how much time passes between calls to TriangleWindow::render(). I have a 60Hz monitor, so I was expecting about 16msec. Instead I see the following times between frames:

    19 19 19 19 47 31 19 19 19 19 19 15 23 10 19 8 18 20 12 15 16 23 9 20 8 18 16 23 9 20 8 18 16 23 9 20 8 19 15 23 9 20 19 9 8 22 16 15 23 9 20 19 8 15 23 9 20 19 8 16 22 9 20 28 19 19 19
    

    In the main function of the example .setAnimating is set to true, so I assumed the example should sync to vblank:

    int main(int argc, char **argv)
    {
        QGuiApplication app(argc, argv);
    
        QSurfaceFormat format;
        format.setSamples(16);
    
        TriangleWindow window;
        window.setFormat(format);
        window.resize(640, 480);
        window.show();
    
        window.setAnimating(true);
    
        return app.exec();
    }
    

    Here's the code I've added to the example to measure these times:

    class TriangleWindow : public OpenGLWindow
    {
    public:
        TriangleWindow();
    
        void initialize() override;
        void render() override;
    
    private:
    <snip>
        QElapsedTimer timer;
    };
    
    void TriangleWindow::render()
    {
        qDebug()<<timer.elapsed();
        timer.start();
        const qreal retinaScale = devicePixelRatio();
        glViewport(0, 0, width() * retinaScale, height() * retinaScale);
    <snip>
        glDrawArrays(GL_TRIANGLES, 0, 3);
    
        glDisableVertexAttribArray(1);
        glDisableVertexAttribArray(0);
    
        m_program->release();
        ++m_frame;
    
    }
    

    I've looked at AMD Radeon settings"->Gaming->Global Settings->global Graphics->Wait for Vertical Refresh, this is set to "always on".

    My system:
    Qt 5.11.1 mingw53_32
    Amd Radeon RX550 Series
    Windows 7 enterprise SP1
    Core i7-3770, 8GB ram

    How can I debug this further?

    Cheers,
    Cedric

    [1] https://doc.qt.io/qt-5/qtgui-openglwindow-example.html

    1 Reply Last reply
    0
    • C Offline
      C Offline
      cdwijs
      wrote on last edited by
      #2

      I have 3 monitors connected, one of the monitor was set to 100Hz with freesync, the other 2 were set to 60Hz. The test was on one of the 60Hz displays.

      Now I've disabled freesync, and set all three monitors to 60Hz. The example now runs almost perfectly on 640x480:

      16 22 13 72 36 20 16 16 16 15 16 15 16 16 16 15 16 16 15 16 16 15 16 16 15 16 16 16 15 15 16 16 16 16 15 16 16 15 16 27 21 15 15 16 16 16 15 16 16 16 16 15 16 16 15 16 16 15 15 18 15 15 16 16 16 16 15 16 16 15 16 16 17 15 15 16 16 16 16 15 16 16 15 16 16 16 16 16 15 16 16 15 16 16 15 16 16 15 16 16 15 16 16 15 16 16 15 16 16 15 16 16 15 16 16 15 16 16 14 18 15 16 16 16 15 16 16 15 16 16 16 16 16 15 16 16 16 15 16 16 15 16 15 16 16 16 15 16 16 15 16 16 15 16 16 15 16 16 15 16 16 15 17 16 15 16 16 15 16 16 15 16 29 18 33 17 15 16 16 16 15 16 16 16 15 16 16 15 16 16 14 16 16 16 16 16 15 16 16 15 16 17 15 16 16 15 16 16 15 16 17 14 16 16 16 16 16 15 16 16 15 16 16 15 16 15 17 15 16 16 15 15 17 15 16 16 15 16 16 15 16 16 15 16 16 15 16 16 15 16 16 15 16 16 15 16 16 15 16 16 15 16 16 15 16 16 15 15 17 15 15 19 14 15 16 15 16 16 16 15 16 16 15 16 16 15 17 16 15 16 16 16 16 16 15 16 16 15 16 16 15 17 16 15 16 16 15 16 16 15 16 16 15 16 16 16 15 16 16 15 16 16 15 16 15 16 16 16 15 16 16 15 17 15
      

      When I maximize the window, it runs on about 3440x1440, then I measure more studder:
      "
      21 16 16 17 16 15 15 16 16 15 16 16 15 16 17 15 16 16 15 16 16 15 16 16 15 16 16 15 16 16 16 16 16 16 16 15 16 15 16 16 15 16 15 16 16 15 16 16 16 15 16 16 15 16 16 15 16 16 15 16 16 16 16 14 16 16 15 16 15 16 16 15 16 16 16 16 15 17 16 15 16 16 15 16 16 15 332 38 51 14 20 11 20 12 24 26 17 16 15 21 26 13 20 12 24 26 17 16 15 21 18 24 13 20 12 19 16 15 16 16 21 25 14 15 16 16 19 16 15 16 16 12 15 16 16 15 16 16 19 16 16 15 16 21 25 14 15 15 16 31 22 15 32 18 15 16 15 16 21 25 15 14 16 15 19 17 16 16 15 21 25 14 20 12 23 18 24 18 15 22 24 15 19 12 24 25 19 21 24 18 16 16 15 16 21 25 14 15 15 16 31 22 15 30 20 20 24 18 21 25 14 20 21 24 18 16 15 16 21 25 15 14 16 15 21 21 24 18 16 16 16 21 24 23 25 14 20 12 24 25 18 17 21 24 15 19 12 20 21 24 19 21 24 18 16 21 24 24 24 32 15 24 25 19 21 24 19 21 24 20 36 24 16 19 12 20 21 24 18 16 21 24 19 21 24 18 16 21 24 19 21 24 19 20 24 15 20 21 24 19 22 24 18 21 24 24 32 24 19 16 21 23 21 32 27 21 27 21 20 24 19 21 24 19 20 25 19 20 24 16 19 20 29 19 25 19 20 24 19 29 21 19 24 19 22 24 19 20 24 20 37 24 15 20 20 24 96
      "
      The example is showing 0% cpu in the windows task manager. Could it be I maxed out the GPU? How can I measure that?

      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