0

I'm building a module that is supposed to display images at a certain rate (not pre defined, but not very high - 10Hz max for the swapping of images).

From my research I got to the conclusion that QGLWidget is the right tool for this task, after enabling vsync with openGL calls(SwapInterval family).

Yet, I am not sure how to actually implement the swapping mechanisem - should I use a timer? If I set a timer for 333.3 ms(3 Hz), when the refresh rate is 60 Hz (16.67 per cycle, thus the timer is 20 cycles), and I be sure that timing will be fine? And if the rate should be 9Hz, I need to set the timer for 100+16.67 because this is the best I can get? And if a timer is ok, should I just call paintGL() when it sends me the timeout event?

Thanks

4

1 回答 1

1

我应该使用计时器吗?

是的,但不是天真的方式。如果您只是使用计时器来精确定位图像的呈现,您的计时器频率将显示垂直同步/刷新振荡器相比——程序计时器从与显示输出不同的时钟源运行。

这种跳动将导致错过交换间隔,这将被视为帧卡顿。

相反,您应该执行以下操作:使用垂直同步缓冲区交换 (SwapBuffers¹) 作为参考点来启动高精度时间测量计时器。

然后为您的目标未来的下一个演示时间渲染框架;考虑到帧间隔以显示刷新间隔粒度出现——除非使用 G-Sync 或 FreeSync。用于glFinish强制完成帧渲染过程,然后停止计时器并确定渲染帧所用的时间。如果帧在刷新周期之前完成,您确实希望添加一个(高分辨率延迟),将您的程序延迟到目标显示周期(瞄准周期中间),然后SwapBuffers是参考点为下一次迭代。


¹:这仅适用于 Nvidia 和 AMD 卡及其专有驱动程序。英特尔 GPU 的驱动程序具有不同的时序行为。

于 2017-02-02T14:46:50.410 回答