OpenGL和线程 [英] OpenGL and threading

查看:122
本文介绍了OpenGL和线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

众所周知,OpenGL驱动程序通常不容许[多]线程. 但是,是否必须处理主线程(例如SDL) 调出GL上下文?如果产生一个线程,则从此开始 从那里调度OpenGL命令会安全吗?还是有 仅限于调出GL的主线程 上下文?

It's known that OpenGL drivers usually don't tolerate [multi]threading. However, does one have to deal with the main thread (of e.g. SDL) that brought up a GL context? If one spawns a thread and from then on only from there dispatches OpenGL commands will it be safe? Or does it have to be restricted to the main thread that brought up the GL context?

推荐答案

您需要在要使用的线程上使OpenGL上下文成为当前上下文,并且一次只能在一个线程上使一个上下文成为当前上下文.因此,如果您将其设置为当前状态,则可以从另一个线程创建一个上下文并使用它.

You need to make the OpenGL context current on the thread you want to use it, and a context can be made current only on one thread at a time. So creating a context and using it from another thread is fine if you make it current.

对于使用OpenGL的多个线程,您需要多个OpenGL上下文,每个线程一个.而且,您可以在OpenGL上下文之间共享资源.

For multiple threads using OpenGL, you need multiple OpenGL contexts, one for each thread. And you can share resources between OpenGL contexts.

这篇关于OpenGL和线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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