From 6855fb028d4e8456a652a5c55a098a5f496f9c2b Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Sat, 28 Sep 2019 18:54:22 -0700 Subject: [PATCH] Fix resolution configuration on SDL2 --- sc2/src/libs/graphics/gfx_common.h | 1 + sc2/src/libs/graphics/sdl/sdl1_common.c | 10 ++++++++++ sc2/src/libs/graphics/sdl/sdl2_common.c | 5 +++++ sc2/src/libs/graphics/sdl/sdl2_pure.c | 3 +++ sc2/src/uqm/setupmenu.c | 25 ++++++++++++++++--------- 5 files changed, 35 insertions(+), 9 deletions(-) diff --git a/sc2/src/libs/graphics/gfx_common.h b/sc2/src/libs/graphics/gfx_common.h index ef9cd718a..2690e9ae9 100644 --- a/sc2/src/libs/graphics/gfx_common.h +++ b/sc2/src/libs/graphics/gfx_common.h @@ -69,6 +69,7 @@ void TFB_UninitGraphics (void); void TFB_ProcessEvents (void); void TFB_SetGamma (float gamma); void TFB_UploadTransitionScreen (void); +int TFB_SupportsHardwareScaling (void); // This function should not be called directly void TFB_SwapBuffers (int force_full_redraw); diff --git a/sc2/src/libs/graphics/sdl/sdl1_common.c b/sc2/src/libs/graphics/sdl/sdl1_common.c index 43e8db878..96f68f7ef 100644 --- a/sc2/src/libs/graphics/sdl/sdl1_common.c +++ b/sc2/src/libs/graphics/sdl/sdl1_common.c @@ -209,4 +209,14 @@ TFB_SetColors (SDL_Surface *surface, SDL_Color *colors, int firstcolor, int ncol return SDL_SetColors (surface, colors, firstcolor, ncolors); } +int +TFB_SupportsHardwareScaling (void) +{ +#ifdef HAVE_OPENGL + return 1; +#else + return 0; +#endif +} + #endif diff --git a/sc2/src/libs/graphics/sdl/sdl2_common.c b/sc2/src/libs/graphics/sdl/sdl2_common.c index 02ba3e871..74f7541cd 100644 --- a/sc2/src/libs/graphics/sdl/sdl2_common.c +++ b/sc2/src/libs/graphics/sdl/sdl2_common.c @@ -203,4 +203,9 @@ TFB_SetColors (SDL_Surface *surface, SDL_Color *colors, int firstcolor, int ncol return 0; } +int +TFB_SupportsHardwareScaling (void) +{ + return 1; +} #endif diff --git a/sc2/src/libs/graphics/sdl/sdl2_pure.c b/sc2/src/libs/graphics/sdl/sdl2_pure.c index 495dd0c40..aa2866d93 100644 --- a/sc2/src/libs/graphics/sdl/sdl2_pure.c +++ b/sc2/src/libs/graphics/sdl/sdl2_pure.c @@ -218,6 +218,9 @@ TFB_Pure_ConfigureVideo (int driver, int flags, int width, int height, int toggl graphics_backend = &sdl2_unscaled_backend; } + /* We succeeded, so alter the screen size to our new sizes */ + ScreenWidthActual = width; + ScreenHeightActual = height; /* TODO: Set bilinear vs nearest-neighbor filtering based on * GfxFlags & TFB_GFXFLAGS_SCALE_ANY */ return 0; diff --git a/sc2/src/uqm/setupmenu.c b/sc2/src/uqm/setupmenu.c index 3ea8c0225..26f91c721 100644 --- a/sc2/src/uqm/setupmenu.c +++ b/sc2/src/uqm/setupmenu.c @@ -66,12 +66,6 @@ static void rename_template (WIDGET_TEXTENTRY *self); static void rebind_control (WIDGET_CONTROLENTRY *widget); static void clear_control (WIDGET_CONTROLENTRY *widget); -#ifdef HAVE_OPENGL -#define RES_OPTS 4 -#else -#define RES_OPTS 2 -#endif - #define MENU_COUNT 8 #define CHOICE_COUNT 22 #define SLIDER_COUNT 3 @@ -190,6 +184,19 @@ static WIDGET **menu_widgets[MENU_COUNT] = { main_widgets, graphics_widgets, audio_widgets, engine_widgets, incomplete_widgets, keyconfig_widgets, advanced_widgets, editkeys_widgets }; +static int +number_res_options (void) +{ + if (TFB_SupportsHardwareScaling ()) + { + return 4; + } + else + { + return 2; + } +} + static int quit_main_menu (WIDGET *self, int event) { @@ -359,11 +366,11 @@ SetDefaults (void) GetGlobalOptions (&opts); if (opts.res == OPTVAL_CUSTOM) { - choices[0].numopts = RES_OPTS + 1; + choices[0].numopts = number_res_options () + 1; } else { - choices[0].numopts = RES_OPTS; + choices[0].numopts = number_res_options (); } choices[0].selected = opts.res; choices[1].selected = opts.driver; @@ -728,7 +735,7 @@ init_widgets (void) } /* The first choice is resolution, and is handled specially */ - choices[0].numopts = RES_OPTS; + choices[0].numopts = number_res_options (); /* Choices 18-20 are also special, being the names of the key configurations */ for (i = 0; i < 6; i++)