src/video/ataricommon/SDL_atarigl.c
changeset 992 0324ce32b2d9
parent 991 12b13601a544
child 993 2662da16d668
     1.1 --- a/src/video/ataricommon/SDL_atarigl.c	Fri Nov 26 16:16:50 2004 +0000
     1.2 +++ b/src/video/ataricommon/SDL_atarigl.c	Fri Nov 26 22:11:30 2004 +0000
     1.3 @@ -80,13 +80,9 @@
     1.4  	return (gl_active);
     1.5  }
     1.6  
     1.7 -void SDL_AtariGL_Quit(_THIS)
     1.8 +void SDL_AtariGL_Quit(_THIS, SDL_bool unload)
     1.9  {
    1.10  #ifdef HAVE_OPENGL
    1.11 -	if (!gl_active) {
    1.12 -		return;
    1.13 -	}
    1.14 -
    1.15  	if (gl_oldmesa) {
    1.16  		/* Old mesa implementations */
    1.17  		if (this->gl_data->OSMesaDestroyLDG) {
    1.18 @@ -106,7 +102,9 @@
    1.19  		}
    1.20  	}
    1.21  
    1.22 -	SDL_AtariGL_UnloadLibrary(this);
    1.23 +	if (unload) {
    1.24 +		SDL_AtariGL_UnloadLibrary(this);
    1.25 +	}
    1.26  
    1.27  #endif /* HAVE_OPENGL */
    1.28  	gl_active = 0;
    1.29 @@ -378,6 +376,8 @@
    1.30  	GLenum osmesa_format;
    1.31  	SDL_PixelFormat *pixel_format;
    1.32  	Uint32	redmask;
    1.33 +	int recreatecontext;
    1.34 +	GLint newaccumsize;
    1.35  
    1.36  	if (this->gl_config.dll_handle) {
    1.37  		if (this->gl_data->OSMesaCreateContextExt == NULL) {
    1.38 @@ -440,11 +440,39 @@
    1.39  			break;
    1.40  	}
    1.41  
    1.42 -	gl_ctx = this->gl_data->OSMesaCreateContextExt(
    1.43 -		osmesa_format, this->gl_config.depth_size,
    1.44 -		this->gl_config.stencil_size, this->gl_config.accum_red_size +
    1.45 -		this->gl_config.accum_green_size + this->gl_config.accum_blue_size +
    1.46 -		this->gl_config.accum_alpha_size, NULL );
    1.47 +	/* Try to keep current context if possible */
    1.48 +	newaccumsize =
    1.49 +		this->gl_config.accum_red_size +
    1.50 +		this->gl_config.accum_green_size +
    1.51 +		this->gl_config.accum_blue_size +
    1.52 +		this->gl_config.accum_alpha_size;
    1.53 +	recreatecontext=1;
    1.54 +	if (gl_ctx &&
    1.55 +		(gl_curformat == osmesa_format) &&
    1.56 +		(gl_curdepth == this->gl_config.depth_size) &&
    1.57 +		(gl_curstencil == this->gl_config.stencil_size) &&
    1.58 +		(gl_curaccum == newaccumsize)) {
    1.59 +		recreatecontext = 0;
    1.60 +	}
    1.61 +	if (recreatecontext) {
    1.62 +		SDL_AtariGL_Quit(this, SDL_FALSE);
    1.63 +
    1.64 +		gl_ctx = this->gl_data->OSMesaCreateContextExt(
    1.65 +			osmesa_format, this->gl_config.depth_size,
    1.66 +			this->gl_config.stencil_size, newaccumsize, NULL );
    1.67 +
    1.68 +		if (gl_ctx) {
    1.69 +			gl_curformat = osmesa_format;
    1.70 +			gl_curdepth = this->gl_config.depth_size;
    1.71 +			gl_curstencil = this->gl_config.stencil_size;
    1.72 +			gl_curaccum = newaccumsize;
    1.73 +		} else {
    1.74 +			gl_curformat = 0;
    1.75 +			gl_curdepth = 0;
    1.76 +			gl_curstencil = 0;
    1.77 +			gl_curaccum = 0;
    1.78 +		}
    1.79 +	}
    1.80  
    1.81  	return (gl_ctx != NULL);
    1.82  }
    1.83 @@ -454,6 +482,7 @@
    1.84  	GLenum osmesa_format;
    1.85  	SDL_PixelFormat *pixel_format;
    1.86  	Uint32	redmask;
    1.87 +	int recreatecontext;
    1.88  
    1.89  	if (this->gl_config.dll_handle) {
    1.90  		if (this->gl_data->OSMesaCreateLDG == NULL) {
    1.91 @@ -520,9 +549,31 @@
    1.92  			break;
    1.93  	}
    1.94  
    1.95 -	gl_shadow = this->gl_data->OSMesaCreateLDG(
    1.96 -		osmesa_format, GL_UNSIGNED_BYTE, current->w, current->h
    1.97 -	);
    1.98 +	/* Try to keep current context if possible */
    1.99 +	recreatecontext=1;
   1.100 +	if (gl_shadow &&
   1.101 +		(gl_curformat == osmesa_format) &&
   1.102 +		(gl_curwidth == current->w) &&
   1.103 +		(gl_curheight == current->h)) {
   1.104 +		recreatecontext = 0;
   1.105 +	}
   1.106 +	if (recreatecontext) {
   1.107 +		SDL_AtariGL_Quit(this, SDL_FALSE);
   1.108 +
   1.109 +		gl_shadow = this->gl_data->OSMesaCreateLDG(
   1.110 +			osmesa_format, GL_UNSIGNED_BYTE, current->w, current->h
   1.111 +		);
   1.112 +
   1.113 +		if (gl_shadow) {
   1.114 +			gl_curformat = osmesa_format;
   1.115 +			gl_curwidth = current->w;
   1.116 +			gl_curheight = current->h;
   1.117 +		} else {
   1.118 +			gl_curformat = 0;
   1.119 +			gl_curwidth = 0;
   1.120 +			gl_curheight = 0;
   1.121 +		}
   1.122 +	}
   1.123  
   1.124  	return (gl_shadow != NULL);
   1.125  }