Hidden window in other thread


#1

In one of my previous projects (when I didn’t use SDL and did all the window-handling myself), I had two threads with their own OpenGL rendering context. Thread 1 was for rendering user interface and animations on screen, thread 2 was for rendering on a hidden window (calculating lots and lots of mathematical curves which could be done way more optimal on the GPU than the CPU).

The reason I did it in separate threads was because it was hard to predict how long all calculations would take (possibly lagging my animation and user interface) and it was just easier to use thread synchronization on calculations that were ready and not have to worry about my frame rate at the same time, having smooth animations all the time.

On the SDL wiki page about threads Thread Management, I read “NOTE: You should not expect to be able to create a window, render, or receive events on any thread other than the main one. For platform-specific exceptions or complicated options…”. What does this mean exactly? Does SDL use singleton data structures preventing it from creating extra windows or handling window messages, or does this statement only tell that you’re on your own in managing multiple SDL implementations on the threads?

In other words: is it possible to create multiple threads, each doing their own SDL_Init, SDL_CreateWindow, getting their own OpenGL context, handle events, … or isn’t this possible in the way SDL has been built (which would be understandable… what I ask is probably quite uncommon)?

I could just try it, but it might maybe work for a while on my machine but crash later in production environments.