0
votes

I want to create few threads to load objects with textures, but it doesn't work. I've read that I should create new OpenGL context in each thread, but when I do it, program crashes on it. Is other way to do it?

I use freeGLUT. These are functions i want to use in threads:

glGenBuffers()
glBindBuffer()
glBufferData()
glGenTextures()
glBindTexture()     
glTexImage2D()
glGenerateMipmap()
glTexParameteri()
glTexEnvi()
1

1 Answers

3
votes

None of those you can call in a different thread. Not unless you create another connected openGL context in the other thread but that is not simple.

What is simpler is creating the object in memory in another thread and then having the main thread dump it in the VBO. after the loading thread signals it has done.

Another option is first creating and allocating the buffer in the main thread and using glMapBuffer to get a pointer you can write to (even from another thread) and letting the loading thread store its data in there and signal back when it's done after which the main thread can unmap it.