QThread's and OpenGL

Is it real to write threaded opengl app, which uses basic initialization (QGLWidget::initializeGL()) and painting (QGLWidget::paintGL()), but threaded drawing with glDrawPixels() ??

Not quite sure what you’re asking, but you can use GL from a separate thread if you’re careful.

I found this thread useful: http://www.gamedev.net/community/forums/topic.asp?topic_id=260982

I’d be very cautious of QGLWidget.

I got multithreaded rendering working today with a bit of hackery in my QGLWidget subclass – working, that is, on Windows and Linux. On Mac OS X the computer crashed hard :stuck_out_tongue: – probably something I was doing was more than a little dodgy :slight_smile:

Writing a simple QGLWidget replacement seems pretty easy. QGLWidget does a bunch of stuff you don’t really care about most of the time… I have the most basic of basic ones working on X11 now. Mac OS X is first up tomorrow.

OneSadCookie: Please, send me your example at squirrel-sf at yandex.ru.

Basically I just used the code in the GameDev.net thread I linked above, in a QWidget subclass. Not sure how robust it is without a bit more testing, and I have to jump through some hoops to get things like resize messages through to the thread. You’re probably better off doing this yourself…

In other interesting news, I implemented the Mac OS X and Win32 versions of said QWidget subclass. The three systems are somewhat differently powered, but here are the performance numbers I gathered today. This is the FPS per-thread, two-thread test, each thread drawing a single triangle, half of a 1280x1024 screen:

Linux (Dell Precision 360, GeForce 6800 Ultra): 380
Mac OS X (Dual 2GHz G5, Radeon 9600): 450
Win32 (Dell Precision 360, GeForce 5900): 580

Just one thing - I need not two threads rendering two separate windows, I need two threads rendering the same window, but only one thread a time. I’ll look at example at gamedev.net, but I don’t hope that it is suitable for me :frowning:

You probably don’t want to get into trying to make GL calls to the same context from two different threads simultaneously…

If you do, you can only do it with a mutex, ensuring the two threads can never make GL calls at the same time as each other.

No, not ‘simultaneously’. I mean Main thread creates QGLWidget, drawes something on it, then creates QThread’s instance and this instance should draw something by itself, then exit. Main thread continues drawing …

You mean that two threads renders in the same buffer ?!

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.