mirror of
https://github.com/libretro/RetroArch
synced 2025-03-29 22:20:21 +00:00
Start creating menu_texture.c - have GLUI use it
This commit is contained in:
parent
5c05086455
commit
4186d97281
@ -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 \
|
||||
|
@ -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"
|
||||
|
@ -22,11 +22,12 @@
|
||||
#include <limits.h>
|
||||
|
||||
#include "../menu.h"
|
||||
#include "../menu_texture.h"
|
||||
#include "../menu_input.h"
|
||||
|
||||
#include <file/file_path.h>
|
||||
#include "../../gfx/gl_common.h"
|
||||
#include "../../gfx/video_thread_wrapper.h"
|
||||
#include <compat/posix_string.h>
|
||||
#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)
|
||||
|
116
menu/menu_texture.c
Normal file
116
menu/menu_texture.c
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "menu_texture.h"
|
||||
#include <file/file_path.h>
|
||||
#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);
|
||||
}
|
37
menu/menu_texture.h
Normal file
37
menu/menu_texture.h
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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
|
Loading…
x
Reference in New Issue
Block a user