diff --git a/sc2/src/sc2code/libs/graphics/sdl/opengl.c b/sc2/src/sc2code/libs/graphics/sdl/opengl.c index dac7d90b3..6faa18c18 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/opengl.c +++ b/sc2/src/sc2code/libs/graphics/sdl/opengl.c @@ -22,9 +22,9 @@ #include "bbox.h" #include "2xscalers.h" -static SDL_Surface *format_conv_surf; -static SDL_Surface *scaled_display; -static SDL_Surface *scaled_transition; +static SDL_Surface *format_conv_surf = NULL; +static SDL_Surface *scaled_display = NULL; +static SDL_Surface *scaled_transition = NULL; static int ScreenFilterMode; static GLuint DisplayTexture; @@ -59,23 +59,11 @@ Create_Screen (void) } int -TFB_GL_InitGraphics (int driver, int flags, int width, int height, int bpp) +TFB_GL_ConfigureVideo (int driver, int flags, int width, int height, int bpp) { - char VideoName[256]; int i, videomode_flags, texture_width, texture_height; - GraphicsDriver = driver; ScreenColorDepth = bpp; - - fprintf (stderr, "Initializing SDL with OpenGL support.\n"); - - SDL_VideoDriverName (VideoName, sizeof (VideoName)); - fprintf (stderr, "SDL driver used: %s\n", VideoName); - fprintf (stderr, "SDL initialized.\n"); - fprintf (stderr, "Initializing Screen.\n"); - - ScreenWidth = 320; - ScreenHeight = 240; ScreenWidthActual = width; ScreenHeightActual = height; @@ -133,33 +121,27 @@ TFB_GL_InitGraphics (int driver, int flags, int width, int height, int bpp) glGetString (GL_RENDERER), glGetString (GL_VERSION)); } - for (i = 0; i < TFB_GFX_NUMSCREENS; i++) - { - SDL_Screens[i] = Create_Screen (); - } - - SDL_Screen = SDL_Screens[0]; - TransitionScreen = SDL_Screens[2]; - - format_conv_surf = SDL_CreateRGBSurface(SDL_SWSURFACE, 0, 0, 32, - R_MASK, G_MASK, B_MASK, A_MASK); - if (format_conv_surf == NULL) - { - fprintf (stderr, "Couldn't create format_conv_surf: %s\n", SDL_GetError()); - exit(-1); - } - if (GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPT || GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPTADV || GfxFlags & TFB_GFXFLAGS_SCALE_TRISCAN) { + if (scaled_display) + { + SDL_FreeSurface (scaled_display); + scaled_display = NULL; + } scaled_display = SDL_CreateRGBSurface(SDL_SWSURFACE, ScreenWidth * 2, ScreenHeight * 2, 32, R_MASK, G_MASK, B_MASK, 0x00000000); if (scaled_display == NULL) { fprintf (stderr, "Couldn't create scaled_display: %s\n", SDL_GetError()); exit(-1); - } + } + if (scaled_transition) + { + SDL_FreeSurface (scaled_transition); + scaled_transition = NULL; + } scaled_transition = SDL_CreateRGBSurface(SDL_SWSURFACE, ScreenWidth * 2, ScreenHeight * 2, 32, R_MASK, G_MASK, B_MASK, 0x00000000); if (scaled_transition == NULL) @@ -177,8 +159,18 @@ TFB_GL_InitGraphics (int driver, int flags, int width, int height, int bpp) texture_height = 256; } - // pre-compute the RGB->YUV transformations - Scale_PrepYUV(); + if (format_conv_surf) + { + SDL_FreeSurface (format_conv_surf); + format_conv_surf = NULL; + } + format_conv_surf = SDL_CreateRGBSurface(SDL_SWSURFACE, 0, 0, 32, + R_MASK, G_MASK, B_MASK, A_MASK); + if (format_conv_surf == NULL) + { + fprintf (stderr, "Couldn't create format_conv_surf: %s\n", SDL_GetError()); + exit(-1); + } if (GfxFlags & TFB_GFXFLAGS_SCALE_BILINEAR || GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPT || @@ -193,6 +185,15 @@ TFB_GL_InitGraphics (int driver, int flags, int width, int height, int bpp) else scanlines = FALSE; + /* TODO: This leaks */ + for (i = 0; i < TFB_GFX_NUMSCREENS; i++) + { + SDL_Screens[i] = Create_Screen (); + } + + SDL_Screen = SDL_Screens[0]; + TransitionScreen = SDL_Screens[2]; + glViewport (0, 0, ScreenWidthActual, ScreenHeightActual); glClearColor (0,0,0,0); glClear (GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); @@ -218,6 +219,29 @@ TFB_GL_InitGraphics (int driver, int flags, int width, int height, int bpp) return 0; } +int +TFB_GL_InitGraphics (int driver, int flags, int width, int height, int bpp) +{ + char VideoName[256]; + + fprintf (stderr, "Initializing SDL with OpenGL support.\n"); + + SDL_VideoDriverName (VideoName, sizeof (VideoName)); + fprintf (stderr, "SDL driver used: %s\n", VideoName); + fprintf (stderr, "SDL initialized.\n"); + fprintf (stderr, "Initializing Screen.\n"); + + ScreenWidth = 320; + ScreenHeight = 240; + + TFB_GL_ConfigureVideo (driver, flags, width, height, bpp); + + // pre-compute the RGB->YUV transformations + Scale_PrepYUV(); + + return 0; +} + void TFB_GL_UploadTransitionScreen (void) { upload_transitiontexture = TRUE; diff --git a/sc2/src/sc2code/libs/graphics/sdl/opengl.h b/sc2/src/sc2code/libs/graphics/sdl/opengl.h index 3313ccdbc..c7828e330 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/opengl.h +++ b/sc2/src/sc2code/libs/graphics/sdl/opengl.h @@ -22,6 +22,7 @@ #include "libs/graphics/sdl/sdl_common.h" int TFB_GL_InitGraphics (int driver, int flags, int width, int height, int bpp); +int TFB_GL_ConfigureVideo (int driver, int flags, int width, int height, int bpp); void TFB_GL_UploadTransitionScreen (void); void TFB_GL_SwapBuffers (int force_full_redraw); SDL_Surface* TFB_GL_DisplayFormatAlpha (SDL_Surface *surface); diff --git a/sc2/src/sc2code/libs/graphics/sdl/pure.c b/sc2/src/sc2code/libs/graphics/sdl/pure.c index 36ab77c70..6bd4273c6 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/pure.c +++ b/sc2/src/sc2code/libs/graphics/sdl/pure.c @@ -21,9 +21,9 @@ #include "bbox.h" #include "2xscalers.h" -static SDL_Surface *fade_black; -static SDL_Surface *fade_white; -static SDL_Surface *fade_temp; +static SDL_Surface *fade_black = NULL; +static SDL_Surface *fade_white = NULL; +static SDL_Surface *fade_temp = NULL; static SDL_Surface * Create_Screen (SDL_Surface *template) @@ -37,32 +37,14 @@ Create_Screen (SDL_Surface *template) } int -TFB_Pure_InitGraphics (int driver, int flags, int width, int height, int bpp) +TFB_Pure_ConfigureVideo (int driver, int flags, int width, int height, int bpp) { - char VideoName[256]; - int videomode_flags; + int i, videomode_flags; SDL_Surface *test_extra; - int i; GraphicsDriver = driver; ScreenColorDepth = bpp; - fprintf (stderr, "Initializing Pure-SDL graphics.\n"); - - SDL_VideoDriverName (VideoName, sizeof (VideoName)); - fprintf (stderr, "SDL driver used: %s\n", VideoName); - // Set the environment variable SDL_VIDEODRIVER to override - // For Linux: x11 (default), dga, fbcon, directfb, svgalib, - // ggi, aalib - // For Windows: directx (default), windib - - fprintf (stderr, "SDL initialized.\n"); - - fprintf (stderr, "Initializing Screen.\n"); - - ScreenWidth = 320; - ScreenHeight = 240; - // must use SDL_SWSURFACE, HWSURFACE doesn't work properly with fades/scaling if (width == 320 && height == 240) { @@ -118,14 +100,29 @@ TFB_Pure_InitGraphics (int driver, int flags, int width, int height, int bpp) SDL_Screen = SDL_Screens[0]; TransitionScreen = SDL_Screens[2]; + if (fade_white) + { + SDL_FreeSurface (fade_white); + fade_white = NULL; + } fade_white = Create_Screen(test_extra); SDL_FillRect (fade_white, NULL, SDL_MapRGB (fade_white->format, 255, 255, 255)); + if (fade_black) + { + SDL_FreeSurface (fade_black); + fade_black = NULL; + } fade_black = Create_Screen(test_extra); SDL_FillRect (fade_black, NULL, SDL_MapRGB (fade_black->format, 0, 0, 0)); + if (fade_temp) + { + SDL_FreeSurface (fade_temp); + fade_temp = NULL; + } fade_temp = Create_Screen(test_extra); - + SDL_FreeSurface (test_extra); - + if (SDL_Video->format->BytesPerPixel != SDL_Screen->format->BytesPerPixel) { fprintf (stderr, "Fatal error: SDL_Video and SDL_Screen bpp doesn't match (%d vs. %d)\n", @@ -133,6 +130,32 @@ TFB_Pure_InitGraphics (int driver, int flags, int width, int height, int bpp) exit(-1); } + return 0; +} + +int +TFB_Pure_InitGraphics (int driver, int flags, int width, int height, int bpp) +{ + char VideoName[256]; + + fprintf (stderr, "Initializing Pure-SDL graphics.\n"); + + SDL_VideoDriverName (VideoName, sizeof (VideoName)); + fprintf (stderr, "SDL driver used: %s\n", VideoName); + // Set the environment variable SDL_VIDEODRIVER to override + // For Linux: x11 (default), dga, fbcon, directfb, svgalib, + // ggi, aalib + // For Windows: directx (default), windib + + fprintf (stderr, "SDL initialized.\n"); + + fprintf (stderr, "Initializing Screen.\n"); + + ScreenWidth = 320; + ScreenHeight = 240; + + TFB_Pure_ConfigureVideo (driver, flags, width, height, bpp); + // pre-compute the RGB->YUV transformations Scale_PrepYUV(); diff --git a/sc2/src/sc2code/libs/graphics/sdl/pure.h b/sc2/src/sc2code/libs/graphics/sdl/pure.h index 86c8d6d12..0729e5468 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/pure.h +++ b/sc2/src/sc2code/libs/graphics/sdl/pure.h @@ -22,6 +22,7 @@ #include "libs/graphics/sdl/sdl_common.h" int TFB_Pure_InitGraphics (int driver, int flags, int width, int height, int bpp); +int TFB_Pure_ConfigureVideo (int driver, int flags, int width, int height, int bpp); void TFB_Pure_SwapBuffers (int force_full_redraw); #endif diff --git a/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c b/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c index 70227adc2..5c22ed50b 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c +++ b/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c @@ -73,6 +73,42 @@ TFB_PreInit (void) } } +int +TFB_ReInitGraphics (int driver, int flags, int width, int height, int bpp) +{ + int result; + char caption[200]; + + GfxFlags = flags; + + if (driver == TFB_GFXDRIVER_SDL_OPENGL) + { +#ifdef HAVE_OPENGL + result = TFB_GL_ConfigureVideo (driver, flags, width, height, bpp); +#else + driver = TFB_GFXDRIVER_SDL_PURE; + fprintf (stderr, "OpenGL support not compiled in, so using pure " + "sdl driver\n"); + result = TFB_Pure_ConfigureVideo (driver, flags, width, height, bpp); +#endif + } + else + { + result = TFB_Pure_ConfigureVideo (driver, flags, width, height, bpp); + } + + sprintf (caption, "The Ur-Quan Masters v%d.%d%s", + UQM_MAJOR_VERSION, UQM_MINOR_VERSION, UQM_EXTRA_VERSION); + SDL_WM_SetCaption (caption, NULL); + + if (flags & TFB_GFXFLAGS_FULLSCREEN) + SDL_ShowCursor (SDL_DISABLE); + else + SDL_ShowCursor (SDL_ENABLE); + + return result; +} + int TFB_InitGraphics (int driver, int flags, int width, int height, int bpp) { @@ -696,9 +732,9 @@ TFB_FlushGraphics () // Only call from main thread!! ClearSemaphore (DC.data.sendsignal.sem); break; case TFB_DRAWCOMMANDTYPE_REINITVIDEO: - fprintf (stderr, "TODO: REINITVIDEO command sent. Not yet implemented. Pester McMartin.\n"); - fprintf (stderr, " Request: %dx%d %dbpp %s Flags: %08x\n", DC.data.reinitvideo.width, DC.data.reinitvideo.height, DC.data.reinitvideo.bpp, DC.data.reinitvideo.driver ? "Pure-SDL" : "OpenGL", DC.data.reinitvideo.flags); - + TFB_ReInitGraphics (DC.data.reinitvideo.driver, DC.data.reinitvideo.flags, + DC.data.reinitvideo.width, DC.data.reinitvideo.height, + DC.data.reinitvideo.bpp); break; } } diff --git a/sc2/src/sc2code/setupmenu.c b/sc2/src/sc2code/setupmenu.c index 41fe66d9b..e4925bb4b 100644 --- a/sc2/src/sc2code/setupmenu.c +++ b/sc2/src/sc2code/setupmenu.c @@ -706,7 +706,9 @@ SetGlobalOptions (GLOBALOPTS *opts) (NewDriver != GraphicsDriver) || (NewGfxFlags != GfxFlags)) { + FlushGraphics (); TFB_DrawScreen_ReinitVideo (NewDriver, NewGfxFlags, NewWidth, NewHeight, NewDepth); + FlushGraphics (); } optSubtitles = (opts->subtitles == OPTVAL_ENABLED) ? TRUE : FALSE; // optWhichMusic = (opts->music == OPTVAL_3DO) ? OPT_3DO : OPT_PC; @@ -714,4 +716,5 @@ SetGlobalOptions (GLOBALOPTS *opts) optWhichFonts = (opts->text == OPTVAL_3DO) ? OPT_3DO : OPT_PC; optWhichCoarseScan = (opts->cscan == OPTVAL_3DO) ? OPT_3DO : OPT_PC; optSmoothScroll = (opts->scroll == OPTVAL_3DO) ? OPT_3DO : OPT_PC; + }