From 475466dcd9b68ba9aa1fc27d57d4d891683778d0 Mon Sep 17 00:00:00 2001 From: Jonathan Haas Date: Wed, 7 Oct 2015 20:30:50 +0200 Subject: [PATCH] Require a restart after changing hardware rendering setting, decouple setting from active status --- data/language/english_uk.txt | 1 + src/localisation/string_ids.h | 3 +++ src/platform/platform.h | 2 ++ src/platform/shared.c | 18 +++++++++++++----- src/windows/options.c | 9 +++++++++ 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/data/language/english_uk.txt b/data/language/english_uk.txt index e306a49921..dfd3774486 100644 --- a/data/language/english_uk.txt +++ b/data/language/english_uk.txt @@ -3896,6 +3896,7 @@ STR_5554 :{SMALLFONT}{BLACK}Enable mountain tool STR_5555 :Show vehicles from other track types STR_5556 :Kick Player STR_5557 :Stay connected after desynchronisation (Multiplayer) +STR_5558 :A restart is required for this setting to take effect ##################### # Rides/attractions # diff --git a/src/localisation/string_ids.h b/src/localisation/string_ids.h index 14d82f3767..1078c93e0a 100644 --- a/src/localisation/string_ids.h +++ b/src/localisation/string_ids.h @@ -2143,6 +2143,9 @@ enum { STR_KICK_PLAYER = 5556, STR_STAY_CONNECTED_AFTER_DESYNC = 5557, + STR_RESTART_REQUIRED = 5558, + + // Have to include resource strings (from scenarios and objects) for the time being now that language is partially working STR_COUNT = 32768 }; diff --git a/src/platform/platform.h b/src/platform/platform.h index 0929c215e3..ec84336859 100644 --- a/src/platform/platform.h +++ b/src/platform/platform.h @@ -90,6 +90,8 @@ extern int gNumResolutions; extern resolution *gResolutions; extern SDL_Window *gWindow; +extern bool gHardwareDisplay; + extern bool gSteamOverlayActive; // Platform shared definitions diff --git a/src/platform/shared.c b/src/platform/shared.c index cdf9ecf854..3bd1934bc0 100644 --- a/src/platform/shared.c +++ b/src/platform/shared.c @@ -58,6 +58,7 @@ SDL_Texture *gBufferTexture = NULL; SDL_PixelFormat *gBufferTextureFormat = NULL; SDL_Color gPalette[256]; uint32 gPaletteHWMapped[256]; +bool gHardwareDisplay; bool gSteamOverlayActive = false; @@ -223,7 +224,7 @@ void platform_draw() int height = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_HEIGHT, uint16); if (!gOpenRCT2Headless) { - if (gConfigGeneral.hardware_display) { + if (gHardwareDisplay) { void *pixels; int pitch; if (SDL_LockTexture(gBufferTexture, NULL, &pixels, &pitch) == 0) { @@ -370,7 +371,7 @@ void platform_update_palette(char* colours, int start_index, int num_colours) } } - if (!gOpenRCT2Headless && !gConfigGeneral.hardware_display) { + if (!gOpenRCT2Headless && !gHardwareDisplay) { surface = SDL_GetWindowSurface(gWindow); if (!surface) { log_fatal("SDL_GetWindowSurface failed %s", SDL_GetError()); @@ -673,6 +674,8 @@ static void platform_create_window() RCT2_GLOBAL(0x009E2D8C, sint32) = 0; + gHardwareDisplay = gConfigGeneral.hardware_display; + // Create window in window first rather than fullscreen so we have the display the window is on first gWindow = SDL_CreateWindow( "OpenRCT2", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_RESIZABLE @@ -857,13 +860,18 @@ void platform_refresh_video() SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, gConfigGeneral.minimize_fullscreen_focus_loss ? "1" : "0"); - if (gConfigGeneral.hardware_display) { + log_verbose("HardwareDisplay: %s", gHardwareDisplay ? "true" : "false"); + + if (gHardwareDisplay) { if (gRenderer == NULL) gRenderer = SDL_CreateRenderer(gWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); if (gRenderer == NULL) { - log_fatal("SDL_CreateRenderer %s", SDL_GetError()); - exit(-1); + log_warning("SDL_CreateRenderer failed: %s", SDL_GetError()); + log_warning("Falling back to software rendering..."); + gHardwareDisplay = false; + platform_refresh_video(); // try again without hardware rendering + return; } if (gBufferTexture != NULL) diff --git a/src/windows/options.c b/src/windows/options.c index 68d69f3d69..696b6b90c3 100644 --- a/src/windows/options.c +++ b/src/windows/options.c @@ -493,7 +493,16 @@ static void window_options_mouseup(rct_window *w, int widgetIndex) break; case WIDX_HARDWARE_DISPLAY_CHECKBOX: gConfigGeneral.hardware_display ^= 1; +#ifdef _WIN32 + // Windows is apparently able to switch to hardware rendering on the fly although + // using the same window in an unaccelerated and accelerated context is unsupported by SDL2 + gHardwareDisplay = gConfigGeneral.hardware_display; platform_refresh_video(); +#else + // Linux requires a restart. This could be improved in the future by recreating the window, + // https://github.com/OpenRCT2/OpenRCT2/issues/2015 + window_error_open(STR_RESTART_REQUIRED, STR_NONE); +#endif config_save_default(); window_invalidate(w); break;