(PS3) FBO changes - no more needless deinit when not necessary

This commit is contained in:
Twinaphex 2012-05-06 20:05:13 +02:00
parent cfe5ce5286
commit 959a0ea809
5 changed files with 31 additions and 40 deletions

View File

@ -188,6 +188,7 @@ struct console_settings
bool block_config_read; bool block_config_read;
bool default_sram_dir_enable; bool default_sram_dir_enable;
bool default_savestate_dir_enable; bool default_savestate_dir_enable;
bool fbo_enabled;
bool frame_advance_enable; bool frame_advance_enable;
bool gamma_correction_enable; bool gamma_correction_enable;
bool initialize_rarch_enable; bool initialize_rarch_enable;

View File

@ -90,7 +90,6 @@ static void set_default_settings(void)
strlcpy(g_settings.video.cg_shader_path, DEFAULT_SHADER_FILE, sizeof(g_settings.video.cg_shader_path)); strlcpy(g_settings.video.cg_shader_path, DEFAULT_SHADER_FILE, sizeof(g_settings.video.cg_shader_path));
g_settings.video.fbo_scale_x = 2.0f; g_settings.video.fbo_scale_x = 2.0f;
g_settings.video.fbo_scale_y = 2.0f; g_settings.video.fbo_scale_y = 2.0f;
g_settings.video.render_to_texture = true;
strlcpy(g_settings.video.second_pass_shader, DEFAULT_SHADER_FILE, sizeof(g_settings.video.second_pass_shader)); strlcpy(g_settings.video.second_pass_shader, DEFAULT_SHADER_FILE, sizeof(g_settings.video.second_pass_shader));
g_settings.video.second_pass_smooth = true; g_settings.video.second_pass_smooth = true;
g_settings.video.smooth = true; g_settings.video.smooth = true;
@ -126,6 +125,7 @@ static void set_default_settings(void)
g_console.triple_buffering_enable = true; g_console.triple_buffering_enable = true;
g_console.default_savestate_dir_enable = false; g_console.default_savestate_dir_enable = false;
g_console.default_sram_dir_enable = false; g_console.default_sram_dir_enable = false;
g_console.fbo_enabled = true;
g_console.mode_switch = MODE_MENU; g_console.mode_switch = MODE_MENU;
g_console.screen_orientation = ORIENTATION_NORMAL; g_console.screen_orientation = ORIENTATION_NORMAL;
g_console.current_resolution_id = CELL_VIDEO_OUT_RESOLUTION_UNDEFINED; g_console.current_resolution_id = CELL_VIDEO_OUT_RESOLUTION_UNDEFINED;
@ -218,6 +218,7 @@ static void init_settings(bool load_libretro_path)
// g_console // g_console
CONFIG_GET_BOOL_CONSOLE(fbo_enabled, "fbo_enabled");
CONFIG_GET_BOOL_CONSOLE(custom_bgm_enable, "custom_bgm_enable"); CONFIG_GET_BOOL_CONSOLE(custom_bgm_enable, "custom_bgm_enable");
CONFIG_GET_BOOL_CONSOLE(overscan_enable, "overscan_enable"); CONFIG_GET_BOOL_CONSOLE(overscan_enable, "overscan_enable");
CONFIG_GET_BOOL_CONSOLE(screenshots_enable, "screenshots_enable"); CONFIG_GET_BOOL_CONSOLE(screenshots_enable, "screenshots_enable");
@ -279,6 +280,7 @@ static void save_settings(void)
} }
// g_console // g_console
config_set_bool(conf, "fbo_enabled", g_console.fbo_enabled);
config_set_bool(conf, "custom_bgm_enable", g_console.custom_bgm_enable); config_set_bool(conf, "custom_bgm_enable", g_console.custom_bgm_enable);
config_set_bool(conf, "overscan_enable", g_console.overscan_enable); config_set_bool(conf, "overscan_enable", g_console.overscan_enable);
config_set_bool(conf, "screenshots_enable", g_console.screenshots_enable); config_set_bool(conf, "screenshots_enable", g_console.screenshots_enable);

