From a328dbd21315b0f4a124aab511418e8a7c94d043 Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Thu, 2 Feb 2012 18:39:09 +0100 Subject: [PATCH] (PS3) Overscan options added --- general.h | 2 ++ ps3/main.c | 25 ++++++++++++++++- ps3/menu.c | 32 ++++++++++++++++++++++ ps3/ps3_video_psgl.c | 65 +++++++++++++++++++++++++++++++++++--------- ps3/ps3_video_psgl.h | 1 + 5 files changed, 111 insertions(+), 14 deletions(-) diff --git a/general.h b/general.h index 198f833e01..aff038ba5d 100644 --- a/general.h +++ b/general.h @@ -175,10 +175,12 @@ struct console_settings bool default_savestate_dir_enable; bool ingame_menu_enable; bool menu_enable; + bool overscan_enable; bool return_to_multiman_enable; bool screenshots_enable; bool throttle_enable; bool triple_buffering_enable; + float overscan_amount; uint32_t aspect_ratio_index; uint32_t screen_orientation; uint32_t current_resolution_index; diff --git a/ps3/main.c b/ps3/main.c index 41eaf9e20f..a1e5113325 100644 --- a/ps3/main.c +++ b/ps3/main.c @@ -170,6 +170,8 @@ static void set_default_settings(void) g_console.aspect_ratio_index = 0; strlcpy(g_console.aspect_ratio_name, "4:3", sizeof(g_console.aspect_ratio_name)); g_console.menu_font_size = 1.0f; + g_console.overscan_enable = false; + g_console.overscan_amount = 0.0f; // g_extern g_extern.state_slot = 0; @@ -205,6 +207,7 @@ static void init_settings(void) // g_console + CONFIG_GET_BOOL_CONSOLE(overscan_enable, "overscan_enable"); CONFIG_GET_BOOL_CONSOLE(screenshots_enable, "screenshots_enable"); CONFIG_GET_BOOL_CONSOLE(throttle_enable, "throttle_enable"); CONFIG_GET_BOOL_CONSOLE(triple_buffering_enable, "triple_buffering_enable"); @@ -214,6 +217,7 @@ static void init_settings(void) CONFIG_GET_STRING_CONSOLE(aspect_ratio_name, "aspect_ratio_name"); CONFIG_GET_STRING_CONSOLE(default_rom_startup_dir, "default_rom_startup_dir"); CONFIG_GET_FLOAT_CONSOLE(menu_font_size, "menu_font_size"); + CONFIG_GET_FLOAT_CONSOLE(overscan_amount, "overscan_amount"); // g_extern CONFIG_GET_INT_EXTERN(state_slot, "state_slot"); @@ -248,6 +252,7 @@ static void save_settings(void) config_set_bool(conf, "video_vsync", g_settings.video.vsync); // g_console + config_set_bool(conf, "overscan_enable", g_console.overscan_enable); config_set_bool(conf, "screenshots_enable", g_console.screenshots_enable); config_set_bool(conf, "throttle_enable", g_console.throttle_enable); config_set_bool(conf, "triple_buffering_enable", g_console.triple_buffering_enable); @@ -257,6 +262,7 @@ static void save_settings(void) config_set_string(conf, "aspect_ratio_name", g_console.aspect_ratio_name); config_set_string(conf, "default_rom_startup_dir", g_console.default_rom_startup_dir); config_set_float(conf, "menu_font_size", g_console.menu_font_size); + config_set_float(conf, "overscan_amount", g_console.overscan_amount); // g_extern config_set_int(conf, "state_slot", g_extern.state_slot); @@ -486,12 +492,28 @@ static void ingame_menu(void) case MENU_ITEM_OVERSCAN_AMOUNT: if(CTRL_LEFT(button_was_pressed) || CTRL_LSTICK_LEFT(button_was_pressed) || CTRL_CROSS(button_was_pressed) || CTRL_LSTICK_LEFT(button_was_held)) { + g_console.overscan_amount -= 0.01f; + g_console.overscan_enable = true; + + if(g_console.overscan_amount == 0.00f) + g_console.overscan_enable = false; + + ps3graphics_set_overscan(g_console.overscan_enable, g_console.overscan_amount, 1); } if(CTRL_RIGHT(button_was_pressed) || CTRL_LSTICK_RIGHT(button_was_pressed) || CTRL_CROSS(button_was_pressed) || CTRL_LSTICK_RIGHT(button_was_held)) { + g_console.overscan_amount += 0.01f; + g_console.overscan_enable = true; + if(g_console.overscan_amount == 0.0f) + g_console.overscan_amount = false; + + ps3graphics_set_overscan(g_console.overscan_enable, g_console.overscan_amount, 1); } if(CTRL_START(button_was_pressed)) { + g_console.overscan_amount = 0.0f; + g_console.overscan_enable = false; + ps3graphics_set_overscan(g_console.overscan_enable, g_console.overscan_amount, 1); } ingame_menu_reset_entry_colors (ingame_menu_item); strcpy(comment, "Press LEFT or RIGHT to change the [Overscan] settings.\nPress START to reset back to default values."); @@ -657,7 +679,8 @@ static void ingame_menu(void) cellDbgFontPrintf (x_position, (ypos+(ypos_increment*MENU_ITEM_KEEP_ASPECT_RATIO)), font_size+0.01f, BLUE, "Aspect Ratio: %s", g_console.aspect_ratio_name); cellDbgFontPrintf(x_position, (ypos+(ypos_increment*MENU_ITEM_KEEP_ASPECT_RATIO)), font_size, menuitem_colors[MENU_ITEM_KEEP_ASPECT_RATIO], "Aspect Ratio: %s", g_console.aspect_ratio_name); - cellDbgFontPrintf(x_position, (ypos+(ypos_increment*MENU_ITEM_OVERSCAN_AMOUNT)), font_size, menuitem_colors[MENU_ITEM_OVERSCAN_AMOUNT], "Overscan: "); + cellDbgFontPrintf(x_position, (ypos+(ypos_increment*MENU_ITEM_OVERSCAN_AMOUNT)), font_size+0.01f, BLUE, "Overscan: %f", g_console.overscan_amount); + cellDbgFontPrintf(x_position, (ypos+(ypos_increment*MENU_ITEM_OVERSCAN_AMOUNT)), font_size, menuitem_colors[MENU_ITEM_OVERSCAN_AMOUNT], "Overscan: %f", g_console.overscan_amount); cellDbgFontPrintf (x_position, (ypos+(ypos_increment*MENU_ITEM_ORIENTATION)), font_size+0.01f, BLUE, "Orientation: "); cellDbgFontPrintf (x_position, (ypos+(ypos_increment*MENU_ITEM_ORIENTATION)), font_size, menuitem_colors[MENU_ITEM_ORIENTATION], "Orientation: %s", msg_temp); diff --git a/ps3/menu.c b/ps3/menu.c index c7b654cefa..6e0abe398a 100644 --- a/ps3/menu.c +++ b/ps3/menu.c @@ -417,6 +417,12 @@ static void set_setting_label(menu * menu_obj, int currentsetting) snprintf(menu_obj->items[currentsetting].comment, sizeof(menu_obj->items[currentsetting].comment), "INFO - [Custom Scaling Factor] is set to: '%fx (X) / %fx (Y)'.", g_settings.video.fbo_scale_x, g_settings.video.fbo_scale_y); break; case SETTING_HW_OVERSCAN_AMOUNT: + if(g_console.overscan_amount == 0.0f) + menu_obj->items[currentsetting].text_color = GREEN; + else + menu_obj->items[currentsetting].text_color = ORANGE; + + snprintf(menu_obj->items[currentsetting].setting_text, sizeof(menu_obj->items[currentsetting].setting_text), "%f", g_console.overscan_amount); break; case SETTING_THROTTLE_MODE: if(g_console.throttle_enable) @@ -1125,6 +1131,32 @@ static void producesettingentry(menu * menu_obj, uint64_t switchvalue) } break; case SETTING_HW_OVERSCAN_AMOUNT: + if(CTRL_LEFT(state) || CTRL_LSTICK_LEFT(state) || CTRL_CROSS(state)) + { + g_console.overscan_amount -= 0.01f; + g_console.overscan_enable = true; + + if(g_console.overscan_amount == 0.0f) + g_console.overscan_enable = false; + + ps3graphics_set_overscan(g_console.overscan_enable, g_console.overscan_amount, 1); + } + if(CTRL_RIGHT(state) || CTRL_LSTICK_RIGHT(state) || CTRL_CROSS(state)) + { + g_console.overscan_amount += 0.01f; + g_console.overscan_enable = true; + + if(g_console.overscan_amount == 0.0f) + g_console.overscan_enable = 0; + + ps3graphics_set_overscan(g_console.overscan_enable, g_console.overscan_amount, 1); + } + if(CTRL_START(state)) + { + g_console.overscan_amount = 0.0f; + g_console.overscan_enable = false; + ps3graphics_set_overscan(g_console.overscan_enable, g_console.overscan_amount, 1); + } break; case SETTING_THROTTLE_MODE: if(CTRL_LEFT(state) || CTRL_LSTICK_LEFT(state) || CTRL_RIGHT(state) || CTRL_LSTICK_RIGHT(state)) diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index cc90bd6db6..237537d956 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -119,6 +119,7 @@ typedef struct gl bool render_to_tex; bool should_resize; bool vsync; + bool overscan_enable; int fbo_pass; unsigned base_size; /* 2 or 4*/ unsigned last_width[TEXTURES]; @@ -129,6 +130,7 @@ typedef struct gl unsigned vp_height, vp_out_height; unsigned win_width; unsigned win_height; + GLfloat overscan_amount; GLfloat tex_coords[8]; GLfloat fbo_tex_coords[8]; GLenum texture_type; /* XBGR1555 or ARGB*/ @@ -487,37 +489,55 @@ static inline unsigned get_alignment(unsigned pitch) static void set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_full) { + uint32_t m_viewport_x_temp, m_viewport_y_temp, m_viewport_width_temp, m_viewport_height_temp; + GLfloat m_left, m_right, m_bottom, m_top, m_zNear, m_zFar; + glMatrixMode(GL_PROJECTION); glLoadIdentity(); + m_viewport_x_temp = 0; + m_viewport_y_temp = 0; + m_viewport_width_temp = width; + m_viewport_height_temp = height; + + m_left = 0.0f; + m_right = 1.0f; + m_bottom = 0.0f; + m_top = 1.0f; + m_zNear = -1.0f; + m_zFar = 1.0f; + if (gl->keep_aspect && !force_full) { float desired_aspect = g_settings.video.aspect_ratio; float device_aspect = (float)width / height; + float delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5; // If the aspect ratios of screen and desired aspect ratio are sufficiently equal (floating point stuff), - // assume they are actually equal. - if (fabs(device_aspect - desired_aspect) < 0.0001) + if (device_aspect > desired_aspect) { - glViewport(0, 0, width, height); - } - else if (device_aspect > desired_aspect) - { - float delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5; - glViewport((GLint)(width * (0.5 - delta)), 0,(GLint)(2.0 * width * delta), height); + m_viewport_x_temp = (GLint)(width * (0.5 - delta)); + m_viewport_width_temp = (GLint)(2.0 * width * delta); width = (unsigned)(2.0 * width * delta); } else { - float delta = (device_aspect / desired_aspect - 1.0) / 2.0 + 0.5; - glViewport(0, (GLint)(height * (0.5 - delta)), width,(GLint)(2.0 * height * delta)); + m_viewport_y_temp = (GLint)(height * (0.5 - delta)); + m_viewport_height_temp = (GLint)(2.0 * height * delta); height = (unsigned)(2.0 * height * delta); } } - else - glViewport(0, 0, width, height); - glOrthof(0.0, 1.0, 0.0, 1.0, -1.0, 1.0); + glViewport(m_viewport_x_temp, m_viewport_y_temp, m_viewport_width_temp, m_viewport_height_temp); + + if(gl->overscan_enable && !force_full) + { + m_left = -gl->overscan_amount/2; + m_right = 1 + gl->overscan_amount/2; + m_bottom = -gl->overscan_amount/2; + } + + glOrthof(m_left, m_right, m_bottom, m_top, m_zNear, m_zFar); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -1290,6 +1310,19 @@ void ps3_set_filtering(unsigned index, bool set_smooth) glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); } +void ps3graphics_set_overscan(bool overscan_enable, float amount, bool recalculate_viewport) +{ + gl_t * gl = g_gl; + if(!gl) + return; + + gl->overscan_enable = overscan_enable; + gl->overscan_amount = amount; + + if(recalculate_viewport) + set_viewport(gl, gl->win_width, gl->win_height, false); +} + void ps3graphics_set_aspect_ratio(uint32_t aspectratio_index) { gl_t * gl = g_gl; @@ -1370,10 +1403,16 @@ void ps3graphics_video_init(bool get_all_resolutions) video_info.input_scale = 2; g_gl = gl_init(&video_info, NULL, NULL); + gl_t * gl = g_gl; + + gl->overscan_enable = g_console.overscan_enable; + gl->overscan_amount = g_console.overscan_amount; + if(get_all_resolutions) get_all_available_resolutions(); ps3_set_resolution(); ps3_setup_texture(); + ps3graphics_set_overscan(gl->overscan_enable, gl->overscan_amount, 0); } void ps3graphics_video_reinit(void) diff --git a/ps3/ps3_video_psgl.h b/ps3/ps3_video_psgl.h index b43d6198b8..64f88bd7af 100644 --- a/ps3/ps3_video_psgl.h +++ b/ps3/ps3_video_psgl.h @@ -52,6 +52,7 @@ void ps3_video_deinit(void); void ps3graphics_block_swap (void); void ps3graphics_reinit_fbos (void); void ps3graphics_set_aspect_ratio(uint32_t aspectratio_index); +void ps3graphics_set_overscan(bool overscan_enable, float amount, bool recalculate_viewport); void ps3graphics_set_orientation(uint32_t orientation); void ps3graphics_set_vsync(uint32_t vsync); void ps3graphics_unblock_swap (void);