From 2aeb0b079e98bb7e525d9313f2ad1536e54d8aca Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Tue, 10 Aug 2021 18:14:02 +0200 Subject: [PATCH] Implement aspect_ratio and scaling integer to PS2 --- gfx/drivers/ps2_gfx.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/gfx/drivers/ps2_gfx.c b/gfx/drivers/ps2_gfx.c index 9ff2cb5f44..1442e8ae22 100644 --- a/gfx/drivers/ps2_gfx.c +++ b/gfx/drivers/ps2_gfx.c @@ -37,7 +37,6 @@ typedef struct ps2_video * to be used in the font driver*/ bool clearVRAM_font; bool menuVisible; - bool fullscreen; bool vsync; int vsync_callback_id; bool force_aspect; @@ -187,20 +186,31 @@ static void set_texture(GSTEXTURE *texture, const void *frame, texture->Mem = (void *)frame; } -static void prim_texture(GSGLOBAL *gsGlobal, GSTEXTURE *texture, int zPosition, bool force_aspect, struct retro_hw_ps2_insets padding) +static void prim_texture(GSGLOBAL *gsGlobal, GSTEXTURE *texture, int zPosition, float aspect_ratio, bool scale_integer, struct retro_hw_ps2_insets padding) { float x1, y1, x2, y2; float visible_width = texture->Width - padding.left - padding.right; float visible_height = texture->Height - padding.top - padding.bottom; - if (force_aspect) + if (scale_integer) { float width_proportion = (float)gsGlobal->Width / (float)visible_width; float height_proportion = (float)gsGlobal->Height / (float)visible_height; - float delta = MIN(width_proportion, height_proportion); + int delta = MIN(width_proportion, height_proportion); float newWidth = visible_width * delta; float newHeight = visible_height * delta; + x1 = (gsGlobal->Width - newWidth) / 2.0f; + y1 = (gsGlobal->Height - newHeight) / 2.0f; + x2 = newWidth + x1; + y2 = newHeight + y1; + } + else if (aspect_ratio > 0) + { + float gs_aspect_ratio = (float)gsGlobal->Width / (float)gsGlobal->Height; + float newWidth = (gs_aspect_ratio > aspect_ratio) ? gsGlobal->Height * aspect_ratio : gsGlobal->Width; + float newHeight = (gs_aspect_ratio > aspect_ratio) ? gsGlobal->Height : gsGlobal->Width / aspect_ratio; + x1 = (gsGlobal->Width - newWidth) / 2.0f; y1 = (gsGlobal->Height - newHeight) / 2.0f; x2 = newWidth + x1; @@ -263,7 +273,6 @@ static void *ps2_gfx_init(const video_info_t *video, FONT_DRIVER_RENDER_PS2); ps2->PSM = (video->rgb32 ? GS_PSM_CT32 : GS_PSM_CT16); - ps2->fullscreen = video->fullscreen; ps2->core_filter = video->smooth ? GS_FILTER_LINEAR : GS_FILTER_NEAREST; ps2->force_aspect = video->force_aspect; ps2->vsync = video->vsync; @@ -288,6 +297,7 @@ static bool ps2_gfx_frame(void *data, const void *frame, struct font_params *osd_params = (struct font_params*) &video_info->osd_stat_params; bool statistics_show = video_info->statistics_show; + settings_t *settings = config_get_ptr(); if (!width || !height) return false; @@ -317,13 +327,16 @@ static bool ps2_gfx_frame(void *data, const void *frame, padding = ps2->iface.padding; } + float aspect_ratio = ps2->force_aspect ? video_driver_get_aspect_ratio() : 0; + bool scale_integer = settings->bools.video_scale_integer; + /* Disable Alpha for cores */ ps2->gsGlobal->PrimAlphaEnable = GS_SETTING_OFF; gsKit_set_test(ps2->gsGlobal, GS_ATEST_OFF); gsKit_TexManager_invalidate(ps2->gsGlobal, ps2->coreTexture); gsKit_TexManager_bind(ps2->gsGlobal, ps2->coreTexture); - prim_texture(ps2->gsGlobal, ps2->coreTexture, 1, ps2->force_aspect, padding); + prim_texture(ps2->gsGlobal, ps2->coreTexture, 1, aspect_ratio, scale_integer, padding); } if (ps2->menuVisible) @@ -331,7 +344,7 @@ static bool ps2_gfx_frame(void *data, const void *frame, bool texture_empty = !ps2->menuTexture->Width || !ps2->menuTexture->Height; if (!texture_empty) { - prim_texture(ps2->gsGlobal, ps2->menuTexture, 2, ps2->fullscreen, empty_ps2_insets); + prim_texture(ps2->gsGlobal, ps2->menuTexture, 2, 0, 0, empty_ps2_insets); } } else if (statistics_show) @@ -418,7 +431,6 @@ static void ps2_set_texture_enable(void *data, bool enable, bool fullscreen) gsKit_clear(ps2->gsGlobal, GS_BLACK); } ps2->menuVisible = enable; - ps2->fullscreen = fullscreen; } static void ps2_set_osd_msg(void *data,