开发者

call OpenGL functions from another thread

开发者 https://www.devze.com 2022-12-18 12:31 出处:网络
My application has two threads: A and B. The A is the main thread and B is my video thread. The video thread has an initialized OpenGL context where开发者_StackOverflow OpenGL functions work properly.

My application has two threads: A and B. The A is the main thread and B is my video thread. The video thread has an initialized OpenGL context where开发者_StackOverflow OpenGL functions work properly. However, when I call OpenGL functions from thread A, the function failed with a 1282 error (GL_INVALID_OPERATION) Is it possible to call OpenGL functions from my main thread (A) ?


  1. Unless you are doing actual background rendering of slow content, this is probably not going to give you a performance delta.

  2. On Windows, open gl contexts are per thread. Ensure that you call wglMakeCurrent from your worker thread before attempting to call open gl functions.

  3. Open GL is not thread safe. If you attempt to make the same context current on multiple threads, it won't stop you. It will just explode.


GL is not Thread Safe, and therefore you can not call GL functions from 2 different threads. You will have to protect each gl part with mutexes, which kills any performance boost you would have expect plus overhead of mutex locking and probably required context switching.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号