Is it safe to make GL calls with multiple threads?
I was wondering if it was safe to make GL calls with multip开发者_开发问答le 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?
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.
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.
精彩评论