Results 1 to 8 of 8

Thread: how to handle a multi-thread OpenGL program

  1. #1
    Guest

    how to handle a multi-thread OpenGL program

    my function like this:

    void xxx(void)
    {
    glBegin(xxx);
    glVertex(yyy);
    ...
    glEnd();
    }

    I called it in several threads and let them execute consequently. I have several other data-processing threads without any display functions. But I get a "segmentation error"
    when the first thread runn xxx, right after
    glBegin().

    Anyone here knows where my problem is?
    Thanks.

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Feb 2000
    Posts
    569

    Re: how to handle a multi-thread OpenGL program

    might not be it. But when you using drawing functions in a thread, the RC to wich you draw have to be create in that thread.

  3. #3
    Guest

    Re: how to handle a multi-thread OpenGL program

    all my threads want to draw in the same window. does it mean I cannot use a multi-thread program here? Or is there any way to get out of it.
    Thanks.

  4. #4
    Senior Member Regular Contributor
    Join Date
    Feb 2000
    Location
    milano, italy
    Posts
    282

    Re: how to handle a multi-thread OpenGL program

    segmentation fault is not due to opengl RC, because when you try to change some states, opengl checks if the RC (wich pratically IS opengl) is assigned to the calling thread.

    if it's not, opengl discard changes.
    it's just like if you don't call opengl function at all.

    so, into a multithreaded application, every thread must have exclusive access to opengl, and since you have only one RC (normally) you have to manually assign it to the thread functions.

    the function to handle thread assignement of RC under win32 is wglMakeCurrent().

    note that when a tread owns a RC, it must be released by the same thread before it can be used by other threads.

    Dolo/\/\ightY

    PS: well, the way opengl behaves when a thread don't own the RC is a spec issue, but sometime specs are not followed correctly...
    i can tell for sure that with MS generic and matrox g200 drivers it works this way.
    other cards... don't know


    [This message has been edited by dmy (edited 04-21-2000).]
    Dolo/\/\ightY

  5. #5
    Member Contributor
    Join Date
    Feb 2000
    Location
    Breda, Netherlands
    Posts
    57

    Re: how to handle a multi-thread OpenGL program

    Isn't OpenGL getting confused too from having glBegin() calls from other threads simultaniously?
    I mean, thread 1 calls glBegin(), some vertices (but not all) thread 2 gets the cpu, calls glBegin(), sends some vertices, thread 1 gets the cpu, finishes but the glBegin() was changed so OpenGL won't know the vertices apart and screws up?

    John

  6. #6
    Junior Member Newbie
    Join Date
    Apr 2000
    Location
    New Jersey, USA
    Posts
    23

    Re: how to handle a multi-thread OpenGL program

    It feels like a waste of time doing sync between threads that all want to render to OpenGL. It would be better (I believe) to have a dedicated rendering thread and other threads are just producing geometry data, culling and whatever.

    OpenGL is a single pipeline - why use threads to render to it when it must be serialized anyway. It makes a point to do animation, application, culling and other stuff in other threads on a multi-CPU system. But not rendering, unless you render to separate displays.

    / Patric

  7. #7
    Senior Member Regular Contributor
    Join Date
    Feb 2000
    Location
    milano, italy
    Posts
    282

    Re: how to handle a multi-thread OpenGL program

    sjohnny:
    as like some gl commands are not accepted after a glBegin(), i believe that opengl don't let the application change the RC assignement.
    oh well, this is the way i would design it

    plg:
    i agree. it's a wate of processor time and developing time.
    but not only rendering commands are not accepted in a Not-Owning-RC-Thread: every gl command is discarded!
    into a NORCT you can't do:
    -rendering
    -creation of display lists
    -initialize textures
    -set states
    -upload/download buffers
    -simply anything!

    Dolo/\/\ightY
    Dolo/\/\ightY

  8. #8
    Senior Member Frequent Contributor
    Join Date
    Apr 2000
    Location
    Melbourne,Victoria,Australia
    Posts
    748

    Re: how to handle a multi-thread OpenGL program

    Multithreading in OpenGL is more to do with either multiple outputs or segmentation of the physics calculations etc. In the first case you may have multiple windows with different RC's each handled by a single thread (Eg. CAD program...).

    In the second your additional threads would perform AI and physics calcs simultaneously with another thread (the controlling one?) performing the rendering. This way you get the most out of the Rendering without the AI interfering with the speed (assuming the AI etc. ends up on another processor). The trick, as with all Multithreaded program. Is designing it write.

    As an idea - however - what if you write to different buffers with each thread, and then a third thread combines the results? (If thats at all possible...)

Similar Threads

  1. How to handle multi-GPU with multi-monitors
    By Aasimon in forum Vulkan
    Replies: 4
    Last Post: 11-19-2018, 06:42 AM
  2. multi head/multi window simple program
    By advorak in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 06-13-2015, 07:56 PM
  3. multi thread in opengl
    By jayaprakash in forum OpenGL: Linux
    Replies: 0
    Last Post: 01-29-2009, 03:32 AM
  4. Multi-thread application about OpenGL
    By stanlylee in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 06-06-2005, 12:46 PM
  5. How can I use OpenGL in multi-thread program?
    By lglabc in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 09-24-2003, 04:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean