ability to set max resolution in config, option to change display resolution (#1661)

This commit is contained in:
Roman Fomin 2024-04-25 09:22:54 +00:00 committed by GitHub
parent 2f98be6785
commit e4678509e8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 74 additions and 22 deletions

View File

@ -70,6 +70,7 @@ boolean uncapped, default_uncapped; // [FG] uncapped rendering frame rate
int fpslimit; // when uncapped, limit framerate to this value int fpslimit; // when uncapped, limit framerate to this value
boolean fullscreen; boolean fullscreen;
boolean exclusive_fullscreen; boolean exclusive_fullscreen;
boolean change_display_resolution;
aspect_ratio_mode_t widescreen, default_widescreen; // widescreen mode aspect_ratio_mode_t widescreen, default_widescreen; // widescreen mode
int custom_fov; int custom_fov;
boolean vga_porch_flash; // emulate VGA "porch" behaviour boolean vga_porch_flash; // emulate VGA "porch" behaviour
@ -106,10 +107,10 @@ static int window_x, window_y;
static int actualheight; static int actualheight;
static int unscaled_actualheight; static int unscaled_actualheight;
static int native_width; int max_video_width, max_video_height;
static int native_height; static int max_width, max_height;
static int native_height_adjusted; static int max_height_adjusted;
static int native_refresh_rate; static int display_refresh_rate;
static boolean use_limiter; static boolean use_limiter;
static int targetrefresh; static int targetrefresh;
@ -407,7 +408,7 @@ static void UpdateLimiter(void)
{ {
if (uncapped) if (uncapped)
{ {
if (fpslimit >= native_refresh_rate && native_refresh_rate > 0 if (fpslimit >= display_refresh_rate && display_refresh_rate > 0
&& use_vsync) && use_vsync)
{ {
// SDL will limit framerate using vsync. // SDL will limit framerate using vsync.
@ -1144,8 +1145,8 @@ static double CurrentAspectRatio(void)
h = unscaled_actualheight; h = unscaled_actualheight;
break; break;
case RATIO_AUTO: case RATIO_AUTO:
w = native_width; w = max_width;
h = native_height; h = max_height;
break; break;
case RATIO_16_10: case RATIO_16_10:
w = 16; w = 16;
@ -1355,7 +1356,7 @@ static void I_ResetTargetRefresh(void)
if (uncapped) if (uncapped)
{ {
// SDL may report native refresh rate as zero. // SDL may report native refresh rate as zero.
targetrefresh = (fpslimit >= TICRATE) ? fpslimit : native_refresh_rate; targetrefresh = (fpslimit >= TICRATE) ? fpslimit : display_refresh_rate;
} }
else else
{ {
@ -1381,22 +1382,41 @@ static void I_InitVideoParms(void)
I_Error("Error getting display mode: %s", SDL_GetError()); I_Error("Error getting display mode: %s", SDL_GetError());
} }
native_width = mode.w; if (max_video_width && max_video_height)
native_height = mode.h; {
if (use_aspect && max_video_height < ACTUALHEIGHT)
{
I_Error("The vertical resolution is too low, turn off the aspect "
"ratio correction.");
}
double aspect_ratio =
(double)max_video_width / (double)max_video_height;
if (aspect_ratio < ASPECT_RATIO_MIN)
{
I_Error("Aspect ratio not supported, set other resolution");
}
max_width = max_video_width;
max_height = max_video_height;
}
else
{
max_width = mode.w;
max_height = mode.h;
}
if (use_aspect) if (use_aspect)
{ {
native_height_adjusted = (int)(native_height / 1.2); max_height_adjusted = (int)(max_height / 1.2);
unscaled_actualheight = ACTUALHEIGHT; unscaled_actualheight = ACTUALHEIGHT;
} }
else else
{ {
native_height_adjusted = native_height; max_height_adjusted = max_height;
unscaled_actualheight = SCREENHEIGHT; unscaled_actualheight = SCREENHEIGHT;
} }
// SDL may report native refresh rate as zero. // SDL may report native refresh rate as zero.
native_refresh_rate = mode.refresh_rate; display_refresh_rate = mode.refresh_rate;
current_video_height = default_current_video_height; current_video_height = default_current_video_height;
window_width = default_window_width; window_width = default_window_width;
@ -1528,14 +1548,23 @@ static void I_InitGraphicsMode(void)
{ {
if (exclusive_fullscreen) if (exclusive_fullscreen)
{ {
SDL_DisplayMode mode; if (change_display_resolution && max_video_width
if (SDL_GetCurrentDisplayMode(video_display, &mode) != 0) && max_video_height)
{ {
I_Error("Could not get display mode for video display #%d: %s", w = max_video_width;
video_display, SDL_GetError()); h = max_video_height;
}
else
{
SDL_DisplayMode mode;
if (SDL_GetCurrentDisplayMode(video_display, &mode) != 0)
{
I_Error("Could not get display mode for video display #%d: %s",
video_display, SDL_GetError());
}
w = mode.w;
h = mode.h;
} }
w = mode.w;
h = mode.h;
// [FG] exclusive fullscreen // [FG] exclusive fullscreen
flags |= SDL_WINDOW_FULLSCREEN; flags |= SDL_WINDOW_FULLSCREEN;
} }
@ -1610,7 +1639,7 @@ static void I_InitGraphicsMode(void)
void I_GetResolutionScaling(resolution_scaling_t *rs) void I_GetResolutionScaling(resolution_scaling_t *rs)
{ {
rs->max = native_height_adjusted; rs->max = max_height_adjusted;
rs->step = 50; rs->step = 50;
} }
@ -1622,7 +1651,7 @@ static int GetCurrentVideoHeight(void)
} }
current_video_height = current_video_height =
BETWEEN(SCREENHEIGHT, native_height_adjusted, current_video_height); BETWEEN(SCREENHEIGHT, max_height_adjusted, current_video_height);
return current_video_height; return current_video_height;
} }

View File

@ -71,9 +71,10 @@ extern boolean drs_skip_frame;
extern boolean use_vsync; // killough 2/8/98: controls whether vsync is called extern boolean use_vsync; // killough 2/8/98: controls whether vsync is called
extern boolean disk_icon; // killough 10/98 extern boolean disk_icon; // killough 10/98
extern int max_video_width, max_video_height;
extern int current_video_height, default_current_video_height; extern int current_video_height, default_current_video_height;
# define DRS_MIN_HEIGHT 400 #define DRS_MIN_HEIGHT 400
extern boolean dynamic_resolution; extern boolean dynamic_resolution;
extern boolean use_aspect; extern boolean use_aspect;
@ -82,6 +83,7 @@ extern boolean uncapped,
extern boolean fullscreen; extern boolean fullscreen;
extern boolean exclusive_fullscreen; extern boolean exclusive_fullscreen;
extern boolean change_display_resolution;
extern int fpslimit; // when uncapped, limit framerate to this value extern int fpslimit; // when uncapped, limit framerate to this value
extern int fps; extern int fps;
extern boolean vga_porch_flash; // emulate VGA "porch" behaviour extern boolean vga_porch_flash; // emulate VGA "porch" behaviour

View File

@ -215,6 +215,27 @@ default_t defaults[] = {
"current video display index" "current video display index"
}, },
{
"max_video_width",
(config_t *) &max_video_width, NULL,
{0}, {SCREENWIDTH, UL}, number, ss_none, wad_no,
"maximum horizontal resolution (native by default)"
},
{
"max_video_height",
(config_t *) &max_video_height, NULL,
{0}, {SCREENHEIGHT, UL}, number, ss_none, wad_no,
"maximum vertical resolution (native by default)"
},
{
"change_display_resolution",
(config_t *) &change_display_resolution, NULL,
{0}, {0, 1}, number, ss_none, wad_no,
"1 to change display resolution with exclusive fullscreen (make sense only with CRT)"
},
// window position // window position
{ {
"window_position_x", "window_position_x",