Share VBOs between contexts

Started by filocava99, April 09, 2021, 14:41:11

Previous topic - Next topic


Hi. I'm trying to buffer data from a context and rendering them from another. The problem is that I get an access violation exception when I try to buffer the data from the second context.
The main context is the one that renders the VAOs, the second one only calls glBufferData to load vertices, normals and uvs and then the main context bind them to a VAO.
I created the second context the same way I created the first one, except that I don't show the window.
Here's my window class that also create the context:
I know it's in Kotlin but it is easily understandable.
From  what I've learned only VBOs are shared between context, that's why I'm binding them to the VAO in main context.
The main context can call glBufferData without any exception, so I think the issue is in the second context creation.
What do you think?
Before you ask, I have to use a second context because the glBufferData calls make the game freeze for too many milliseconds (i'm loading tiles of terrain procedurally generated while the player moves)


The solution is to use the sharing parameter of the GLFW's glfwCreateWindow function. You must call such method from the main thread, otherwise glfw will fail to create an opengl context.
I figured it out thanks to a stackoverflow user