You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Wednesday, March 13th 2013, 12:25pm

OpenGL rendering in separate thread, Qt 5.0.1

Hi,

I use Qt 5.0.1 and tried demo http://qt-project.org/doc/qt-4.8/demos-glhypnotizer.html. It doesn't work on 5.0.1 because glWidget->makeCurrent() function in GLPainter::start() leads to the assertion "Cannot make QOpenGLContext current in a different thread" and crash. I added string

context()->moveToThread(&glThread);

to GLWidget::startRendering() before calling connect and this almost fixed the demo - it works stable if only one MDI window is opened and almost always crashes if I try to create new window with new thread. Also it is complaining a lot in the application output like this:

QGLShader::link: "(45,20): warning X3206: implicit truncation of vector type
QWidget::repaint: It is dangerous to leave painters active on a widget outside of the PaintEvent
QBackingStore::flush() called with non-exposed window, behavior is undefined
QGLShader::link: "(45,20): warning X3206: implicit truncation of vector type
QWidget::repaint: It is dangerous to leave painters active on a widget outside of the PaintEvent


etc etc.

I wander is it possible to make it work stable? Was it supposed to be enough in Qt 5.0.1 just to move QGLWidget context to the rendering thread before running it?

I attached the demo with changes mentioned.
jaf_ua has attached the following file:
  • hypnotizer.zip (19.15 kB - 24 times downloaded - latest: Aug 20th 2017, 6:47pm)