Dear SDL samurais! I have a noob question about threadsafety.
I’m using SDL2 only to put the final frame onto screen, using my own blitting routines and surface format, because SDL provided are too inefficient and missing important features, like textured triangle rendering. SDL is also a bit unstable, with newer version changing everything, so less dependency on SDL is always good. So I have the following code to upload the frame:
SDL_LockSurface(surface); memcpy(surface->pixels, framebuffer, w*h*4); SDL_UnlockSurface(surface); SDL_UpdateWindowSurface(window);
Now that memcpy takes a lot of time, which I can spend updating the game world for the next frame, if only it was running in it own thread, that would have given me several more FPS. Yet I’m unsure if functions like SDL_LockSurface, SDL_UnlockSurface and SDL_UpdateWindowSurface are thread safe or I should do all SDL calls in a single thread, taking requests from the rest of the code?
Note that I can’t use surface->pixels as a framebuffer itself, because my surface format has pixels embedded into the structure to eliminate indirection and make set_pixel several times faster. But maybe surface->pixels can be user allocated, so I could prefix them with my own surface header data? Then there will be no need to copy anything.
Thanks in advance!