Professional Documents
Culture Documents
C - How Is Double Buffering Implemented in SDL2 - Stack Overflow
C - How Is Double Buffering Implemented in SDL2 - Stack Overflow
C - How Is Double Buffering Implemented in SDL2 - Stack Overflow
Asked 2 years, 11 months ago Modified 2 years, 11 months ago Viewed 493 times
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.
0
First, you have to create a window:
You can now use this pointer to blit something to the surface and display it by updating the window's
surface:
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!
c sdl-2 double-buffering
If you care about how it's implemented, why not just read the sources? – HolyBlackCat May 1, 2021 at 12:46
@HolyBlackCat Honestly, I didn't consider this up until now. I just caught up on it, and it was a bit overwhelming as
I'm fairly new to programming. UpdateWindowSurface() is calling UpdateWindowSurfaceRects(), which calls
UpdateWindowFrameBuffer(), which is a function pointer in the source file I'm reading right now. I cannot find the
implementation of UpdateWindowFrameBuffer(). It would be sufficient for me to know how double buffering gets
basically realised here rather than know every detail of the implementation that would overwhelm me most likely
anyway. – Ruperrrt May 1, 2021 at 13:23
Related questions