diff --git a/Makefile.common b/Makefile.common index 358bb5dbaa..03b37bac07 100644 --- a/Makefile.common +++ b/Makefile.common @@ -307,6 +307,7 @@ ifeq ($(HAVE_MENU_COMMON), 1) menu/menu_action.o \ menu/menu_database.o \ menu/menu_shader.o \ + menu/menu_texture.o \ menu/menu_entries.o \ menu/menu_entries_cbs.o \ menu/menu_list.o \ diff --git a/griffin/griffin.c b/griffin/griffin.c index 588d9d2837..5ce297ed66 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -686,6 +686,7 @@ MENU #include "../menu/menu_entries.c" #include "../menu/menu_entries_cbs.c" #include "../menu/menu_shader.c" +#include "../menu/menu_texture.c" #include "../menu/menu_navigation.c" #include "../menu/menu_animation.c" #include "../menu/menu_database.c" diff --git a/menu/drivers/glui.c b/menu/drivers/glui.c index 52028735d9..f6bb85b2b7 100644 --- a/menu/drivers/glui.c +++ b/menu/drivers/glui.c @@ -22,11 +22,12 @@ #include #include "../menu.h" +#include "../menu_texture.h" +#include "../menu_input.h" + #include #include "../../gfx/gl_common.h" -#include "../../gfx/video_thread_wrapper.h" #include -#include "../menu_input.h" #include "shared.h" @@ -497,55 +498,6 @@ static void glui_free(void *data) free(menu->userdata); } -static GLuint glui_png_texture_load_(const char * file_name) -{ - GLuint texture = 0; - struct texture_image ti = {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); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - - free(ti.pixels); - - return texture; -} -static int glui_png_texture_load_wrap(void *data) -{ - const char *filename = (const char*)data; - return glui_png_texture_load_(filename); -} - - -static GLuint glui_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; - thr->cmd_data.custom_command.method = glui_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 glui_png_texture_load_(file_name); -} - static void glui_context_reset(void *data) { @@ -573,7 +525,7 @@ static void glui_context_reset(void *data) fill_pathname_join(bgpath, bgpath, "bg.png", sizeof(bgpath)); if (path_file_exists(bgpath)) - glui->bg = glui_png_texture_load(bgpath); + glui->bg = (GLuint)menu_texture_load(bgpath, TEXTURE_BACKEND_OPENGL); } static void glui_navigation_clear(void *data, bool pending_push) diff --git a/menu/menu_texture.c b/menu/menu_texture.c new file mode 100644 index 0000000000..a812d37890 --- /dev/null +++ b/menu/menu_texture.c @@ -0,0 +1,116 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2011-2015 - Daniel De Matteis + * Copyright (C) 2014-2015 - Jean-André Santoni + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#include "menu_texture.h" +#include +#include "../general.h" +#include "../gfx/video_thread_wrapper.h" + +#ifdef HAVE_OPENGL +#include "../gfx/gl_common.h" + +static void menu_texture_png_load_gl(struct texture_image *ti, + unsigned *id) +{ + /* Generate the OpenGL texture object */ + glGenTextures(1, id); + glBindTexture(GL_TEXTURE_2D, (GLuint)*id); + 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); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); +} +#endif + +static unsigned menu_texture_png_load(const char *path, + enum texture_backend_type type) +{ + unsigned id = 0; + struct texture_image ti = {0}; + if (! path_file_exists(path)) + return 0; + + texture_image_load(&ti, path); + + switch (type) + { + case TEXTURE_BACKEND_OPENGL: +#ifdef HAVE_OPENGL + menu_texture_png_load_gl(&ti, &id); +#endif + break; + case TEXTURE_BACKEND_DEFAULT: + default: + break; + } + + free(ti.pixels); + + return id; +} + +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); +} + +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); +} + +unsigned menu_texture_load(const char *path, + enum texture_backend_type type) +{ + 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; + + switch (type) + { + case TEXTURE_BACKEND_OPENGL: + thr->cmd_data.custom_command.method = menu_texture_png_load_wrap_gl; + break; + case TEXTURE_BACKEND_DEFAULT: + default: + thr->cmd_data.custom_command.method = menu_texture_png_load_wrap; + break; + } + + thr->cmd_data.custom_command.data = (void*)path; + + 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 menu_texture_png_load(path, type); +} diff --git a/menu/menu_texture.h b/menu/menu_texture.h new file mode 100644 index 0000000000..4f48d38c52 --- /dev/null +++ b/menu/menu_texture.h @@ -0,0 +1,37 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2011-2015 - Daniel De Matteis + * Copyright (C) 2014-2015 - Jean-André Santoni + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#ifndef _MENU_TEXTURE_MANAGER_H +#define _MENU_TEXTURE_MANAGER_H + +enum texture_backend_type +{ + TEXTURE_BACKEND_DEFAULT = 0, + TEXTURE_BACKEND_OPENGL, +}; + +#ifdef __cplusplus +extern "C" { +#endif + +unsigned menu_texture_load(const char *path, + enum texture_backend_type type); + +#ifdef __cplusplus +} +#endif + +#endif