[SDL] SDL 1.3 backend: Questions about Framebuffers
Ryan C. Gordon
icculus at icculus.org
Wed Jul 20 20:54:45 PDT 2011
> Here's my problem: I am given the pixel array to fill, the address of
> which is passed on to SDL. This is all well and good. But if the
> window changes size, my pixel array has to change size (there are
> problems if the window moves or the screen resolution changes, too, but
> I think that I can overcome this with a copy of the buffer). I know
> when the window resizes, and can allocate accordingly; but how do I tell
> SDL to change its pointer to the framebuffer, or copy thereof?
When the OS tells you that the window has been resized, you need to call
SDL_SendWindowEvent(my_sdl_window, SDL_WINDOWEVENT_RESIZED, w, h);
...and eventually SDL, at some higher level, will call
SDL_OnWindowResized(), which lets the system know that the existing
framebuffer is gone. The next time it needs a framebuffer, it will call
your driver's CreateWindowFramebuffer() implementation again.
SDL will not make any attempt to free the array you provide in
CreateWindowFramebuffer. If you need to free or realloc this buffer when
the window resizes or is destroyed, it is your responsibility to do it!
Once the system decides a framebuffer isn't valid, due to a resize
event, it just simply never touches that pointer again (but if the
pointer is still usable for some reason, you can just hand it to SDL
again when it re-calls CreateWindowFramebuffer()).
If the app called SDL_SetWindowSize(), then SDL will eventually call
SDL_OnWindowResized() for the same result. You're still responsible for
dealing with the framebuffer pointer (realloc or whatever in your
SetWindowSize() implementation), but you don't call SDL_SendWindowEvent
in this case.
More information about the SDL