0

I have id like a variable of a opengl texture identificator. I generate it with glGenTextures (1, &id) and it works fine. The problem is when i call glGenTextures function in a different thread. It always return 0 and not generate texture. I think it is because the opengl context is different.

I use SDL for load the image and then pass it to the texture with glTexImage2D. I'm trying to create a new SDL_GLContext in the thread to share it with the main thread, but i don't how to make it. I can modify id inside the thread with id=2 for example, and read and print it, but i can't modify with glGenTextures and i can't generate the texture that i need.

4

1 回答 1

3

OpenGL 上下文一次只能在一个线程中处于活动状态。您不能在多个线程中绑定单个 OpenGL 上下文。但是,可以创建第二个 OpenGL 上下文,共享 OpenGL 资源命名空间并将其绑定到另一个线程中。或者您使用像素缓冲区对象 (PBO) 将一些 OpenGL 内存映射到进程地址空间,并从另一个线程填充它。

于 2013-09-04T16:33:31.347 回答