OpenGL and OpenMP

Hello, has anyone tried to run other jobs in parallel to rendering?

#pragma omp parallel sections
{
   #pragma omp section
   {
     OpenGL rendering
   }
   #pragma omp section
   {
     unrelated CPU number crunching
   }
}

I tried it with GF8 and VC+2005 and OpenGL code gets broken on many different places…e.g. uniform location is sometimes not found, although the same location in the same shader was found in previous frame.

no idea, but what i do know is that an opengl context can only be current to one thread at a time. So if OpenMP is forking multiple threads to execute the opengl functions you’re in trouble.

“omp section” and gl rendering in it is always executed only by one thread, but thread is selected randomly from pool. It works when rendering is assigned to master thread, thanks for help!

but thread is selected randomly from pool.
This means, you have to make the OpenGL rendering context current in that thread before issuing any GL commands.

Also you have to consider that if you want to render in the same scene, all the OpenGL states must be encapsulated in Mutexs.