Search code examples
sdlsdl-1.2

SDL_SetVideoMode ignores flags & SDL_Flip is slow


I'm initializing with

SDL_Init(SDL_INIT_VIDEO);
screen = SDL_SetVideoMode(800, 600, 32, SDL_SWSURFACE|SDL_DOUBLEBUF);

and then calling, in a loop, between calls to sleep, just

SDL_LockSurface(screen);
// Will eventually twiddle pixels here...but not yet
SDL_UnlockSurface(screen);
SDL_Flip(screen);

And that call to flip takes a varying amount of time, but around 10ms, which is a lot for nothing.

So that makes me wonder if I'm causing, say, a copy from video memory to system memory or something, and I should create the surface differently. BUT, additionally, screen->flags is always equal to SDL_ASYNCBLIT and no other bits are set, regardless of the flags I pass to SDL_SetVideoMode. So I can't make any other kind of surface anyway.

Should I be creating another offscreen surface, rendering to that, and then blitting it to the screen? What am I doing wrong?

EDIT: Removing the SDL_Lock and SDL_Unlock pair does nothing to speed things up. The SDL_Flip is just slow.


Solution

  • For the sake of the two or three people that may, someday, see this question, I think the reason the SDL_Flip takes so long is that it waits for vsync, so a busy loop calling SDL_Flip will necessarily be limited by the vsync rate.

    If that's correct, the fact that SDL_Flip takes so long is not an actual issue, since if I were doing work to render things, then there'd be less time to wait for the vsync.