Require a restart after changing hardware rendering setting, decouple setting from active status

This commit is contained in:
Jonathan Haas 2015-10-07 20:30:50 +02:00
parent 7e753afe52
commit 475466dcd9
5 changed files with 28 additions and 5 deletions

View File

@ -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 #

View File

@ -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
};

View File

@ -90,6 +90,8 @@ extern int gNumResolutions;
extern resolution *gResolutions;
extern SDL_Window *gWindow;
extern bool gHardwareDisplay;
extern bool gSteamOverlayActive;
// Platform shared definitions

View File

@ -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)

View File

@ -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;