multithreading - wglMakeCurrent,绘图和多线程会引起比赛吗?

标签 multithreading winapi opengl

如果我有两个opengl渲染线程,每个线程都有一种设置其上下文的模式,以固定的帧速率进行绘制。会比赛吗?

我担心会发生以下情况:

  • 线程1调用wglMakeCurrent
  • 线程2调用wglMakeCurrent
  • 线程2绘制
  • 线程1绘制

  • 反过来,两个线程都使用第二个线程的上下文。

    每当设置渲染上下文并进行绘制以确保操作不会干扰其他渲染线程时,是否应该使用锁?

    最佳答案

    只要每个线程都有自己的上下文,就可以安全地绘制两个线程。
    仅当您要在线程之间共享单个上下文时,才必须确保该上下文一次仅在单个线程中是最新的。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/

    相关文章:

    c# - 具有单个上下文的 OpenTK 多个 GLControl

    c++ - EncryptFile 函数是如何工作的,为什么我仍然可以保存内容?

    在控制台中看不到 Windows 程序的标准输出(在 Windows 上用 Clang 编译)

    c - 从我们按下键盘上的一个键到它出现在你的word文档中会发生什么

    c++ - OpenGL 相机 - 来自四元数的 View 矩阵行为不正确且间距太小

    android - 创建的 Smack Cache Executor 线程过多

    c# - 在线程内 sleep 的替代方法

    java - 单核处理器还能抛出ConcurrentModificationException吗?

    java - Wicket 和多线程业务对象

    c++ - 将一个 int 传递给一个函数,然后使用该 int 创建一个数组