views:

118

answers:

2

I was wondering if it was safe to make GL calls with multiple threads. Basically I'm using a GLUtesselator and was wondering if I could divide the objects to draw into 4 and assign a thread to each one.

I'm just wondering if this would cause trouble since the tesselator uses callback functions. Can 2 threads run the same callback at the same time as long as that callback does not access ant global variables?

Are there also other ways I could optimize OpenGL drawing using multithreading?

Thanks

+1  A: 

The answer to "Can 2 threads run the same callback at the same time as long as that callback does not access ant global variables?" is a clear YES.

However, you will get problems when you modify the state of OpenGL in your callback functions, especially when using glBegin / glEnd (eg if you generate a DisplayList). As long as you don't use the GPU (eg if you use a mesh), you can do tesselation with multithreading.

If you want to optimize your drawing, you may want to use the geometry shader for tesselation instead. This requires Shader Model 4.

flyx
Shader Model 4 is DirectX specific: http://www.opengl.org/wiki/Detecting_the_Shader_Model. Did you mean GLSL 1.3?
Xavier Ho
Okay, the correct term is "Unified Shader Model", which is called Shader Model 4 in DX. This is what the graphics card has to support. The OpenGL geometry shader came with OpenGL 3.2, GLSL 1.50, but you can also use it as extention in OpenGL 2.0.
flyx
+1  A: 

Reading between the lines in your question, the answer is no. You can't make calls to the same GL context from different threads concurrently. You can find more details in the Parallel OpenGL FAQ.

eile