I've found a nice tutorial on multithreaded OpenGL rendering on QGLWidget:
http://doc.trolltech.com/qq/qq06-gli...glapplications
But I have some questions about it:
1.
class GLThread : public QThread
To copy to clipboard, switch view to plain text mode
Is it safe to modify GLThread's members:
bool doRendering;
bool doResize;
int w;
...
bool doRendering;
bool doResize;
int w;
...
To copy to clipboard, switch view to plain text mode
when GLThread thread is running and reads each variable every iteration?
I'm talking about
{ /*glt is GLThread's object*/
glt.resizeViewport(evt->size());
}
void GLWidget::resizeEvent(QResizeEvent *evt)
{ /*glt is GLThread's object*/
glt.resizeViewport(evt->size());
}
To copy to clipboard, switch view to plain text mode
2. Is it safe to modify more complex GLThread's members when GLThread thread is running? E.g.
class MyComplexGLThreadMemberClass {
int a;
double b;
vector<int> c;
};
class MyComplexGLThreadMemberClass {
int a;
double b;
vector<int> c;
};
To copy to clipboard, switch view to plain text mode
3.
class GLWidget : public QGLWidget
To copy to clipboard, switch view to plain text mode
Is it safe to call GLWidget's methods from a running GLThread thread?
void GLThread::run()
{
glw->makeCurrent();
while (doRendering) {
// Rendering code goes here
glw->swapBuffers();
}
}
void GLThread::run()
{
glw->makeCurrent();
while (doRendering) {
// Rendering code goes here
glw->swapBuffers();
}
}
To copy to clipboard, switch view to plain text mode
Here is my source code for Qt4.7 and exe file built with Qt4.7, you'll need Qt dlls to run it.
TestGl.zip
TestGl_exe.zip
Bookmarks