comparison src/video/ataricommon/SDL_atarigl.c @ 992:0324ce32b2d9

Keep current OpenGL context when possible
author Patrice Mandin <patmandin@gmail.com>
date Fri, 26 Nov 2004 22:11:30 +0000
parents 12b13601a544
children 2662da16d668
comparison
equal deleted inserted replaced
991:12b13601a544 992:0324ce32b2d9
78 #endif 78 #endif
79 79
80 return (gl_active); 80 return (gl_active);
81 } 81 }
82 82
83 void SDL_AtariGL_Quit(_THIS) 83 void SDL_AtariGL_Quit(_THIS, SDL_bool unload)
84 { 84 {
85 #ifdef HAVE_OPENGL 85 #ifdef HAVE_OPENGL
86 if (!gl_active) {
87 return;
88 }
89
90 if (gl_oldmesa) { 86 if (gl_oldmesa) {
91 /* Old mesa implementations */ 87 /* Old mesa implementations */
92 if (this->gl_data->OSMesaDestroyLDG) { 88 if (this->gl_data->OSMesaDestroyLDG) {
93 this->gl_data->OSMesaDestroyLDG(); 89 this->gl_data->OSMesaDestroyLDG();
94 } 90 }
104 } 100 }
105 gl_ctx = NULL; 101 gl_ctx = NULL;
106 } 102 }
107 } 103 }
108 104
109 SDL_AtariGL_UnloadLibrary(this); 105 if (unload) {
106 SDL_AtariGL_UnloadLibrary(this);
107 }
110 108
111 #endif /* HAVE_OPENGL */ 109 #endif /* HAVE_OPENGL */
112 gl_active = 0; 110 gl_active = 0;
113 } 111 }
114 112
376 static int InitNew(_THIS, SDL_Surface *current) 374 static int InitNew(_THIS, SDL_Surface *current)
377 { 375 {
378 GLenum osmesa_format; 376 GLenum osmesa_format;
379 SDL_PixelFormat *pixel_format; 377 SDL_PixelFormat *pixel_format;
380 Uint32 redmask; 378 Uint32 redmask;
379 int recreatecontext;
380 GLint newaccumsize;
381 381
382 if (this->gl_config.dll_handle) { 382 if (this->gl_config.dll_handle) {
383 if (this->gl_data->OSMesaCreateContextExt == NULL) { 383 if (this->gl_data->OSMesaCreateContextExt == NULL) {
384 return 0; 384 return 0;
385 } 385 }
438 gl_pixelsize = 1; 438 gl_pixelsize = 1;
439 osmesa_format = OSMESA_COLOR_INDEX; 439 osmesa_format = OSMESA_COLOR_INDEX;
440 break; 440 break;
441 } 441 }
442 442
443 gl_ctx = this->gl_data->OSMesaCreateContextExt( 443 /* Try to keep current context if possible */
444 osmesa_format, this->gl_config.depth_size, 444 newaccumsize =
445 this->gl_config.stencil_size, this->gl_config.accum_red_size + 445 this->gl_config.accum_red_size +
446 this->gl_config.accum_green_size + this->gl_config.accum_blue_size + 446 this->gl_config.accum_green_size +
447 this->gl_config.accum_alpha_size, NULL ); 447 this->gl_config.accum_blue_size +
448 this->gl_config.accum_alpha_size;
449 recreatecontext=1;
450 if (gl_ctx &&
451 (gl_curformat == osmesa_format) &&
452 (gl_curdepth == this->gl_config.depth_size) &&
453 (gl_curstencil == this->gl_config.stencil_size) &&
454 (gl_curaccum == newaccumsize)) {
455 recreatecontext = 0;
456 }
457 if (recreatecontext) {
458 SDL_AtariGL_Quit(this, SDL_FALSE);
459
460 gl_ctx = this->gl_data->OSMesaCreateContextExt(
461 osmesa_format, this->gl_config.depth_size,
462 this->gl_config.stencil_size, newaccumsize, NULL );
463
464 if (gl_ctx) {
465 gl_curformat = osmesa_format;
466 gl_curdepth = this->gl_config.depth_size;
467 gl_curstencil = this->gl_config.stencil_size;
468 gl_curaccum = newaccumsize;
469 } else {
470 gl_curformat = 0;
471 gl_curdepth = 0;
472 gl_curstencil = 0;
473 gl_curaccum = 0;
474 }
475 }
448 476
449 return (gl_ctx != NULL); 477 return (gl_ctx != NULL);
450 } 478 }
451 479
452 static int InitOld(_THIS, SDL_Surface *current) 480 static int InitOld(_THIS, SDL_Surface *current)
453 { 481 {
454 GLenum osmesa_format; 482 GLenum osmesa_format;
455 SDL_PixelFormat *pixel_format; 483 SDL_PixelFormat *pixel_format;
456 Uint32 redmask; 484 Uint32 redmask;
485 int recreatecontext;
457 486
458 if (this->gl_config.dll_handle) { 487 if (this->gl_config.dll_handle) {
459 if (this->gl_data->OSMesaCreateLDG == NULL) { 488 if (this->gl_data->OSMesaCreateLDG == NULL) {
460 return 0; 489 return 0;
461 } 490 }
518 gl_copyshadow = CopyShadowDirect; 547 gl_copyshadow = CopyShadowDirect;
519 osmesa_format = OSMESA_COLOR_INDEX; 548 osmesa_format = OSMESA_COLOR_INDEX;
520 break; 549 break;
521 } 550 }
522 551
523 gl_shadow = this->gl_data->OSMesaCreateLDG( 552 /* Try to keep current context if possible */
524 osmesa_format, GL_UNSIGNED_BYTE, current->w, current->h 553 recreatecontext=1;
525 ); 554 if (gl_shadow &&
555 (gl_curformat == osmesa_format) &&
556 (gl_curwidth == current->w) &&
557 (gl_curheight == current->h)) {
558 recreatecontext = 0;
559 }
560 if (recreatecontext) {
561 SDL_AtariGL_Quit(this, SDL_FALSE);
562
563 gl_shadow = this->gl_data->OSMesaCreateLDG(
564 osmesa_format, GL_UNSIGNED_BYTE, current->w, current->h
565 );
566
567 if (gl_shadow) {
568 gl_curformat = osmesa_format;
569 gl_curwidth = current->w;
570 gl_curheight = current->h;
571 } else {
572 gl_curformat = 0;
573 gl_curwidth = 0;
574 gl_curheight = 0;
575 }
576 }
526 577
527 return (gl_shadow != NULL); 578 return (gl_shadow != NULL);
528 } 579 }
529 580
530 /*--- Conversions routines from shadow buffer to the screen ---*/ 581 /*--- Conversions routines from shadow buffer to the screen ---*/