View File

@ -457,7 +457,7 @@ static void set_setting_label(menu * menu_obj, uint64_t currentsetting)
} }
break; break;
case SETTING_SCALE_ENABLED: case SETTING_SCALE_ENABLED:
if(g_settings.video.render_to_texture) if(g_console.fbo_enabled)
{ {
snprintf(menu_obj->items[currentsetting].setting_text, sizeof(menu_obj->items[currentsetting].setting_text), "ON"); snprintf(menu_obj->items[currentsetting].setting_text, sizeof(menu_obj->items[currentsetting].setting_text), "ON");
menu_obj->items[currentsetting].text_color = GREEN; menu_obj->items[currentsetting].text_color = GREEN;
@ -1337,19 +1337,15 @@ static void producesettingentry(menu * menu_obj, uint64_t switchvalue)
case SETTING_SCALE_ENABLED: case SETTING_SCALE_ENABLED:
if(CTRL_LEFT(state) || CTRL_LSTICK_LEFT(state) || CTRL_RIGHT(state) || CTRL_LSTICK_RIGHT(state) || CTRL_CROSS(state)) if(CTRL_LEFT(state) || CTRL_LSTICK_LEFT(state) || CTRL_RIGHT(state) || CTRL_LSTICK_RIGHT(state) || CTRL_CROSS(state))
{ {
g_settings.video.render_to_texture = !g_settings.video.render_to_texture; g_console.fbo_enabled = !g_console.fbo_enabled;
gl_set_fbo_enable(g_console.fbo_enabled);
if(g_settings.video.render_to_texture)
apply_scaling(FBO_INIT);
else
apply_scaling(FBO_DEINIT);
set_delay = DELAY_MEDIUM; set_delay = DELAY_MEDIUM;
} }
if(CTRL_START(state)) if(CTRL_START(state))
{ {
g_settings.video.render_to_texture = true; g_console.fbo_enabled = true;
g_settings.video.fbo_scale_x = 2.0f; g_settings.video.fbo_scale_x = 2.0f;
g_settings.video.fbo_scale_y = 2.0f; g_settings.video.fbo_scale_y = 2.0f;
apply_scaling(FBO_DEINIT); apply_scaling(FBO_DEINIT);
@ -1359,7 +1355,7 @@ static void producesettingentry(menu * menu_obj, uint64_t switchvalue)
case SETTING_SCALE_FACTOR: case SETTING_SCALE_FACTOR:
if(CTRL_LEFT(state) || CTRL_LSTICK_LEFT(state)) if(CTRL_LEFT(state) || CTRL_LSTICK_LEFT(state))
{ {
if(g_settings.video.render_to_texture) if(g_console.fbo_enabled)
{ {
if((g_settings.video.fbo_scale_x > MIN_SCALING_FACTOR)) if((g_settings.video.fbo_scale_x > MIN_SCALING_FACTOR))
{ {
@ -1372,7 +1368,7 @@ static void producesettingentry(menu * menu_obj, uint64_t switchvalue)
} }
if(CTRL_RIGHT(state) || CTRL_LSTICK_RIGHT(state) || CTRL_CROSS(state)) if(CTRL_RIGHT(state) || CTRL_LSTICK_RIGHT(state) || CTRL_CROSS(state))
{ {
if(g_settings.video.render_to_texture) if(g_console.fbo_enabled)
{ {
if((g_settings.video.fbo_scale_x < MAX_SCALING_FACTOR)) if((g_settings.video.fbo_scale_x < MAX_SCALING_FACTOR))
{ {
@ -2158,7 +2154,7 @@ static void ingame_menu(uint32_t menu_id)
case MENU_ITEM_SCALE_FACTOR: case MENU_ITEM_SCALE_FACTOR:
if(CTRL_LEFT(state) || CTRL_LSTICK_LEFT(state)) if(CTRL_LEFT(state) || CTRL_LSTICK_LEFT(state))
{ {
if(g_settings.video.render_to_texture) if(g_console.fbo_enabled)
{ {
if((g_settings.video.fbo_scale_x > MIN_SCALING_FACTOR)) if((g_settings.video.fbo_scale_x > MIN_SCALING_FACTOR))
{ {
@ -2171,7 +2167,7 @@ static void ingame_menu(uint32_t menu_id)
} }
if(CTRL_RIGHT(state) || CTRL_LSTICK_RIGHT(state) || CTRL_CROSS(state)) if(CTRL_RIGHT(state) || CTRL_LSTICK_RIGHT(state) || CTRL_CROSS(state))
{ {
if(g_settings.video.render_to_texture) if(g_console.fbo_enabled)
{ {
if((g_settings.video.fbo_scale_x < MAX_SCALING_FACTOR)) if((g_settings.video.fbo_scale_x < MAX_SCALING_FACTOR))
{ {

View File

@ -147,6 +147,13 @@ static bool gl_shader_filter_type(unsigned index, bool *smooth)
return valid; return valid;
} }
void gl_set_fbo_enable (bool enable)
{
gl_t *gl = g_gl;
gl->fbo_enabled = enable;
}
static void gl_shader_scale(unsigned index, struct gl_fbo_scale *scale) static void gl_shader_scale(unsigned index, struct gl_fbo_scale *scale)
{ {
scale->valid = false; scale->valid = false;
@ -182,33 +189,21 @@ static void gl_create_fbo_textures(gl_t *gl)
} }
void gl_deinit_fbo(gl_t *gl) void gl_deinit_fbo(gl_t *gl)
{
if (gl->fbo_inited)
{ {
glDeleteTextures(gl->fbo_pass, gl->fbo_texture); glDeleteTextures(gl->fbo_pass, gl->fbo_texture);
glDeleteFramebuffersOES(gl->fbo_pass, gl->fbo); glDeleteFramebuffersOES(gl->fbo_pass, gl->fbo);
memset(gl->fbo_texture, 0, sizeof(gl->fbo_texture)); memset(gl->fbo_texture, 0, sizeof(gl->fbo_texture));
memset(gl->fbo, 0, sizeof(gl->fbo)); memset(gl->fbo, 0, sizeof(gl->fbo));
gl->fbo_inited = false;
gl->render_to_tex = false;
gl->fbo_pass = 0; gl->fbo_pass = 0;
} }
}
// Horribly long and complex FBO init :D // Horribly long and complex FBO init :D
void gl_init_fbo(gl_t *gl, unsigned width, unsigned height) void gl_init_fbo(gl_t *gl, unsigned width, unsigned height)
{ {
if (!g_settings.video.render_to_texture && gl_shader_num() == 0)
return;
struct gl_fbo_scale scale, scale_last; struct gl_fbo_scale scale, scale_last;
gl_shader_scale(1, &scale); gl_shader_scale(1, &scale);
gl_shader_scale(gl_shader_num(), &scale_last); gl_shader_scale(gl_shader_num(), &scale_last);
// No need to use FBOs.
if (gl_shader_num() == 1 && !scale.valid && !g_settings.video.render_to_texture)
return;
gl->fbo_pass = gl_shader_num() - 1; gl->fbo_pass = gl_shader_num() - 1;
if (scale_last.valid) if (scale_last.valid)
gl->fbo_pass++; gl->fbo_pass++;
@ -320,7 +315,6 @@ void gl_init_fbo(gl_t *gl, unsigned width, unsigned height)
goto error; goto error;
} }
gl->fbo_inited = true;
glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0); glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);
return; return;
@ -545,12 +539,11 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
// Render to texture in first pass. // Render to texture in first pass.
if (gl->fbo_inited) if (gl->fbo_enabled)
{ {
gl_compute_fbo_geometry(gl, width, height, gl->vp_out_width, gl->vp_out_height); gl_compute_fbo_geometry(gl, width, height, gl->vp_out_width, gl->vp_out_height);
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, gl->fbo[0]); glBindFramebufferOES(GL_FRAMEBUFFER_OES, gl->fbo[0]);
gl->render_to_tex = true;
set_viewport_force_full(gl, gl->fbo_rect[0].img_width, gl->fbo_rect[0].img_height); set_viewport_force_full(gl, gl->fbo_rect[0].img_width, gl->fbo_rect[0].img_height);
} }
@ -581,7 +574,7 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei
// Need to preserve the "flipped" state when in FBO as well to have // Need to preserve the "flipped" state when in FBO as well to have
// consistent texture coordinates. // consistent texture coordinates.
if (gl->render_to_tex) if (gl->fbo_enabled)
glVertexPointer(2, GL_FLOAT, 0, vertexes); glVertexPointer(2, GL_FLOAT, 0, vertexes);
size_t buffer_addr = gl->tex_w * gl->tex_h * gl->tex_index * gl_base_size; size_t buffer_addr = gl->tex_w * gl->tex_h * gl->tex_index * gl_base_size;
@ -617,7 +610,7 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei
glDrawArrays(GL_QUADS, 0, 4); glDrawArrays(GL_QUADS, 0, 4);
if (gl->fbo_inited) if (gl->fbo_enabled)
{ {
// Render the rest of our passes. // Render the rest of our passes.
glTexCoordPointer(2, GL_FLOAT, 0, gl->fbo_tex_coords); glTexCoordPointer(2, GL_FLOAT, 0, gl->fbo_tex_coords);
@ -678,7 +671,6 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei
glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[gl->fbo_pass - 1]); glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[gl->fbo_pass - 1]);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
gl->render_to_tex = false;
set_viewport(gl, gl->win_width, gl->win_height); set_viewport(gl, gl->win_width, gl->win_height);
gl_cg_set_params(prev_rect->img_width, prev_rect->img_height, gl_cg_set_params(prev_rect->img_width, prev_rect->img_height,
prev_rect->width, prev_rect->height, prev_rect->width, prev_rect->height,
@ -1176,7 +1168,7 @@ void ps3_set_filtering(unsigned index, bool set_smooth)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, set_smooth ? GL_LINEAR : GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, set_smooth ? GL_LINEAR : GL_NEAREST);
} }
} }
else if (index >= 2 && gl->fbo_inited) else if (index >= 2 && gl->fbo_enabled)
{ {
glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[index - 2]); glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[index - 2]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, set_smooth ? GL_LINEAR : GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, set_smooth ? GL_LINEAR : GL_NEAREST);
@ -1211,6 +1203,7 @@ void ps3graphics_video_init(bool get_all_resolutions)
video_info.smooth = g_settings.video.smooth; video_info.smooth = g_settings.video.smooth;
video_info.input_scale = 2; video_info.input_scale = 2;
g_gl = gl_init(&video_info, NULL, NULL); g_gl = gl_init(&video_info, NULL, NULL);
gl_set_fbo_enable(g_console.fbo_enabled);
gl_t * gl = g_gl; gl_t * gl = g_gl;

View File

@ -45,10 +45,8 @@
typedef struct gl typedef struct gl
{ {
bool block_swap; bool block_swap;
bool fbo_inited; bool fbo_enabled;
bool keep_aspect; bool keep_aspect;
bool render_to_tex;
bool should_resize;
bool vsync; bool vsync;
bool overscan_enable; bool overscan_enable;
int fbo_pass; int fbo_pass;
@ -89,6 +87,7 @@ int ps3_check_resolution(uint32_t resolution_id);
void gl_frame_menu(void); void gl_frame_menu(void);
void gl_deinit_fbo(gl_t * gl); void gl_deinit_fbo(gl_t * gl);
void gl_init_fbo(gl_t * gl, unsigned width, unsigned height); void gl_init_fbo(gl_t * gl, unsigned width, unsigned height);
void gl_set_fbo_enable(bool enable);
void ps3_previous_resolution (void); void ps3_previous_resolution (void);
void ps3_next_resolution (void); void ps3_next_resolution (void);
void ps3_set_filtering(unsigned index, bool set_smooth); void ps3_set_filtering(unsigned index, bool set_smooth);