Call OpenGL functions from another thread

My application has two streams: A and B. A is the main stream, and B is my video stream. The video stream has an initialized OpenGL context where the OpenGL functions work correctly. However, when I call OpenGL functions from thread A, the function failed with error 1282 (GL_INVALID_OPERATION) Can I call OpenGL functions from my main thread (A)?

+4
source share
2 answers
  • Unless you are doing the actual background rendering of slow content, this probably won't give you a performance delta.

  • On Windows, open gl contexts for each thread. Make sure you call wglMakeCurrent from the workflow before trying to call public gl functions.

  • Open GL is not thread safe. If you try to make the same context relevant for multiple threads, this will not stop you. It just explodes.

+10
source

GL is not thread safe, so you cannot call GL functions from two different threads. You will have to protect every part of gl with mutexes, which leads to the increase in performance you expect, plus the overhead of locking the mutex and possibly the necessary context switching.

+3
source

Source: https://habr.com/ru/post/1299949/


All Articles