Hi guys, I’m on the usual Quest for Smooth Animation. I know this is a
common topic but I didn’t find any post that tells the whole story. So
I’ll try to do that, please let me know if I got it right.
-
Create the video surface with SDL_DOUBLEBUFF | SDL_HWSURFACE.
-
If it succeeds (flags & SDL_HWSURFACE == SDL_HWSURFACE), you get a
video memory chunk with enough space for TWO screens. The video card
displays one of these at a time. So you draw into the offscreen one (the
one represented by the returned SDL_Surface, right?), and call
SDL_Flip(), which waits for VSYNC and swaps the visible surface with the
invisible surface. -
Because the back buffer is on hardware, alpha blitting (which I do a
lot) is slow because it requires read. Therefore, you also allocate a
second surface, with the same dimensions and format of the screen, but
as a software surface. You draw on this third buffer, copy the dirty
parts to the hardware back buffer, and call SDL_Flip(). This is triple
buffering. -
If 1) didn’t succeed, instead you got a software surface (and the
display memory which you can’t directly touch). You draw on this
surface, and copy the dirty bits with SDL_UpdateRect(). The copy is
immediate, no wait for VSYNC, so you get tearing. The best you can do is
try to have a frame rate close to the monitor’s refresh rate.
I’m I right so far? I’ll try to sort my understanding about dirty rect
management in triple buffering now
Thanks!
–Gabriel