Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Using Multi-Threaded Drawing

  1. #1
    Junior Member Newbie
    Join Date
    May 2014
    Posts
    9

    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,

  2. #2
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,290
    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.

  3. #3
    Junior Member Newbie
    Join Date
    May 2014
    Posts
    9
    Hi,

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

  4. #4
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,290
    Oh, so you're using a GL1.4 feature-set then, without any VBOs.
    http://www.opengl.org/sdk/docs/man2/...lMapBuffer.xml
    You need to get a http://www.opengl.org/wiki/OpenGL_Loading_Library
    And find some tutorials on using VBOs.

  5. #5
    Junior Member Newbie
    Join Date
    May 2014
    Posts
    9
    Thanks! Problem Solved!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •