Sign in to follow this  
tejaswini

threading

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this