Using Multi-Threaded Drawing

Hi,

I am attempting to create a game like “Powder Toy” and since it handles a lot of particles and drawing I’m trying to that and a single thread cannot handle it after 2000 particles it becomes incredibly slow and that in mind I want to create a multi-threaded drawing threads each doing its own thing. That in mind I used CreateThread() and gave it its parameters but somehow it crashes and does not draw.

I only first tried to create an single thread which still failed, but how do these large simulation which have thousands of particles (10,000+) actually process on normal PCs I’m extremely baffled by this. Is there a way of doing this if so how.

Regards,

When you MakeCurrent(), you bind the GL context to THAT thread. Calling from another thread should return an error or maybe crash things.
What you should do is:
1)glMapBuffer(…,GL_WRITE_ONLY) one or several buffers in your main thread ( they’ll all remain mapped);
2) fill the buffers in the secondary threads;
3) signal a mutex or something from the secondary threads, that you finished uploading data
4) in the main thread, you’ll be drawing unrelated stuff that doesn’t depend on those buffers
5) in the main thread, wait for all secondary threads to finish writing the buffers; glUnmapBuffer() for all those buffers; start drawing with the buffers.

Hi,

Thanks but I cannot find glMapBuffer() whats it header file? Or do I install and set something else up?

Oh, so you’re using a GL1.4 feature-set then, without any VBOs.
http://www.opengl.org/sdk/docs/man2/xhtml/glMapBuffer.xml
You need to get a http://www.opengl.org/wiki/OpenGL_Loading_Library
And find some tutorials on using VBOs.

Thanks! Problem Solved!