From 3d2f3bda64a63addf8a55b80806cc6ad3751d3a1 Mon Sep 17 00:00:00 2001 From: Marc Date: Thu, 18 Mar 2021 21:37:36 +0000 Subject: [PATCH 1/2] Fixes a resolution switching issue when the game uses **only** OpenGL as the renderer Canvas.tscript fixes provided by @OTHG_Mars --- Engine/source/gfx/gl/sdl/gfxGLDevice.sdl.cpp | 11 ++++++++- .../game/core/gui/scripts/canvas.tscript | 24 +++++++++++++++---- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/Engine/source/gfx/gl/sdl/gfxGLDevice.sdl.cpp b/Engine/source/gfx/gl/sdl/gfxGLDevice.sdl.cpp index 785c1c9c3..a74be76ca 100644 --- a/Engine/source/gfx/gl/sdl/gfxGLDevice.sdl.cpp +++ b/Engine/source/gfx/gl/sdl/gfxGLDevice.sdl.cpp @@ -58,7 +58,16 @@ void EnumerateVideoModes(Vector& outModes) GFXVideoMode outMode; outMode.resolution.set( mode.w, mode.h ); outMode.refreshRate = mode.refresh_rate; - outMode.bitDepth = SDL_BYTESPERPIXEL( mode.format ); + + // BBP = 32 for some reason the engine knows it should be 32, but then we + // add some extra code to break what the engine knows. + //outMode.bitDepth = SDL_BYTESPERPIXEL( mode.format ); // sets bitdepths to 4 + //outMode.bitDepth = SDL_BITSPERPIXEL(mode.format); // sets bitdepth to 24 + + // hardcoded magic numbers ftw + // This value is hardcoded in DX, probably to avoid the shenanigans going on here + outMode.bitDepth = 32; + outMode.wideScreen = (mode.w / mode.h) > (4 / 3); outMode.fullScreen = true; diff --git a/Templates/BaseGame/game/core/gui/scripts/canvas.tscript b/Templates/BaseGame/game/core/gui/scripts/canvas.tscript index 51a2cd55f..818447de5 100644 --- a/Templates/BaseGame/game/core/gui/scripts/canvas.tscript +++ b/Templates/BaseGame/game/core/gui/scripts/canvas.tscript @@ -155,6 +155,10 @@ function GuiCanvas::prefsToModeStr(%this) function GuiCanvas::checkCanvasRes(%this, %mode, %deviceId, %deviceMode, %startup) { + // Toggle for selecting the borderless window allowed sizes. Set true to allow + // boderless windows to be less than the device res. + %allowSmallBorderless = true; + %resX = getWord(%mode, $WORD::RES_X); %resY = getWord(%mode, $WORD::RES_Y); @@ -175,6 +179,9 @@ function GuiCanvas::checkCanvasRes(%this, %mode, %deviceId, %deviceMode, %startu if ((%resX > %deviceRect.x) || (%resY > %deviceRect.y)) return false; + if (!%allowSmallBorderless && ((%resX != %deviceRect.x) || (%resY != %deviceRect.y))) + return false; + return true; } @@ -202,7 +209,8 @@ function GuiCanvas::checkCanvasRes(%this, %mode, %deviceId, %deviceMode, %startu return false; } -// Find the best video mode setting for the device and display mode +// Find the best video mode setting for the device and display mode. +// "Best" is the largest resolution that will fit at highest refresh rate. function GuiCanvas::getBestCanvasRes(%this, %deviceId, %deviceMode) { if (%deviceMode == $Video::ModeWindowed) @@ -210,19 +218,25 @@ function GuiCanvas::getBestCanvasRes(%this, %deviceId, %deviceMode) else %deviceRect = getWords(%this.getMonitorRect(%deviceId), 2); + %bestRes = ""; %resCount = %this.getModeCount(); for (%i = %resCount - 1; %i >= 0; %i--) { %testRes = %this.getMode(%i); %resX = getWord(%testRes, $WORD::RES_X); %resY = getWord(%testRes, $WORD::RES_Y); + %rate = getWord(%testRes, $WORD::REFRESH); - if ((%resX > %deviceRect.x) || (%resY > %deviceRect.y)) + if ((%resX > %deviceRect.x) || (%resY > %deviceRect.y) || + (%resX < $Video::minimumXResolution) || (%resY < $Video::minimumYResolution)) continue; - return %testRes; + if (((%bestRes $= "") || (%resX > getWord(%bestRes, $WORD::RES_X)) || + (%resY > getWord(%bestRes, $WORD::RES_Y))) || + ((%resX == getWord(%bestRes, $WORD::RES_X)) && (%resY == getWord(%bestRes, $WORD::RES_Y)) && + (%rate > getWord(%bestRes, $WORD::REFRESH)))) + %bestRes = %testRes; } - // Nothing found? return first mode - return %this.getMonitorMode(%deviceId, 0); + return %bestRes; } From 9323bac5ea76a82184f8d1d9e1147b36998bf607 Mon Sep 17 00:00:00 2001 From: Brian Roberts Date: Tue, 13 Apr 2021 16:53:31 -0500 Subject: [PATCH 2/2] Update Templates/BaseGame/game/core/gui/scripts/canvas.tscript Co-authored-by: Lukas Joergensen --- Templates/BaseGame/game/core/gui/scripts/canvas.tscript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Templates/BaseGame/game/core/gui/scripts/canvas.tscript b/Templates/BaseGame/game/core/gui/scripts/canvas.tscript index 818447de5..9f040f1e9 100644 --- a/Templates/BaseGame/game/core/gui/scripts/canvas.tscript +++ b/Templates/BaseGame/game/core/gui/scripts/canvas.tscript @@ -156,7 +156,7 @@ function GuiCanvas::prefsToModeStr(%this) function GuiCanvas::checkCanvasRes(%this, %mode, %deviceId, %deviceMode, %startup) { // Toggle for selecting the borderless window allowed sizes. Set true to allow - // boderless windows to be less than the device res. + // borderless windows to be less than the device res. %allowSmallBorderless = true; %resX = getWord(%mode, $WORD::RES_X);