对于具有不同上下文的多个线程,OpenGL线程是否安全? [英] Is OpenGL threadsafe for multiple threads with distinct contexts?

查看:225
本文介绍了对于具有不同上下文的多个线程,OpenGL线程是否安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在线程之间共享单个上下文是坏消息。我知道当主线程上的GL没有发生任何事情时,我可以在辅助线程上安全地创建和使用带有屏幕外帧缓冲的上下文。

I know that sharing a single context between threads is bad news. I know that I can safely create and use a context with an offscreen framebuffer on a secondary thread when nothing is happening with GL on the main thread.

我还没有能够找到一个明确的答案,我可以安全地在两个不同的线程上创建两个上下文(例如,绘制到屏幕的主线程,以及执行屏幕外绘制工作的辅助线程)并让它们都进行GL函数调用同时。

I haven't yet been able to find a definitive answer to the question of whether I can safely create two contexts on two different threads (say, a main thread drawing to the screen, and a secondary thread doing offscreen drawing work) and have them both making GL function calls simultaneously.

换句话说,只要上下文不同,两个线程可以共享C API,从而共享GPU吗?或者这本身就是不可分享的东西?或者这是特定于实现的?

In other words, as long as the contexts are different, can two threads "share" the C API and thus the GPU? Or is that inherently something that is unshareable? Or is this implementation-specific?

在iOS上专门询问OpenGL ES,但这可能是一般性问题。

Asking specifically for OpenGL ES on iOS, but it's probably a general GL question.

推荐答案

是的,您需要为要使用OpenGL的每个线程使用一个上下文,也可以在上下文之间共享对象。这是要走的路:):

Yes, you need to use one context for each thread you want to use OpenGL with, also you can share objects between the contexts. This is the way to go :)

这篇关于对于具有不同上下文的多个线程,OpenGL线程是否安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