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 2 of 2

Thread: multithread; how to tell opengl-thread to redraw

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2003
    Posts
    1

    multithread; how to tell opengl-thread to redraw

    Hi,

    I'm fairly new at opengl and multithreading. That said I have the following problem:

    I'm writing a numerical-analysis program which does a lot of computation. Therefor I want to use two threads, an opengl thread and a numerical thread.

    How can I sensibly notify the GL-thread that computations have led to new data to be drawn. I can't use something like glutPostRedisplay() directly; the GL-thread doesn't react to that. I don't want the GL-thread to constantly check for a condition-flag in its idle function, thereby consuming lots of CPU-time.

    Is the only sensible way to for GL's idle-func to check for a condition-flag and sleep for some micro-seconds if condition is not met (which is the best suggestion I've found sofar)????

    Thanks, Ludo

  2. #2
    Advanced Member Frequent Contributor marcus256's Avatar
    Join Date
    Aug 2001
    Location
    Sweden
    Posts
    853

    Re: multithread; how to tell opengl-thread to redraw

    That depends on what threading environemnt you are using. If you use POSIX threads (or similar), then condition variables are exactly what you are looking for (in combination with a mutex). You can let a thread wait for the condition variable (read: sleep), and another thread signal the condition variable to wake up the waiting thread(s). Then have a flag/counter to indicate if new rendering is needed, and protect this flag with a mutex or critical section so that both threads can safely access it.

    If you do not have condition variables, you should be able to do something similar with signals or events.

Posting Permissions

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