How can I do fast animation without dropping frames?



  • I have an application that generates a stream of mathematically created scenes. As soon as each scene is created I want to render it.

    As normal, the actual rendering is done in a subclass of QWidget by overriding the paintEvent() method.

    The scenes are created in a separate thread. As soon as a new scene is created I call update() on the QWidget subclass. I have to call update() rather than repaint() because the latter can't be called from a different thread. Unfortunately update() can be called multiple times before a scene is rendered, hence the reason I'm losing scenes or getting only partial updates.

    I've tried syncing the scene creation thread with the renderer by waiting in the scene creation thread until QWidget::paintingActive() returns false. However this makes no difference.

    Further investigation suggests that QWidget::paintEvent() can execute multiple times without the screen being updated.

    Any ideas will be most welcome!

    (I'm developing on a laptop running Windows 7)



  • I think I've solved my own problem. I used a QMutex object to ensure that a new scene couldn't be created whilst the old scene was being rendered and vice versa.

    However I'm not sure why waiting on paintingActive() didn't have the same effect.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.