From 773c5111796fc6b3f4deb0f44ea43c8919c0a748 Mon Sep 17 00:00:00 2001 From: Themaister Date: Mon, 25 Mar 2013 16:42:41 +0100 Subject: [PATCH] Add floating point FBO support. --- gfx/gl.c | 27 +++++++++++++++++++++++---- gfx/gl_common.h | 1 + gfx/shader_cg.c | 6 +++++- gfx/shader_glsl.c | 8 +++++++- 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/gfx/gl.c b/gfx/gl.c index 40fd2cd3f1..b100e50d5a 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -518,10 +518,29 @@ static void gl_create_fbo_textures(void *data) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter_type); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter_type); - glTexImage2D(GL_TEXTURE_2D, - 0, driver.gfx_use_rgba ? GL_RGBA : RARCH_GL_INTERNAL_FORMAT32, gl->fbo_rect[i].width, gl->fbo_rect[i].height, - 0, driver.gfx_use_rgba ? GL_RGBA : RARCH_GL_TEXTURE_TYPE32, - RARCH_GL_FORMAT32, NULL); +#if !defined(HAVE_OPENGLES2) && !defined(HAVE_PSGL) + bool fp_fbo = gl->fbo_scale[i].valid && gl->fbo_scale[i].fp_fbo; + + if (fp_fbo) + { + bool has_fp_fbo = gl_query_extension("ARB_texture_float"); + if (!has_fp_fbo) + RARCH_ERR("ARB_texture_float extension was not found.\n"); + + RARCH_LOG("FBO pass #%d is floating-point.\n", i); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, + gl->fbo_rect[i].width, gl->fbo_rect[i].height, + 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + } + else +#endif + { + glTexImage2D(GL_TEXTURE_2D, + 0, driver.gfx_use_rgba ? GL_RGBA : RARCH_GL_INTERNAL_FORMAT32, + gl->fbo_rect[i].width, gl->fbo_rect[i].height, + 0, driver.gfx_use_rgba ? GL_RGBA : RARCH_GL_TEXTURE_TYPE32, + RARCH_GL_FORMAT32, NULL); + } } glBindTexture(GL_TEXTURE_2D, 0); diff --git a/gfx/gl_common.h b/gfx/gl_common.h index a233b8233d..6ff82cfa2e 100644 --- a/gfx/gl_common.h +++ b/gfx/gl_common.h @@ -169,6 +169,7 @@ enum gl_scale_type struct gl_fbo_scale { + bool fp_fbo; enum gl_scale_type type_x; enum gl_scale_type type_y; float scale_x; diff --git a/gfx/shader_cg.c b/gfx/shader_cg.c index 978615e51f..a6794c857c 100644 --- a/gfx/shader_cg.c +++ b/gfx/shader_cg.c @@ -844,7 +844,6 @@ static bool load_shader_params(unsigned i, config_file_t *conf) prg[i + 1].frame_count_mod = strtoul(frame_count_mod, NULL, 0); char scale_name_buf[64]; - print_buf(scale_name_buf, "scale_type%u", i); config_get_array(conf, scale_name_buf, scale_type, sizeof(scale_type)); @@ -874,6 +873,11 @@ static bool load_shader_params(unsigned i, config_file_t *conf) scale->scale_x = 1.0; scale->scale_y = 1.0; + char fp_fbo_buf[64]; + print_buf(fp_fbo_buf, "float_framebuffer%u", i); + scale->fp_fbo = false; + config_get_bool(conf, fp_fbo_buf, &scale->fp_fbo); + const struct retro_game_geometry *geom = &g_extern.system.av_info.geometry; scale->abs_x = geom->base_width; scale->abs_y = geom->base_height; diff --git a/gfx/shader_glsl.c b/gfx/shader_glsl.c index 345e3cfe3a..b57905e132 100644 --- a/gfx/shader_glsl.c +++ b/gfx/shader_glsl.c @@ -167,6 +167,7 @@ struct shader_program char *fragment; enum filter_type filter; + bool fp_fbo; float scale_x; float scale_y; unsigned abs_x; @@ -303,6 +304,7 @@ static char *xml_replace_if_file(char *content, const char *path, xmlNodePtr nod static bool get_xml_attrs(struct shader_program *prog, xmlNodePtr ptr) { prog->frame_count_mod = 0; + prog->fp_fbo = false; prog->scale_x = 1.0; prog->scale_y = 1.0; prog->type_x = prog->type_y = RARCH_SCALE_INPUT; @@ -332,7 +334,7 @@ static bool get_xml_attrs(struct shader_program *prog, xmlNodePtr ptr) char attr_scale[64], attr_scale_x[64], attr_scale_y[64]; char attr_size[64], attr_size_x[64], attr_size_y[64]; char attr_outscale[64], attr_outscale_x[64], attr_outscale_y[64]; - char frame_count_mod[64]; + char frame_count_mod[64], fp_fbo[64]; xml_get_prop(attr_scale, sizeof(attr_scale), ptr, "scale"); xml_get_prop(attr_scale_x, sizeof(attr_scale_x), ptr, "scale_x"); @@ -344,6 +346,9 @@ static bool get_xml_attrs(struct shader_program *prog, xmlNodePtr ptr) xml_get_prop(attr_outscale_x, sizeof(attr_outscale_x), ptr, "outscale_x"); xml_get_prop(attr_outscale_y, sizeof(attr_outscale_y), ptr, "outscale_y"); xml_get_prop(frame_count_mod, sizeof(frame_count_mod), ptr, "frame_count_mod"); + xml_get_prop(fp_fbo, sizeof(fp_fbo), ptr, "float_framebuffer"); + + prog->fp_fbo = strcmp(fp_fbo, "true") == 0; unsigned x_attr_cnt = 0, y_attr_cnt = 0; @@ -1189,6 +1194,7 @@ bool gl_glsl_init(const char *path) for (unsigned i = 0; i < num_progs; i++) { gl_filter_type[i + 1] = progs[i].filter; + gl_scale[i + 1].fp_fbo = progs[i].fp_fbo; gl_scale[i + 1].type_x = progs[i].type_x; gl_scale[i + 1].type_y = progs[i].type_y; gl_scale[i + 1].scale_x = progs[i].scale_x;