mirror of
https://github.com/libretro/RetroArch
synced 2025-03-27 23:37:39 +00:00
Have menu_texture.c reuse gl_common.c's gl_load_texture_data
This commit is contained in:
parent
b64584672f
commit
f19339eb38
@ -16,20 +16,49 @@
|
|||||||
|
|
||||||
#include "gl_common.h"
|
#include "gl_common.h"
|
||||||
|
|
||||||
void gl_load_texture_data(GLuint obj, const struct texture_image *img,
|
void gl_load_texture_data(GLuint id,
|
||||||
GLenum wrap, bool linear, bool mipmap)
|
const struct texture_image *img,
|
||||||
|
enum gfx_wrap_type wrap_type,
|
||||||
|
enum texture_filter_type filter_type)
|
||||||
{
|
{
|
||||||
glBindTexture(GL_TEXTURE_2D, obj);
|
GLint mag_filter, min_filter;
|
||||||
|
GLenum wrap;
|
||||||
|
bool want_mipmap = false;
|
||||||
|
|
||||||
|
glBindTexture(GL_TEXTURE_2D, id);
|
||||||
|
|
||||||
|
wrap = driver.video->wrap_type_to_enum(wrap_type);
|
||||||
|
|
||||||
#ifdef HAVE_PSGL
|
|
||||||
mipmap = false;
|
|
||||||
#endif
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap);
|
||||||
|
|
||||||
GLint mag_filter = linear ? GL_LINEAR : GL_NEAREST;
|
switch (filter_type)
|
||||||
GLint min_filter = linear ? (mipmap ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR) :
|
{
|
||||||
(mipmap ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST);
|
case TEXTURE_FILTER_MIPMAP_LINEAR:
|
||||||
|
min_filter = GL_LINEAR_MIPMAP_LINEAR;
|
||||||
|
mag_filter = GL_LINEAR;
|
||||||
|
#ifndef HAVE_PSGL
|
||||||
|
want_mipmap = true;
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
case TEXTURE_FILTER_MIPMAP_NEAREST:
|
||||||
|
min_filter = GL_NEAREST_MIPMAP_NEAREST;
|
||||||
|
mag_filter = GL_NEAREST;
|
||||||
|
#ifndef HAVE_PSGL
|
||||||
|
want_mipmap = true;
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
case TEXTURE_FILTER_NEAREST:
|
||||||
|
min_filter = GL_NEAREST;
|
||||||
|
mag_filter = GL_NEAREST;
|
||||||
|
break;
|
||||||
|
case TEXTURE_FILTER_LINEAR:
|
||||||
|
default:
|
||||||
|
min_filter = GL_LINEAR;
|
||||||
|
mag_filter = GL_LINEAR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter);
|
||||||
|
|
||||||
@ -37,14 +66,14 @@ void gl_load_texture_data(GLuint obj, const struct texture_image *img,
|
|||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
|
||||||
#endif
|
#endif
|
||||||
glTexImage2D(GL_TEXTURE_2D,
|
glTexImage2D(GL_TEXTURE_2D,
|
||||||
0, driver.gfx_use_rgba ? GL_RGBA : RARCH_GL_INTERNAL_FORMAT32,
|
0,
|
||||||
img->width, img->height,
|
driver.gfx_use_rgba ? GL_RGBA : RARCH_GL_INTERNAL_FORMAT32,
|
||||||
0, driver.gfx_use_rgba ? GL_RGBA : RARCH_GL_TEXTURE_TYPE32,
|
img->width, img->height, 0,
|
||||||
|
driver.gfx_use_rgba ? GL_RGBA : RARCH_GL_TEXTURE_TYPE32,
|
||||||
RARCH_GL_FORMAT32, img->pixels);
|
RARCH_GL_FORMAT32, img->pixels);
|
||||||
#ifndef HAVE_PSGL
|
|
||||||
if (mipmap)
|
if (want_mipmap)
|
||||||
glGenerateMipmap(GL_TEXTURE_2D);
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool gl_load_luts(const struct video_shader *generic_shader,
|
bool gl_load_luts(const struct video_shader *generic_shader,
|
||||||
@ -60,9 +89,12 @@ bool gl_load_luts(const struct video_shader *generic_shader,
|
|||||||
* texture handle. I assume it was a bug, but if not,
|
* texture handle. I assume it was a bug, but if not,
|
||||||
* replace num_luts with 1 when GLSL is used. */
|
* replace num_luts with 1 when GLSL is used. */
|
||||||
glGenTextures(num_luts, textures_lut);
|
glGenTextures(num_luts, textures_lut);
|
||||||
|
|
||||||
for (i = 0; i < num_luts; i++)
|
for (i = 0; i < num_luts; i++)
|
||||||
{
|
{
|
||||||
struct texture_image img = {0};
|
struct texture_image img = {0};
|
||||||
|
enum texture_filter_type filter_type = TEXTURE_FILTER_LINEAR;
|
||||||
|
|
||||||
RARCH_LOG("Loading texture image from: \"%s\" ...\n",
|
RARCH_LOG("Loading texture image from: \"%s\" ...\n",
|
||||||
generic_shader->lut[i].path);
|
generic_shader->lut[i].path);
|
||||||
|
|
||||||
@ -73,10 +105,20 @@ bool gl_load_luts(const struct video_shader *generic_shader,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (generic_shader->lut[i].filter == RARCH_FILTER_NEAREST)
|
||||||
|
filter_type = TEXTURE_FILTER_NEAREST;
|
||||||
|
|
||||||
|
if (generic_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], &img,
|
gl_load_texture_data(textures_lut[i], &img,
|
||||||
driver.video->wrap_type_to_enum(generic_shader->lut[i].wrap),
|
generic_shader->lut[i].wrap,
|
||||||
generic_shader->lut[i].filter != RARCH_FILTER_NEAREST,
|
filter_type);
|
||||||
generic_shader->lut[i].mipmap);
|
|
||||||
texture_image_free(&img);
|
texture_image_free(&img);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -403,8 +403,10 @@ static inline bool gl_check_error(void)
|
|||||||
void gl_set_viewport(gl_t *gl, unsigned width, unsigned height,
|
void gl_set_viewport(gl_t *gl, unsigned width, unsigned height,
|
||||||
bool force_full, bool allow_rotate);
|
bool force_full, bool allow_rotate);
|
||||||
|
|
||||||
void gl_load_texture_data(GLuint obj, const struct texture_image *img,
|
void gl_load_texture_data(GLuint id,
|
||||||
GLenum wrap, bool linear, bool mipmap);
|
const struct texture_image *img,
|
||||||
|
enum gfx_wrap_type wrap_type,
|
||||||
|
enum texture_filter_type filter_type);
|
||||||
|
|
||||||
bool gl_load_luts(const struct video_shader *generic_shader,
|
bool gl_load_luts(const struct video_shader *generic_shader,
|
||||||
GLuint *lut_textures);
|
GLuint *lut_textures);
|
||||||
|
@ -74,6 +74,13 @@ struct font_params
|
|||||||
bool align_right;
|
bool align_right;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum texture_filter_type
|
||||||
|
{
|
||||||
|
TEXTURE_FILTER_LINEAR = 0,
|
||||||
|
TEXTURE_FILTER_NEAREST,
|
||||||
|
TEXTURE_FILTER_MIPMAP_LINEAR,
|
||||||
|
TEXTURE_FILTER_MIPMAP_NEAREST,
|
||||||
|
};
|
||||||
|
|
||||||
#define FONT_COLOR_RGBA(r, g, b, a) (((r) << 0) | ((g) << 8) | ((b) << 16) | ((a) << 24))
|
#define FONT_COLOR_RGBA(r, g, b, a) (((r) << 0) | ((g) << 8) | ((b) << 16) | ((a) << 24))
|
||||||
#define FONT_COLOR_GET_RED(col) (((col) >> 0) & 0xff)
|
#define FONT_COLOR_GET_RED(col) (((col) >> 0) & 0xff)
|
||||||
|
@ -492,8 +492,9 @@ static void glui_context_reset(void *data)
|
|||||||
fill_pathname_join(bgpath, bgpath, "bg.png", sizeof(bgpath));
|
fill_pathname_join(bgpath, bgpath, "bg.png", sizeof(bgpath));
|
||||||
|
|
||||||
if (path_file_exists(bgpath))
|
if (path_file_exists(bgpath))
|
||||||
glui->bg = (GLuint)menu_texture_load(bgpath, TEXTURE_BACKEND_OPENGL,
|
glui->bg = (GLuint)menu_texture_load(bgpath,
|
||||||
TEXTURE_FILTER_DEFAULT);
|
TEXTURE_BACKEND_OPENGL,
|
||||||
|
TEXTURE_FILTER_LINEAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void glui_navigation_clear(void *data, bool pending_push)
|
static void glui_navigation_clear(void *data, bool pending_push)
|
||||||
|
@ -1272,7 +1272,7 @@ static void xmb_context_reset(void *data)
|
|||||||
|
|
||||||
for (k = 0; k < XMB_TEXTURE_LAST; k++)
|
for (k = 0; k < XMB_TEXTURE_LAST; k++)
|
||||||
xmb->textures[k].id = menu_texture_load(xmb->textures[k].path,
|
xmb->textures[k].id = menu_texture_load(xmb->textures[k].path,
|
||||||
TEXTURE_BACKEND_OPENGL, TEXTURE_FILTER_MIPMAP);
|
TEXTURE_BACKEND_OPENGL, TEXTURE_FILTER_MIPMAP_LINEAR);
|
||||||
|
|
||||||
xmb->settings_node.icon = xmb->textures[XMB_TEXTURE_SETTINGS].id;
|
xmb->settings_node.icon = xmb->textures[XMB_TEXTURE_SETTINGS].id;
|
||||||
xmb->settings_node.alpha = xmb->c_active_alpha;
|
xmb->settings_node.alpha = xmb->c_active_alpha;
|
||||||
@ -1318,9 +1318,9 @@ static void xmb_context_reset(void *data)
|
|||||||
node->alpha = 0;
|
node->alpha = 0;
|
||||||
node->zoom = xmb->c_passive_zoom;
|
node->zoom = xmb->c_passive_zoom;
|
||||||
node->icon = menu_texture_load(texturepath,
|
node->icon = menu_texture_load(texturepath,
|
||||||
TEXTURE_BACKEND_OPENGL, TEXTURE_FILTER_MIPMAP);
|
TEXTURE_BACKEND_OPENGL, TEXTURE_FILTER_MIPMAP_LINEAR);
|
||||||
node->content_icon = menu_texture_load(content_texturepath,
|
node->content_icon = menu_texture_load(content_texturepath,
|
||||||
TEXTURE_BACKEND_OPENGL, TEXTURE_FILTER_MIPMAP);
|
TEXTURE_BACKEND_OPENGL, TEXTURE_FILTER_MIPMAP_LINEAR);
|
||||||
|
|
||||||
|
|
||||||
if (i == xmb->active_category)
|
if (i == xmb->active_category)
|
||||||
|
@ -28,30 +28,8 @@ static void menu_texture_png_load_gl(struct texture_image *ti,
|
|||||||
{
|
{
|
||||||
/* Generate the OpenGL texture object */
|
/* Generate the OpenGL texture object */
|
||||||
glGenTextures(1, id);
|
glGenTextures(1, id);
|
||||||
glBindTexture(GL_TEXTURE_2D, (GLuint)*id);
|
gl_load_texture_data((GLuint)*id,
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, driver.gfx_use_rgba ?
|
ti, RARCH_WRAP_EDGE, filter_type);
|
||||||
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);
|
|
||||||
|
|
||||||
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
|
#endif
|
||||||
|
|
||||||
@ -89,7 +67,7 @@ static int menu_texture_png_load_wrap(void *data)
|
|||||||
if (!filename)
|
if (!filename)
|
||||||
return 0;
|
return 0;
|
||||||
return menu_texture_png_load(filename, TEXTURE_BACKEND_DEFAULT,
|
return menu_texture_png_load(filename, TEXTURE_BACKEND_DEFAULT,
|
||||||
TEXTURE_FILTER_DEFAULT);
|
TEXTURE_FILTER_LINEAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int menu_texture_png_load_wrap_gl_mipmap(void *data)
|
static int menu_texture_png_load_wrap_gl_mipmap(void *data)
|
||||||
@ -98,7 +76,7 @@ static int menu_texture_png_load_wrap_gl_mipmap(void *data)
|
|||||||
if (!filename)
|
if (!filename)
|
||||||
return 0;
|
return 0;
|
||||||
return menu_texture_png_load(filename, TEXTURE_BACKEND_OPENGL,
|
return menu_texture_png_load(filename, TEXTURE_BACKEND_OPENGL,
|
||||||
TEXTURE_FILTER_MIPMAP);
|
TEXTURE_FILTER_MIPMAP_LINEAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int menu_texture_png_load_wrap_gl(void *data)
|
static int menu_texture_png_load_wrap_gl(void *data)
|
||||||
@ -107,7 +85,7 @@ static int menu_texture_png_load_wrap_gl(void *data)
|
|||||||
if (!filename)
|
if (!filename)
|
||||||
return 0;
|
return 0;
|
||||||
return menu_texture_png_load(filename, TEXTURE_BACKEND_OPENGL,
|
return menu_texture_png_load(filename, TEXTURE_BACKEND_OPENGL,
|
||||||
TEXTURE_FILTER_DEFAULT);
|
TEXTURE_FILTER_LINEAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned menu_texture_load(const char *path,
|
unsigned menu_texture_load(const char *path,
|
||||||
@ -125,7 +103,8 @@ unsigned menu_texture_load(const char *path,
|
|||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case TEXTURE_BACKEND_OPENGL:
|
case TEXTURE_BACKEND_OPENGL:
|
||||||
if (filter_type == TEXTURE_FILTER_MIPMAP)
|
if (filter_type == TEXTURE_FILTER_MIPMAP_LINEAR ||
|
||||||
|
filter_type == TEXTURE_FILTER_MIPMAP_NEAREST)
|
||||||
thr->cmd_data.custom_command.method = menu_texture_png_load_wrap_gl_mipmap;
|
thr->cmd_data.custom_command.method = menu_texture_png_load_wrap_gl_mipmap;
|
||||||
else
|
else
|
||||||
thr->cmd_data.custom_command.method = menu_texture_png_load_wrap_gl;
|
thr->cmd_data.custom_command.method = menu_texture_png_load_wrap_gl;
|
||||||
|
@ -17,18 +17,14 @@
|
|||||||
#ifndef _MENU_TEXTURE_MANAGER_H
|
#ifndef _MENU_TEXTURE_MANAGER_H
|
||||||
#define _MENU_TEXTURE_MANAGER_H
|
#define _MENU_TEXTURE_MANAGER_H
|
||||||
|
|
||||||
|
#include "../gfx/video_driver.h"
|
||||||
|
|
||||||
enum texture_backend_type
|
enum texture_backend_type
|
||||||
{
|
{
|
||||||
TEXTURE_BACKEND_DEFAULT = 0,
|
TEXTURE_BACKEND_DEFAULT = 0,
|
||||||
TEXTURE_BACKEND_OPENGL,
|
TEXTURE_BACKEND_OPENGL,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum texture_filter_type
|
|
||||||
{
|
|
||||||
TEXTURE_FILTER_DEFAULT = 0,
|
|
||||||
TEXTURE_FILTER_MIPMAP,
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user