While trying to learn SDL2, I read about double buffering. I know that SDL uses double buffering on its own. However, I am confused about how double buffering could be implemented in software rendering.
First, you have to create a window:
SDL_Window *window = SDL_CreateWindow("SDL2 Window",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
680, 480,
0);
Then you get a pointer to the window's surface ONCE:
SDL_Surface *window_surface = SDL_GetWindowSurface(window);
You can now use this pointer to blit something to the surface and display it by updating the window's surface:
SDL_BlitSurface(image, NULL, window_surface, NULL);
SDL_UpdateWindowSurface(window);
I know that UpdateWindowSurface() is equivalent to SDL1.2's Flip(). This implies that the buffer swap is performed here. Theoretically, the buffer that was the window's back buffer (the one pointed to by window_surface) should now be the front buffer, and you should need another pointer to the old front buffer, which now is the new back buffer - at least in my mind. But you don't. You can blit and update like above again to display a possibly changed frame. How is that possible?
Here (Where can I find the definition of 'SDL_Window') you can see that the struct SDL_Window also has only ONE member SDL_Surface* surface
. There is no "back surface" and "front surface". A surface neither has two buffers that could act as front and back buffer. So how does double buffering work here? Is UpdateWindowSurface() not a flip anymore? Is the WindowSurface just copied to a buffer in graphics output by the graphics card that implements double buffering? What am I missing? I'd appreciate any help a lot!