Implement aspect_ratio and scaling integer to PS2

This commit is contained in:
Francisco Javier Trujillo Mata 2021-08-10 18:14:02 +02:00
parent 9cd5e66b21
commit 2aeb0b079e

View File

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