diff --git a/gfx/common/gl_common.h b/gfx/common/gl_common.h index c7b3e8e7e5..1e7b00b431 100644 --- a/gfx/common/gl_common.h +++ b/gfx/common/gl_common.h @@ -175,9 +175,6 @@ typedef struct gl void *renderchain_data; } gl_t; -bool gl_load_luts(const struct video_shader *generic_shader, - GLuint *lut_textures); - #ifdef NO_GL_FF_VERTEX #define gl_ff_vertex(coords) ((void)0) #else @@ -246,6 +243,14 @@ void gl_load_texture_image(GLenum target, GLenum type, const GLvoid * data); +void gl_load_texture_data( + uint32_t id_data, + enum gfx_wrap_type wrap_type, + enum texture_filter_type filter_type, + unsigned alignment, + unsigned width, unsigned height, + const void *frame, unsigned base_size); + RETRO_END_DECLS #endif diff --git a/gfx/drivers/gl.c b/gfx/drivers/gl.c index e88aac883d..1b09a65357 100644 --- a/gfx/drivers/gl.c +++ b/gfx/drivers/gl.c @@ -2522,28 +2522,6 @@ unsigned *height_p, size_t *pitch_p) } #endif - -bool gl_load_luts(const struct video_shader *shader, - GLuint *textures_lut) -{ - unsigned i; - unsigned num_luts = MIN(shader->luts, GFX_MAX_TEXTURES); - - if (!shader->luts) - return true; - - glGenTextures(num_luts, textures_lut); - - for (i = 0; i < num_luts; i++) - { - if (!gl2_renderchain_add_lut(shader, i, textures_lut)) - return false; - } - - glBindTexture(GL_TEXTURE_2D, 0); - return true; -} - #ifdef HAVE_OVERLAY static bool gl_overlay_load(void *data, const void *image_data, unsigned num_images) diff --git a/gfx/drivers_renderchain/gl2_renderchain.c b/gfx/drivers_renderchain/gl2_renderchain.c index 0f9340221d..38604bfa7d 100644 --- a/gfx/drivers_renderchain/gl2_renderchain.c +++ b/gfx/drivers_renderchain/gl2_renderchain.c @@ -962,50 +962,6 @@ static void gl2_renderchain_bind_prev_texture( #endif } -bool gl2_renderchain_add_lut( - const struct video_shader *shader, - unsigned i, void *textures_data) -{ - struct texture_image img; - GLuint *textures_lut = (GLuint*)textures_data; - enum texture_filter_type filter_type = TEXTURE_FILTER_LINEAR; - - img.width = 0; - img.height = 0; - img.pixels = NULL; - img.supports_rgba = video_driver_supports_rgba(); - - if (!image_texture_load(&img, shader->lut[i].path)) - { - RARCH_ERR("[GL]: Failed to load texture image from: \"%s\"\n", - shader->lut[i].path); - return false; - } - - RARCH_LOG("[GL]: Loaded texture image from: \"%s\" ...\n", - shader->lut[i].path); - - if (shader->lut[i].filter == RARCH_FILTER_NEAREST) - filter_type = TEXTURE_FILTER_NEAREST; - - if (shader->lut[i].mipmap) - { - if (filter_type == TEXTURE_FILTER_NEAREST) - filter_type = TEXTURE_FILTER_MIPMAP_NEAREST; - else - filter_type = TEXTURE_FILTER_MIPMAP_LINEAR; - } - - gl_load_texture_data(textures_lut[i], - shader->lut[i].wrap, - filter_type, 4, - img.width, img.height, - img.pixels, sizeof(uint32_t)); - image_texture_free(&img); - - return true; -} - static void gl2_renderchain_viewport_info( void *data, struct video_viewport *vp) { diff --git a/gfx/drivers_renderchain/gl2_renderchain.h b/gfx/drivers_renderchain/gl2_renderchain.h index c8bcf95d00..79d4e7460b 100644 --- a/gfx/drivers_renderchain/gl2_renderchain.h +++ b/gfx/drivers_renderchain/gl2_renderchain.h @@ -25,9 +25,6 @@ RETRO_BEGIN_DECLS -bool gl2_renderchain_add_lut(const struct video_shader *shader, - unsigned i, void *textures_lut); - void gl2_renderchain_deinit_fbo(void *data); void context_bind_hw_render(bool enable); diff --git a/gfx/drivers_shader/shader_gl_cg.c b/gfx/drivers_shader/shader_gl_cg.c index 754e08b4e2..93ec4c4925 100644 --- a/gfx/drivers_shader/shader_gl_cg.c +++ b/gfx/drivers_shader/shader_gl_cg.c @@ -781,6 +781,72 @@ static bool gl_cg_load_shader(void *data, unsigned i) return true; } +static bool gl_cg_add_lut( + const struct video_shader *shader, + unsigned i, void *textures_data) +{ + struct texture_image img; + GLuint *textures_lut = (GLuint*)textures_data; + enum texture_filter_type filter_type = TEXTURE_FILTER_LINEAR; + + img.width = 0; + img.height = 0; + img.pixels = NULL; + img.supports_rgba = video_driver_supports_rgba(); + + if (!image_texture_load(&img, shader->lut[i].path)) + { + RARCH_ERR("[GL]: Failed to load texture image from: \"%s\"\n", + shader->lut[i].path); + return false; + } + + RARCH_LOG("[GL]: Loaded texture image from: \"%s\" ...\n", + shader->lut[i].path); + + if (shader->lut[i].filter == RARCH_FILTER_NEAREST) + filter_type = TEXTURE_FILTER_NEAREST; + + if (shader->lut[i].mipmap) + { + if (filter_type == TEXTURE_FILTER_NEAREST) + filter_type = TEXTURE_FILTER_MIPMAP_NEAREST; + else + filter_type = TEXTURE_FILTER_MIPMAP_LINEAR; + } + + gl_load_texture_data(textures_lut[i], + shader->lut[i].wrap, + filter_type, 4, + img.width, img.height, + img.pixels, sizeof(uint32_t)); + image_texture_free(&img); + + return true; +} + +static bool gl_cg_load_luts( + const struct video_shader *shader, + GLuint *textures_lut) +{ + unsigned i; + unsigned num_luts = MIN(shader->luts, GFX_MAX_TEXTURES); + + if (!shader->luts) + return true; + + glGenTextures(num_luts, textures_lut); + + for (i = 0; i < num_luts; i++) + { + if (!gl_cg_add_lut(shader, i, textures_lut)) + return false; + } + + glBindTexture(GL_TEXTURE_2D, 0); + return true; +} + static bool gl_cg_load_preset(void *data, const char *path) { unsigned i; @@ -841,7 +907,7 @@ static bool gl_cg_load_preset(void *data, const char *path) } } - if (!gl_load_luts(cg->shader, cg->lut_textures)) + if (!gl_cg_load_luts(cg->shader, cg->lut_textures)) { RARCH_ERR("Failed to load lookup textures ...\n"); return false; diff --git a/gfx/drivers_shader/shader_glsl.c b/gfx/drivers_shader/shader_glsl.c index 3112aabadb..fffcd3109c 100644 --- a/gfx/drivers_shader/shader_glsl.c +++ b/gfx/drivers_shader/shader_glsl.c @@ -157,6 +157,72 @@ static float* current_mat_data_pointer[GFX_MAX_SHADERS]; static float current_mat_data[GFX_MAX_SHADERS]; static unsigned current_idx; +static bool gl_glsl_add_lut( + const struct video_shader *shader, + unsigned i, void *textures_data) +{ + struct texture_image img; + GLuint *textures_lut = (GLuint*)textures_data; + enum texture_filter_type filter_type = TEXTURE_FILTER_LINEAR; + + img.width = 0; + img.height = 0; + img.pixels = NULL; + img.supports_rgba = video_driver_supports_rgba(); + + if (!image_texture_load(&img, shader->lut[i].path)) + { + RARCH_ERR("[GL]: Failed to load texture image from: \"%s\"\n", + shader->lut[i].path); + return false; + } + + RARCH_LOG("[GL]: Loaded texture image from: \"%s\" ...\n", + shader->lut[i].path); + + if (shader->lut[i].filter == RARCH_FILTER_NEAREST) + filter_type = TEXTURE_FILTER_NEAREST; + + if (shader->lut[i].mipmap) + { + if (filter_type == TEXTURE_FILTER_NEAREST) + filter_type = TEXTURE_FILTER_MIPMAP_NEAREST; + else + filter_type = TEXTURE_FILTER_MIPMAP_LINEAR; + } + + gl_load_texture_data(textures_lut[i], + shader->lut[i].wrap, + filter_type, 4, + img.width, img.height, + img.pixels, sizeof(uint32_t)); + image_texture_free(&img); + + return true; +} + +static bool gl_glsl_load_luts( + const struct video_shader *shader, + GLuint *textures_lut) +{ + unsigned i; + unsigned num_luts = MIN(shader->luts, GFX_MAX_TEXTURES); + + if (!shader->luts) + return true; + + glGenTextures(num_luts, textures_lut); + + for (i = 0; i < num_luts; i++) + { + if (!gl_glsl_add_lut(shader, i, textures_lut)) + return false; + } + + glBindTexture(GL_TEXTURE_2D, 0); + return true; +} + static GLint gl_glsl_get_uniform(glsl_shader_data_t *glsl, GLuint prog, const char *base) { @@ -876,7 +942,7 @@ static void *gl_glsl_init(void *data, const char *path) if (!gl_glsl_compile_programs(glsl, &glsl->prg[1])) goto error; - if (!gl_load_luts(glsl->shader, glsl->lut_textures)) + if (!gl_glsl_load_luts(glsl->shader, glsl->lut_textures)) { RARCH_ERR("[GL]: Failed to load LUTs.\n"); goto error;