threading

Started by
3 comments, last by karx11erx 16 years, 6 months ago
Hi all, In a window (or overlay windows), Iam drawing a square and a circle. Now I want to have multiple threads in the application. In one thread, I want to draw a square and in another thread I want to draw a circle. How can I implement this, so that I get desired output. Any piece of guidelines or sample program or code skeleton regarding this, is highly appreciated. Thanks in advance. --tej
Advertisement
Hi,

Could you specify what are you trying to accomplish with this idea ? Also, giving some details about the platform / graphics API would help.

Generally answering, I speculate that you are after some extra performance on multi-core CPUs + software rendering, this isn't the way to go.

If it is about some graphics API, like GDI, OpenGL, D3D etc I'd say that this is a definete no no.

[edit]

Sorry, I noticed that this is under OpenGL thread. I am not too familiar with it, but I strongly suspect that giving commands to OpenGL from multiple threads would give anything else than headache. Correct me if I am wrong.
i really get sick and tired of saying this but google is your friend!!

http://support.microsoft.com/kb/q128122/

*edit*

although this demo uses multiple context's. I can't see you gaining any advantage using mutiple threads with the one context(as stated above it's a headache), which is more than likely what u r after. You would be far better off using say one thread for rendering activities and another thread for say physics , sound etc
That's correct. It's doesn't give you more speed firing GL commands from different threads, but it is possible.
Just make the GL context current for each thread before making GL calls.
You also need to syncronize things and that's where you lose lots of performance.
What I mean is that you have to make sure that you make the calls to draw the circle in the secondary thread, then go back to thread 0, SwapBuffers.

It's better to make threads in which you run your physics engine, another for AI, another for some more AI, another for some intersection testing, culling, etc.
Do your GL calls from a single thread, probably the main one.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
The bottleneck with multi threading are shared resources. In the case of gfx rendering, that would be the render buffers. Imo multi threading therefore doesn't make sense with render calls. It makes sense with setting up stuff to be rendered if the data is completely independent. You could compute the vertex and color data for circle and square concurrently in two different threads, and then sequentially render them.

In your case that wouldn't speed up things noteably, but if you are having a lot of complex objects to be rendered with complex setup procedures you could speed up things pretty much.
_________karx11erxVisit my Descent site or see my case mod.

This topic is closed to new replies.

Advertisement