So I went and did it. I added a secondary OpenGL context to my project so I can load scenes in a separate thread from main. It actually wasn't too big of a deal to implement what I have so far. Basically on initial load I pull the scene into the main thread, then any scene load after that is pushed off to a secondary thread with a separate OpenGL context (made current on the executing thread). Once the secondary thread has finished, I then swap the context used by the main thread with the context that was used on the secondary thread.
This allows a scene to remain responsive to a user while they are in game, while the next scene loads in the background. However, I've noticed that while the active scene does remain responsive, there is a rather severe intermittent stutter/jump.
This is what I'm currently attempting to track down a solution for if one exists and I had a question I was hoping someone more knowledgeable with opengl than myself might be able to answer.
Since this loading is happening in a separate thread, I would think that the main thread should continue to execute at the same rate without being affected by the processing in the secondary thread, however since that's not the case, the only thing I could think of that may be causing this would be if the secondary thread was locking some memory that the main thread was attempting to access for drawing, causing the main thread to have to wait.
After reviewing my code, I could not find any cases where I'm explicitly accessing the same memory values between threads, EXCEPT MAYBE the opengl calls as I'm not well versed with what's actually going on under the hood when these calls are made. For example, lets say my main thread which is working off it's context is calling ‘glDrawElements’ every tick, and my secondary thread is generating and loading new buffers in it's own context via ‘glGenVertexArrays’, ‘glBindVertexArray’, ‘glBufferData’, etc.
Would the fact that my secondary thread is loading data into a separate context from my main thread still have an effect on my main thread, potentially causing the issue described above? If not, does anyone have any other ideas as to what may be causing this?
Thanks! ?