From 04022926bc7c507bdc1cea9a6768ffbd511eb02e Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 11 Feb 2015 03:52:35 +0100 Subject: [PATCH] Have XMB and GLUI reuse same menu_texture code --- menu/drivers/glui.c | 3 +- menu/drivers/xmb.c | 71 +++++++-------------------------------------- menu/menu_texture.c | 50 +++++++++++++++++++++++++------ menu/menu_texture.h | 9 +++++- 4 files changed, 61 insertions(+), 72 deletions(-) diff --git a/menu/drivers/glui.c b/menu/drivers/glui.c index f6bb85b2b7..bab1f4d905 100644 --- a/menu/drivers/glui.c +++ b/menu/drivers/glui.c @@ -525,7 +525,8 @@ static void glui_context_reset(void *data) fill_pathname_join(bgpath, bgpath, "bg.png", sizeof(bgpath)); if (path_file_exists(bgpath)) - glui->bg = (GLuint)menu_texture_load(bgpath, TEXTURE_BACKEND_OPENGL); + glui->bg = (GLuint)menu_texture_load(bgpath, TEXTURE_BACKEND_OPENGL, + TEXTURE_FILTER_DEFAULT); } static void glui_navigation_clear(void *data, bool pending_push) diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index 2dc04341fb..bfd9f6228a 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -22,13 +22,15 @@ #include "../menu.h" #include "../menu_input.h" +#include "../menu_animation.h" +#include "../menu_texture.h" + #include #include "../../gfx/gl_common.h" #include "../../gfx/video_thread_wrapper.h" #include #include "shared.h" -#include "../menu_animation.h" #ifndef XMB_THEME #define XMB_THEME "monochrome" @@ -575,63 +577,6 @@ static void xmb_list_open_new(file_list_t *list, int dir, size_t current) xmb->old_depth = xmb->depth; } -static GLuint xmb_png_texture_load_(const char * file_name) -{ - struct texture_image ti = {0}; - GLuint texture = 0; - - if (! path_file_exists(file_name)) - return 0; - - texture_image_load(&ti, file_name); - - /* Generate the OpenGL texture object */ - glGenTextures(1, &texture); - glBindTexture(GL_TEXTURE_2D, texture); - glTexImage2D(GL_TEXTURE_2D, 0, driver.gfx_use_rgba ? - GL_RGBA : RARCH_GL_INTERNAL_FORMAT32, - ti.width, ti.height, 0, - driver.gfx_use_rgba ? GL_RGBA : RARCH_GL_TEXTURE_TYPE32, - RARCH_GL_FORMAT32, ti.pixels); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glGenerateMipmap(GL_TEXTURE_2D); - - free(ti.pixels); - - return texture; -} - -static int xmb_png_texture_load_wrap(void *data) -{ - const char *filename = (const char*)data; - - if (!filename) - return 0; - return xmb_png_texture_load_(filename); -} - -static GLuint xmb_png_texture_load(const char* file_name) -{ - if (g_settings.video.threaded - && !g_extern.system.hw_render_callback.context_type) - { - thread_video_t *thr = (thread_video_t*)driver.video_data; - - if (!thr) - return 0; - - thr->cmd_data.custom_command.method = xmb_png_texture_load_wrap; - thr->cmd_data.custom_command.data = (void*)file_name; - thr->send_cmd_func(thr, CMD_CUSTOM_COMMAND); - thr->wait_reply_func(thr, CMD_CUSTOM_COMMAND); - - return thr->cmd_data.custom_command.return_value; - } - - return xmb_png_texture_load_(file_name); -} - static xmb_node_t* xmb_node_for_core(int i) { core_info_t *info = NULL; @@ -1408,7 +1353,8 @@ static void xmb_context_reset(void *data) "clock.png", sizeof(xmb->textures[XMB_TEXTURE_CLOCK].path)); for (k = 0; k < XMB_TEXTURE_LAST; k++) - xmb->textures[k].id = xmb_png_texture_load(xmb->textures[k].path); + xmb->textures[k].id = menu_texture_load(xmb->textures[k].path, + TEXTURE_BACKEND_OPENGL, TEXTURE_FILTER_MIPMAP); xmb->settings_node.icon = xmb->textures[XMB_TEXTURE_SETTINGS].id; xmb->settings_node.alpha = xmb->c_active_alpha; @@ -1453,8 +1399,11 @@ static void xmb_context_reset(void *data) node->alpha = 0; node->zoom = xmb->c_passive_zoom; - node->icon = xmb_png_texture_load(texturepath); - node->content_icon = xmb_png_texture_load(content_texturepath); + node->icon = menu_texture_load(texturepath, + TEXTURE_BACKEND_OPENGL, TEXTURE_FILTER_MIPMAP); + node->content_icon = menu_texture_load(content_texturepath, + TEXTURE_BACKEND_OPENGL, TEXTURE_FILTER_MIPMAP); + if (i == xmb->active_category) { diff --git a/menu/menu_texture.c b/menu/menu_texture.c index a812d37890..817d032029 100644 --- a/menu/menu_texture.c +++ b/menu/menu_texture.c @@ -23,6 +23,7 @@ #include "../gfx/gl_common.h" static void menu_texture_png_load_gl(struct texture_image *ti, + enum texture_filter_type filter_type, unsigned *id) { /* Generate the OpenGL texture object */ @@ -34,13 +35,29 @@ static void menu_texture_png_load_gl(struct texture_image *ti, driver.gfx_use_rgba ? GL_RGBA : RARCH_GL_TEXTURE_TYPE32, RARCH_GL_FORMAT32, ti->pixels); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + switch (filter_type) + { + case TEXTURE_FILTER_MIPMAP: + glTexParameterf(GL_TEXTURE_2D, + GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); + glTexParameterf(GL_TEXTURE_2D, + GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glGenerateMipmap(GL_TEXTURE_2D); + break; + case TEXTURE_FILTER_DEFAULT: + default: + glTexParameterf(GL_TEXTURE_2D, + GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, + GL_TEXTURE_MAG_FILTER, GL_LINEAR); + break; + } } #endif static unsigned menu_texture_png_load(const char *path, - enum texture_backend_type type) + enum texture_backend_type type, + enum texture_filter_type filter_type) { unsigned id = 0; struct texture_image ti = {0}; @@ -53,7 +70,7 @@ static unsigned menu_texture_png_load(const char *path, { case TEXTURE_BACKEND_OPENGL: #ifdef HAVE_OPENGL - menu_texture_png_load_gl(&ti, &id); + menu_texture_png_load_gl(&ti, filter_type, &id); #endif break; case TEXTURE_BACKEND_DEFAULT: @@ -71,7 +88,17 @@ static int menu_texture_png_load_wrap(void *data) const char *filename = (const char*)data; if (!filename) return 0; - return menu_texture_png_load(filename, TEXTURE_BACKEND_DEFAULT); + return menu_texture_png_load(filename, TEXTURE_BACKEND_DEFAULT, + TEXTURE_FILTER_DEFAULT); +} + +static int menu_texture_png_load_wrap_gl_mipmap(void *data) +{ + const char *filename = (const char*)data; + if (!filename) + return 0; + return menu_texture_png_load(filename, TEXTURE_BACKEND_OPENGL, + TEXTURE_FILTER_MIPMAP); } static int menu_texture_png_load_wrap_gl(void *data) @@ -79,11 +106,13 @@ static int menu_texture_png_load_wrap_gl(void *data) const char *filename = (const char*)data; if (!filename) return 0; - return menu_texture_png_load(filename, TEXTURE_BACKEND_OPENGL); + return menu_texture_png_load(filename, TEXTURE_BACKEND_OPENGL, + TEXTURE_FILTER_DEFAULT); } unsigned menu_texture_load(const char *path, - enum texture_backend_type type) + enum texture_backend_type type, + enum texture_filter_type filter_type) { if (g_settings.video.threaded && !g_extern.system.hw_render_callback.context_type) @@ -96,7 +125,10 @@ unsigned menu_texture_load(const char *path, switch (type) { case TEXTURE_BACKEND_OPENGL: - thr->cmd_data.custom_command.method = menu_texture_png_load_wrap_gl; + if (filter_type == TEXTURE_FILTER_MIPMAP) + thr->cmd_data.custom_command.method = menu_texture_png_load_wrap_gl_mipmap; + else + thr->cmd_data.custom_command.method = menu_texture_png_load_wrap_gl; break; case TEXTURE_BACKEND_DEFAULT: default: @@ -112,5 +144,5 @@ unsigned menu_texture_load(const char *path, return thr->cmd_data.custom_command.return_value; } - return menu_texture_png_load(path, type); + return menu_texture_png_load(path, type, filter_type); } diff --git a/menu/menu_texture.h b/menu/menu_texture.h index 4f48d38c52..d5ef3ffd22 100644 --- a/menu/menu_texture.h +++ b/menu/menu_texture.h @@ -23,12 +23,19 @@ enum texture_backend_type TEXTURE_BACKEND_OPENGL, }; +enum texture_filter_type +{ + TEXTURE_FILTER_DEFAULT = 0, + TEXTURE_FILTER_MIPMAP, +}; + #ifdef __cplusplus extern "C" { #endif unsigned menu_texture_load(const char *path, - enum texture_backend_type type); + enum texture_backend_type type, + enum texture_filter_type filter_type); #ifdef __cplusplus }