如果我有两个opengl渲染线程,每个线程都有一种设置其上下文的模式,以固定的帧速率进行绘制。会比赛吗?
我担心会发生以下情况:
反过来,两个线程都使用第二个线程的上下文。
每当设置渲染上下文并进行绘制以确保操作不会干扰其他渲染线程时,是否应该使用锁?
最佳答案
只要每个线程都有自己的上下文,就可以安全地绘制两个线程。
仅当您要在线程之间共享单个上下文时,才必须确保该上下文一次仅在单个线程中是最新的。wglMakeCurrent()
的documentation设置规则:
A thread can have one current rendering context. A process can have multiple rendering contexts by means of multithreading.
A thread must set a current rendering context before calling any OpenGL functions. Otherwise, all OpenGL calls are ignored.
A rendering context can be current to only one thread at a time. You cannot make a rendering context current to multiple threads.
An application can perform multithread drawing by making different rendering contexts current to different threads, supplying each thread with its own rendering context and device context.
关于multithreading - wglMakeCurrent,绘图和多线程会引起比赛吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47983823/