Don't recreate the GL content in windib target if SDL_SetVideoMode() is being SDL-1.2
authorRyan C. Gordon <icculus@icculus.org>
Wed, 12 Mar 2008 22:01:48 +0000
branchSDL-1.2
changeset 414373e7e7f5b5a1
parent 4142 4433ef2a1802
child 4144 904defc0792e
Don't recreate the GL content in windib target if SDL_SetVideoMode() is being
called in response to a window resize event...prevents loss of GL state and
objects.
src/video/windib/SDL_dibvideo.c
     1.1 --- a/src/video/windib/SDL_dibvideo.c	Fri Feb 29 14:01:45 2008 +0000
     1.2 +++ b/src/video/windib/SDL_dibvideo.c	Wed Mar 12 22:01:48 2008 +0000
     1.3 @@ -512,6 +512,36 @@
     1.4  	int x, y;
     1.5  	Uint32 Rmask, Gmask, Bmask;
     1.6  
     1.7 +	/*
     1.8 +	 * Special case for OpenGL windows...since the app needs to call
     1.9 +	 *  SDL_SetVideoMode() in response to resize events to continue to
    1.10 +	 *  function, but WGL handles the GL context details behind the scenes,
    1.11 +	 *  there's no sense in tearing the context down just to rebuild it
    1.12 +	 *  to what it already was...tearing it down sacrifices your GL state
    1.13 +	 *  and uploaded textures. So if we're requesting the same video mode
    1.14 +	 *  attributes and the width/height matches the physical window, just
    1.15 +	 *  return immediately.
    1.16 +	 */
    1.17 +	if ( (SDL_Window != NULL) &&
    1.18 +	     (current != NULL) &&
    1.19 +	     (current->flags == flags) &&
    1.20 +	     (current->format->BitsPerPixel == bpp) &&
    1.21 +	     ((flags & SDL_FULLSCREEN) == 0) ) {  /* probably not safe for fs */
    1.22 +		int curwidth, curheight;
    1.23 +		RECT size;
    1.24 +
    1.25 +		/* Get the current position of our window */
    1.26 +		GetClientRect(SDL_Window, &size);
    1.27 +
    1.28 +		curwidth = (size.right - size.left);
    1.29 +		curheight = (size.bottom - size.top);
    1.30 +		if ((width == curwidth) && (height == curheight)) {
    1.31 +			current->w = width;
    1.32 +			current->h = height;
    1.33 +			return current;  /* we're already good to go. */
    1.34 +		}
    1.35 +	}
    1.36 +
    1.37  	prev_flags = current->flags;
    1.38  
    1.39  	/* Clean up any GL context that may be hanging around */