From 03f081ace6eebe1dd69ded1871d59b6120a9978e Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Tue, 22 May 2012 18:23:58 +0200 Subject: [PATCH] (PS3) Automatic aspect ratio based on game width/height works now --- console/console_ext.c | 19 +++++++++++++++++++ console/console_ext.h | 2 ++ ps3/main.c | 2 ++ ps3/ps3_video_psgl.c | 8 ++++++++ 4 files changed, 31 insertions(+) diff --git a/console/console_ext.c b/console/console_ext.c index c14ec51f6b..3f54d6fddb 100644 --- a/console/console_ext.c +++ b/console/console_ext.c @@ -490,6 +490,25 @@ struct aspect_ratio_elem aspectratio_lut[ASPECT_RATIO_END] = { { "Custom", 0.0f } }; +void rarch_set_auto_viewport(unsigned width, unsigned height) +{ + unsigned aspect_x, aspect_y, len, highest, i; + + len = width < height ? width : height; + highest = 1; + for (i = 1; i < len; i++) + { + if ((width % i) == 0 && (height % i) == 0) + highest = i; + } + + aspect_x = width / highest; + aspect_y = height / highest; + + snprintf(aspectratio_lut[ASPECT_RATIO_AUTO].name, sizeof(aspectratio_lut[ASPECT_RATIO_AUTO].name), "%d:%d (Auto)", aspect_x, aspect_y); + aspectratio_lut[ASPECT_RATIO_AUTO].value = (int)aspect_x / (int)aspect_y; +} + /*============================================================ LIBRETRO ============================================================ */ diff --git a/console/console_ext.h b/console/console_ext.h index 51a91776e9..d3f3da52d9 100644 --- a/console/console_ext.h +++ b/console/console_ext.h @@ -61,6 +61,8 @@ struct aspect_ratio_elem extern struct aspect_ratio_elem aspectratio_lut[ASPECT_RATIO_END]; +extern void rarch_set_auto_viewport(unsigned width, unsigned height); + #include "console_ext_input.h" /*============================================================ diff --git a/ps3/main.c b/ps3/main.c index 3536ee7cfb..53184e5247 100644 --- a/ps3/main.c +++ b/ps3/main.c @@ -523,6 +523,8 @@ begin_loop: input_ps3.poll(NULL); + rarch_set_auto_viewport(g_extern.frame_cache.width, g_extern.frame_cache.height); + do{ repeat = rarch_main_iterate(); }while(repeat && !g_console.frame_advance_enable); diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index a8259e826a..1ba26c14a2 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -557,6 +557,9 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei GLfloat yamt = (GLfloat)height / gl->tex_h; set_texture_coords(gl->tex_coords, xamt, yamt); + + if(g_console.aspect_ratio_index == ASPECT_RATIO_AUTO ) + rarch_set_auto_viewport(width, height); } else if (width != gl->last_width[(gl->tex_index - 1) & TEXTURES_MASK] || height != gl->last_height[(gl->tex_index - 1) & TEXTURES_MASK]) { @@ -983,9 +986,14 @@ static void ps3graphics_set_aspect_ratio(void * data, uint32_t aspectratio_index (void)data; gl_t * gl = g_gl; + if(g_console.aspect_ratio_index == ASPECT_RATIO_AUTO) + rarch_set_auto_viewport(g_extern.frame_cache.width, g_extern.frame_cache.height); + g_settings.video.aspect_ratio = aspectratio_lut[g_console.aspect_ratio_index].value; g_settings.video.force_aspect = false; gl->keep_aspect = true; + + set_viewport(gl, gl->win_width, gl->win_height); }