Abstract away GL code in menu behind display driver interface

This commit is contained in:
twinaphex 2015-11-08 01:30:07 +01:00
parent c3ef432abe
commit a9b7636ddb
15 changed files with 645 additions and 325 deletions

View File

@ -450,6 +450,7 @@ ifeq ($(HAVE_MENU_COMMON), 1)
menu/menu_display.o \
menu/menu_displaylist.o \
menu/menu_animation.o \
menu/drivers_display/menu_display_null.o \
menu/drivers/menu_generic.o \
menu/drivers/null.o
endif
@ -577,6 +578,10 @@ ifeq ($(HAVE_GL_CONTEXT), 1)
gfx/drivers_font/gl_raster_font.o \
libretro-common/gfx/math/matrix_4x4.o \
libretro-common/glsym/rglgen.o
ifeq ($(HAVE_MENU_COMMON), 1)
OBJ += menu/drivers_display/menu_display_gl.o
endif
ifeq ($(HAVE_KMS), 1)
OBJ += gfx/drivers_context/drm_egl_ctx.o

View File

@ -139,6 +139,9 @@ VIDEO CONTEXT
#include "../gfx/drivers_context/vc_egl_ctx.c"
#endif
#ifdef HAVE_MENU
#include "../menu/drivers_display/menu_display_gl.c"
#endif
#if defined(_WIN32) && !defined(_XBOX)
#include "../gfx/drivers_context/wgl_ctx.c"
@ -814,6 +817,7 @@ MENU
#include "../menu/intl/menu_hash_pt.c"
#include "../menu/intl/menu_hash_us.c"
#include "../menu/drivers_display/menu_display_null.c"
#include "../menu/drivers/null.c"
#include "../menu/drivers/menu_generic.c"
#endif

View File

@ -25,6 +25,9 @@
#include <retro_log.h>
#include <compat/posix_string.h>
#include <file/file_path.h>
#include <formats/image.h>
#include <gfx/math/matrix_4x4.h>
#include <string/string_list.h>
#include "menu_generic.h"
@ -34,6 +37,8 @@
#include "../menu_hash.h"
#include "../menu_display.h"
#include "../../configuration.h"
#include "../../runloop.h"
#include "../../runloop_data.h"
enum
@ -62,7 +67,7 @@ enum
struct mui_texture_item
{
GRuint id;
uintptr_t id;
};
typedef struct mui_handle
@ -85,7 +90,7 @@ typedef struct mui_handle
struct mui_texture_item bg;
struct mui_texture_item list[MUI_TEXTURE_LAST];
GRuint white;
uintptr_t white;
} textures;
struct
@ -160,11 +165,11 @@ static void mui_context_reset_textures(mui_handle_t *mui, const char *iconpath)
}
static void mui_draw_icon(mui_handle_t *mui,
GRuint texture,
uintptr_t texture,
float x, float y,
unsigned width, unsigned height,
float rotation, float scale_factor,
GRfloat *color)
float *color)
{
struct gfx_coords coords;
math_matrix_4x4 mymat;
@ -179,7 +184,7 @@ static void mui_draw_icon(mui_handle_t *mui,
coords.lut_tex_coord = NULL;
coords.color = (const float*)color;
menu_display_draw_frame(
menu_display_draw(
x,
height - y - mui->icon_size,
mui->icon_size,
@ -217,7 +222,7 @@ static void mui_blit_line(float x, float y, unsigned width, unsigned height,
static void mui_render_quad(int x, int y, unsigned w, unsigned h,
unsigned width, unsigned height,
GRfloat *coord_color)
float *coord_color)
{
struct gfx_coords coords;
@ -232,7 +237,7 @@ static void mui_render_quad(int x, int y, unsigned w, unsigned h,
menu_display_blend_begin();
menu_display_draw_frame(
menu_display_draw(
x,
height - y - h,
w,
@ -243,7 +248,7 @@ static void mui_render_quad(int x, int y, unsigned w, unsigned h,
menu_display_blend_end();
}
static void mui_draw_scrollbar(unsigned width, unsigned height, GRfloat *coord_color)
static void mui_draw_scrollbar(unsigned width, unsigned height, float *coord_color)
{
unsigned header_height;
float content_height, total_height, scrollbar_height, scrollbar_margin, y;
@ -405,14 +410,14 @@ static void mui_render(void)
static void mui_render_label_value(mui_handle_t *mui,
int y, unsigned width, unsigned height,
uint64_t index, uint32_t color, bool selected, const char *label,
const char *value, GRfloat *pure_white)
const char *value, float *pure_white)
{
char label_str[PATH_MAX_LENGTH];
char value_str[PATH_MAX_LENGTH];
int value_len = strlen(value);
int ticker_limit = 0;
size_t usable_width = 0;
GRuint texture_switch = 0;
uintptr_t texture_switch = 0;
bool do_draw_text = false;
uint32_t hash_value = 0;
@ -506,7 +511,7 @@ static void mui_render_menu_list(mui_handle_t *mui,
menu_handle_t *menu,
uint32_t normal_color,
uint32_t hover_color,
GRfloat *pure_white)
float *pure_white)
{
unsigned header_height;
size_t i = 0;
@ -547,7 +552,7 @@ static void mui_render_menu_list(mui_handle_t *mui,
}
static void mui_draw_cursor(mui_handle_t *mui,
GRfloat *color,
float *color,
float x, float y, unsigned width, unsigned height)
{
struct gfx_coords coords;
@ -560,7 +565,7 @@ static void mui_draw_cursor(mui_handle_t *mui,
menu_display_blend_begin();
menu_display_draw_frame(
menu_display_draw(
x - 32,
height - y - 32,
64,
@ -591,7 +596,7 @@ static size_t mui_list_get_size(void *data, menu_list_type_t type)
return list_size;
}
static void bgcolor_setalpha(GRfloat *bg, float alpha)
static void bgcolor_setalpha(float *bg, float alpha)
{
bg[3] = alpha;
bg[7] = alpha;
@ -603,49 +608,49 @@ static void mui_frame(void)
{
unsigned header_height;
bool display_kb;
GRfloat black_bg[16] = {
float black_bg[16] = {
0, 0, 0, 0.75,
0, 0, 0, 0.75,
0, 0, 0, 0.75,
0, 0, 0, 0.75,
};
GRfloat blue_bg[16] = {
float blue_bg[16] = {
0.13, 0.59, 0.95, 1,
0.13, 0.59, 0.95, 1,
0.13, 0.59, 0.95, 1,
0.13, 0.59, 0.95, 1,
};
GRfloat lightblue_bg[16] = {
float lightblue_bg[16] = {
0.89, 0.95, 0.99, 1.00,
0.89, 0.95, 0.99, 1.00,
0.89, 0.95, 0.99, 1.00,
0.89, 0.95, 0.99, 1.00,
};
GRfloat pure_white[16]= {
float pure_white[16]= {
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
};
GRfloat white_bg[16]= {
float white_bg[16]= {
0.98, 0.98, 0.98, 1,
0.98, 0.98, 0.98, 1,
0.98, 0.98, 0.98, 1,
0.98, 0.98, 0.98, 1,
};
GRfloat white_transp_bg[16]= {
float white_transp_bg[16]= {
0.98, 0.98, 0.98, 0.90,
0.98, 0.98, 0.98, 0.90,
0.98, 0.98, 0.98, 0.90,
0.98, 0.98, 0.98, 0.90,
};
GRfloat grey_bg[16]= {
float grey_bg[16]= {
0.78, 0.78, 0.78, 1,
0.78, 0.78, 0.78, 1,
0.78, 0.78, 0.78, 1,
0.78, 0.78, 0.78, 1,
};
GRfloat shadow_bg[16]= {
float shadow_bg[16]= {
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0.2,
@ -689,7 +694,7 @@ static void mui_frame(void)
if (libretro_running)
{
menu_display_frame_background(
menu_display_draw_bg(
width, height,
mui->textures.white, 0.75f, false,
&white_transp_bg[0], &white_bg[0],
@ -707,7 +712,7 @@ static void mui_frame(void)
/* Set new opacity for transposed white background */
bgcolor_setalpha(white_transp_bg, 0.30);
menu_display_frame_background(
menu_display_draw_bg(
width, height,
mui->textures.bg.id, 0.75f, true,
&white_transp_bg[0], &white_bg[0],
@ -948,7 +953,7 @@ static void *mui_init(void)
if (!menu)
goto error;
if (!menu_display_check_compatibility((enum menu_display_driver_type)menu_ctx_mui.type))
if (!menu_display_driver_init_first())
goto error;
menu->userdata = (mui_handle_t*)calloc(1, sizeof(mui_handle_t));
@ -1422,7 +1427,6 @@ menu_ctx_driver_t menu_ctx_mui = {
NULL,
mui_load_image,
"glui",
MENU_VIDEO_DRIVER_OPENGL,
mui_environ,
mui_pointer_tap,
};

View File

@ -56,7 +56,6 @@ menu_ctx_driver_t menu_ctx_null = {
NULL, /* bind_init */
NULL, /* load_image */
"null",
MENU_VIDEO_DRIVER_GENERIC,
NULL,
NULL,
};

View File

@ -902,7 +902,6 @@ menu_ctx_driver_t menu_ctx_rgui = {
NULL,
NULL,
"rgui",
MENU_VIDEO_DRIVER_GENERIC,
rgui_environ,
rgui_pointer_tap,
};

View File

@ -357,7 +357,6 @@ menu_ctx_driver_t menu_ctx_rmenu = {
NULL,
NULL,
"rmenu",
MENU_VIDEO_DRIVER_DIRECT3D,
rmenu_environ,
NULL,
};

View File

@ -723,7 +723,6 @@ menu_ctx_driver_t menu_ctx_rmenu_xui = {
rmenu_xui_list_set_selection,
NULL,
"rmenu_xui",
MENU_VIDEO_DRIVER_DIRECT3D,
rmenu_xui_environ,
NULL,
};

View File

@ -22,8 +22,12 @@
#include <file/file_path.h>
#include <compat/posix_string.h>
#include <compat/strl.h>
#include <retro_log.h>
#include <formats/image.h>
#include <string/stdstring.h>
#include <string/string_list.h>
#include <gfx/math/matrix_4x4.h>
#include "menu_generic.h"
@ -37,8 +41,10 @@
#include "../menu_cbs.h"
#include "../../configuration.h"
#include "../../file_ext.h"
#include "../../runloop.h"
#include "../../runloop_data.h"
#ifndef XMB_THEME
@ -71,8 +77,8 @@ typedef struct
float zoom;
float x;
float y;
GRuint icon;
GRuint content_icon;
uintptr_t icon;
uintptr_t content_icon;
} xmb_node_t;
enum
@ -125,7 +131,7 @@ enum
struct xmb_texture_item
{
GRuint id;
uintptr_t id;
};
typedef struct xmb_handle
@ -139,7 +145,7 @@ typedef struct xmb_handle
char box_message[PATH_MAX_LENGTH];
float x;
float alpha;
GRuint boxart;
uintptr_t boxart;
float boxart_size;
char background_file_path[PATH_MAX_LENGTH];
@ -323,11 +329,11 @@ static float xmb_item_y(xmb_handle_t *xmb, int i, size_t current)
}
static void xmb_draw_icon(xmb_handle_t *xmb,
GRuint texture,
uintptr_t texture,
float x, float y,
unsigned width, unsigned height,
float rotation, float scale_factor,
GRfloat *color)
float *color)
{
struct gfx_coords coords;
math_matrix_4x4 mymat;
@ -347,7 +353,7 @@ static void xmb_draw_icon(xmb_handle_t *xmb,
coords.lut_tex_coord = NULL;
coords.color = (const float*)color;
menu_display_draw_frame(
menu_display_draw(
x,
height - y,
xmb->icon.size,
@ -358,11 +364,11 @@ static void xmb_draw_icon(xmb_handle_t *xmb,
static void xmb_draw_icon_predone(xmb_handle_t *xmb,
math_matrix_4x4 *mymat,
GRuint texture,
uintptr_t texture,
float x, float y,
unsigned width, unsigned height,
float alpha, float rotation, float scale_factor,
GRfloat *color)
float *color)
{
struct gfx_coords coords;
@ -379,7 +385,7 @@ static void xmb_draw_icon_predone(xmb_handle_t *xmb,
coords.lut_tex_coord = NULL;
coords.color = color;
menu_display_draw_frame(
menu_display_draw(
x,
height - y,
xmb->icon.size,
@ -388,7 +394,7 @@ static void xmb_draw_icon_predone(xmb_handle_t *xmb,
MENU_DISPLAY_PRIM_TRIANGLESTRIP);
}
static void xmb_draw_boxart(xmb_handle_t *xmb, GRfloat *color, unsigned width, unsigned height)
static void xmb_draw_boxart(xmb_handle_t *xmb, float *color, unsigned width, unsigned height)
{
struct gfx_coords coords;
math_matrix_4x4 mymat;
@ -404,7 +410,7 @@ static void xmb_draw_boxart(xmb_handle_t *xmb, GRfloat *color, unsigned width, u
coords.lut_tex_coord = NULL;
coords.color = (const float*)color;
menu_display_draw_frame(
menu_display_draw(
x,
height - y,
xmb->boxart_size,
@ -1219,7 +1225,7 @@ static void xmb_populate_entries(const char *path,
xmb_list_open(xmb);
}
static GRuint xmb_icon_get_id(xmb_handle_t *xmb,
static uintptr_t xmb_icon_get_id(xmb_handle_t *xmb,
xmb_node_t *core_node, xmb_node_t *node, unsigned type, bool active)
{
switch(type)
@ -1287,7 +1293,7 @@ static GRuint xmb_icon_get_id(xmb_handle_t *xmb,
static void xmb_draw_items(xmb_handle_t *xmb,
file_list_t *list, file_list_t *stack,
size_t current, size_t cat_selection_ptr, GRfloat *color,
size_t current, size_t cat_selection_ptr, float *color,
unsigned width, unsigned height)
{
unsigned i, ticker_limit;
@ -1321,8 +1327,8 @@ static void xmb_draw_items(xmb_handle_t *xmb,
const float half_size = xmb->icon.size / 2.0f;
menu_entry_t entry = {{0}};
GRuint texture_switch = 0;
GRuint icon = 0;
uintptr_t texture_switch = 0;
uintptr_t icon = 0;
xmb_node_t * node = (xmb_node_t*)menu_entries_get_userdata_at_offset(list, i);
uint32_t hash_label = 0;
uint32_t hash_value = 0;
@ -1514,7 +1520,7 @@ static void xmb_draw_items(xmb_handle_t *xmb,
}
static void xmb_draw_cursor(xmb_handle_t *xmb,
GRfloat *color,
float *color,
float x, float y, unsigned width, unsigned height)
{
struct gfx_coords coords;
@ -1527,7 +1533,7 @@ static void xmb_draw_cursor(xmb_handle_t *xmb,
menu_display_blend_begin();
menu_display_draw_frame(
menu_display_draw(
x - (xmb->cursor.size/2),
height - y - (xmb->cursor.size/2),
xmb->cursor.size,
@ -1597,7 +1603,7 @@ static void xmb_render(void)
static void xmb_frame_horizontal_list(xmb_handle_t *xmb,
menu_handle_t *menu, unsigned width, unsigned height,
GRfloat *color)
float *color)
{
unsigned i;
size_t list_size = xmb_list_get_size(menu, MENU_LIST_HORIZONTAL) + XMB_SYSTEM_TAB_END;
@ -1637,9 +1643,9 @@ static void xmb_frame(void)
char msg[PATH_MAX_LENGTH];
char title_msg[PATH_MAX_LENGTH];
char timedate[PATH_MAX_LENGTH];
GRfloat item_color[16];
GRfloat coord_color[16];
GRfloat coord_color2[16];
float item_color[16];
float coord_color[16];
float coord_color2[16];
bool display_kb;
bool render_background = false;
xmb_handle_t *xmb = NULL;
@ -1680,7 +1686,7 @@ static void xmb_frame(void)
coord_color[3] = coord_color[7] = coord_color[11] = coord_color[15] = (0.75f > xmb->alpha) ? xmb->alpha : 0.75f;
coord_color2[3] = coord_color2[7] = coord_color2[11] = coord_color2[15] = xmb->alpha;
menu_display_frame_background(
menu_display_draw_bg(
width, height, xmb->textures.bg.id, xmb->alpha, false, &coord_color[0],
&coord_color2[0], NULL, NULL, 4,
MENU_DISPLAY_PRIM_TRIANGLESTRIP);
@ -1784,7 +1790,7 @@ static void xmb_frame(void)
if (render_background)
{
menu_display_frame_background(
menu_display_draw_bg(
width, height,
xmb->textures.bg.id, xmb->alpha, true,
&coord_color[0], &coord_color2[0],
@ -1943,7 +1949,7 @@ static void *xmb_init(void)
if (!menu)
goto error;
if (!menu_display_check_compatibility((enum menu_display_driver_type)menu_ctx_xmb.type))
if (!menu_display_driver_init_first())
goto error;
video_driver_get_size(&width, &height);
@ -2749,7 +2755,6 @@ menu_ctx_driver_t menu_ctx_xmb = {
xmb_list_bind_init,
xmb_load_image,
"xmb",
MENU_VIDEO_DRIVER_OPENGL,
xmb_environ,
xmb_pointer_tap,
};

View File

@ -24,6 +24,8 @@
#include <file/file_path.h>
#include <file/dir_list.h>
#include <compat/posix_string.h>
#include <gfx/math/matrix_4x4.h>
#include <formats/image.h>
#include <compat/strl.h>
#include <retro_log.h>
#include <retro_stat.h>
@ -43,6 +45,9 @@
#include "../../gfx/font_driver.h"
#include "../../configuration.h"
#include "../../runloop.h"
#if 0
#define ZARCH_DEBUG
#endif
@ -1039,7 +1044,7 @@ static void zarch_frame(void)
menu_display_blend_begin();
menu_display_draw_frame(
menu_display_draw(
0,
0,
zui->width,
@ -1050,7 +1055,7 @@ static void zarch_frame(void)
menu_display_blend_end();
menu_display_frame_background(
menu_display_draw_bg(
zui->width, zui->height,
zui->textures.bg.id, 0.75f, false,
&coord_color[0], &coord_color2[0],
@ -1074,7 +1079,7 @@ static void *zarch_init(void)
if (!menu)
goto error;
if (!menu_display_check_compatibility((enum menu_display_driver_type)menu_ctx_zarch.type))
if (!menu_display_driver_init_first())
goto error;
menu->userdata = (zui_t*)calloc(1, sizeof(zui_t));
@ -1359,7 +1364,6 @@ menu_ctx_driver_t menu_ctx_zarch = {
NULL,
zarch_load_image,
"zarch",
MENU_VIDEO_DRIVER_OPENGL,
NULL,
NULL,
};

View File

@ -0,0 +1,247 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2011-2015 - Daniel De Matteis
*
* 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 <time.h>
#include <queues/message_queue.h>
#include <retro_miscellaneous.h>
#include <gfx/math/matrix_4x4.h>
#include "../../config.def.h"
#include "../../gfx/font_renderer_driver.h"
#include "../../gfx/video_context_driver.h"
#include "../../gfx/video_thread_wrapper.h"
#include "../../gfx/video_texture.h"
#include "../../gfx/drivers/gl_common.h"
#include "../menu_display.h"
static const GLfloat gl_vertexes[] = {
0, 0,
1, 0,
0, 1,
1, 1
};
static const GLfloat gl_tex_coords[] = {
0, 1,
1, 1,
0, 0,
1, 0
};
static math_matrix_4x4 *menu_display_get_default_mvp(void)
{
gl_t *gl = (gl_t*)video_driver_get_ptr(NULL);
if (!gl)
return NULL;
return (math_matrix_4x4*)&gl->mvp_no_rot;
}
static GLenum menu_display_prim_to_gl_enum(enum menu_display_prim_type prim_type)
{
switch (prim_type)
{
case MENU_DISPLAY_PRIM_TRIANGLESTRIP:
return GL_TRIANGLE_STRIP;
case MENU_DISPLAY_PRIM_TRIANGLES:
return GL_TRIANGLES;
case MENU_DISPLAY_PRIM_NONE:
default:
break;
}
return 0;
}
static void menu_display_gl_blend_begin(void)
{
gl_t *gl = (gl_t*)video_driver_get_ptr(NULL);
if (!gl)
return;
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
if (gl->shader && gl->shader->use)
gl->shader->use(gl, GL_SHADER_STOCK_BLEND);
}
static void menu_display_gl_blend_end(void)
{
glDisable(GL_BLEND);
}
static void menu_display_gl_draw(
unsigned x, unsigned y,
unsigned width, unsigned height,
struct gfx_coords *coords,
void *matrix_data,
uintptr_t texture,
enum menu_display_prim_type prim_type
)
{
driver_t *driver = driver_get_ptr();
gl_t *gl = (gl_t*)video_driver_get_ptr(NULL);
math_matrix_4x4 *mat = (math_matrix_4x4*)matrix_data;
if (!gl)
return;
/* TODO - edge case */
if (height <= 0)
height = 1;
if (!mat)
mat = &gl->mvp_no_rot;
if (!coords->vertex)
coords->vertex = &gl_vertexes[0];
if (!coords->tex_coord)
coords->tex_coord = &gl_tex_coords[0];
if (!coords->lut_tex_coord)
coords->lut_tex_coord = &gl_tex_coords[0];
glViewport(x, y, width, height);
glBindTexture(GL_TEXTURE_2D, (GLuint)texture);
gl->shader->set_coords(coords);
gl->shader->set_mvp(driver->video_data, mat);
glDrawArrays(menu_display_prim_to_gl_enum(prim_type), 0, coords->vertices);
gl->coords.color = gl->white_color_ptr;
}
static void menu_display_gl_draw_bg(
unsigned width,
unsigned height,
uintptr_t texture,
float handle_alpha,
bool force_transparency,
GLfloat *coord_color,
GLfloat *coord_color2,
const float *vertex,
const float *tex_coord,
size_t vertex_count,
enum menu_display_prim_type prim_type)
{
struct gfx_coords coords;
const GLfloat *new_vertex = NULL;
const GLfloat *new_tex_coord = NULL;
global_t *global = global_get_ptr();
settings_t *settings = config_get_ptr();
gl_t *gl = (gl_t*)video_driver_get_ptr(NULL);
if (!gl)
return;
new_vertex = vertex;
new_tex_coord = tex_coord;
if (!new_vertex)
new_vertex = &gl_vertexes[0];
if (!new_tex_coord)
new_tex_coord = &gl_tex_coords[0];
coords.vertices = vertex_count;
coords.vertex = new_vertex;
coords.tex_coord = new_tex_coord;
coords.lut_tex_coord = new_tex_coord;
coords.color = (const float*)coord_color;
menu_display_gl_blend_begin();
menu_display_ctl(MENU_DISPLAY_CTL_SET_VIEWPORT, NULL);
if ((settings->menu.pause_libretro
|| !global->inited.main || (global->inited.core.type == CORE_TYPE_DUMMY))
&& !force_transparency
&& texture)
coords.color = (const float*)coord_color2;
menu_display_gl_draw(0, 0, width, height,
&coords, &gl->mvp_no_rot,
(GLuint)texture, prim_type);
menu_display_gl_blend_end();
gl->coords.color = gl->white_color_ptr;
}
static void menu_display_gl_restore_clear_color(void)
{
glClearColor(0.0f, 0.0f, 0.0f, 0.00f);
}
static void menu_display_gl_clear_color(float r, float g, float b, float a)
{
glClearColor(r, g, b, a);
glClear(GL_COLOR_BUFFER_BIT);
}
static void menu_display_gl_matrix_4x4_rotate_z(void *data, float rotation,
float scale_x, float scale_y, float scale_z, bool scale_enable)
{
math_matrix_4x4 matrix_rotated;
math_matrix_4x4 matrix_scaled;
math_matrix_4x4 *matrix = (math_matrix_4x4*)data;
math_matrix_4x4 *b = menu_display_get_default_mvp();
if (!matrix)
return;
matrix_4x4_rotate_z(&matrix_rotated, rotation);
matrix_4x4_multiply(matrix, &matrix_rotated, b);
if (!scale_enable)
return;
matrix_4x4_scale(&matrix_scaled, scale_x, scale_y, scale_z);
matrix_4x4_multiply(matrix, &matrix_scaled, matrix);
}
static unsigned menu_display_gl_texture_load(void *data, enum texture_filter_type type)
{
return video_texture_load(data, TEXTURE_BACKEND_OPENGL, type);
}
static void menu_display_gl_texture_unload(uintptr_t *id)
{
if (!id)
return;
video_texture_unload(id);
}
static const float *menu_display_gl_get_tex_coords(void)
{
return &gl_tex_coords[0];
}
menu_display_ctx_driver_t menu_display_ctx_gl = {
menu_display_gl_draw,
menu_display_gl_draw_bg,
menu_display_gl_blend_begin,
menu_display_gl_blend_end,
menu_display_gl_restore_clear_color,
menu_display_gl_clear_color,
menu_display_gl_matrix_4x4_rotate_z,
menu_display_gl_get_tex_coords,
menu_display_gl_texture_load,
menu_display_gl_texture_unload,
MENU_VIDEO_DRIVER_OPENGL,
"menu_display_gl",
};

View File

@ -0,0 +1,105 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2011-2015 - Daniel De Matteis
*
* 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 <time.h>
#include <queues/message_queue.h>
#include <retro_miscellaneous.h>
#include <gfx/math/matrix_4x4.h>
#include "../../config.def.h"
#include "../../gfx/font_renderer_driver.h"
#include "../../gfx/video_context_driver.h"
#include "../../gfx/video_thread_wrapper.h"
#include "../../gfx/video_texture.h"
#include "../menu_display.h"
static void menu_display_null_blend_begin(void)
{
}
static void menu_display_null_blend_end(void)
{
}
static void menu_display_null_draw(
unsigned x, unsigned y,
unsigned width, unsigned height,
struct gfx_coords *coords,
void *matrix_data,
uintptr_t texture,
enum menu_display_prim_type prim_type
)
{
}
static void menu_display_null_draw_bg(
unsigned width,
unsigned height,
uintptr_t texture,
float handle_alpha,
bool force_transparency,
float *coord_color,
float *coord_color2,
const float *vertex,
const float *tex_coord,
size_t vertex_count,
enum menu_display_prim_type prim_type)
{
}
static void menu_display_null_restore_clear_color(void)
{
}
static void menu_display_null_clear_color(float r, float g, float b, float a)
{
}
static void menu_display_null_matrix_4x4_rotate_z(void *data, float rotation,
float scale_x, float scale_y, float scale_z, bool scale_enable)
{
}
static unsigned menu_display_null_texture_load(void *data, enum texture_filter_type type)
{
return 0;
}
static void menu_display_null_texture_unload(uintptr_t *id)
{
}
static const float *menu_display_null_get_tex_coords(void)
{
static float floats[1] = {1.00f};
return &floats[0];
}
menu_display_ctx_driver_t menu_display_ctx_null = {
menu_display_null_draw,
menu_display_null_draw_bg,
menu_display_null_blend_begin,
menu_display_null_blend_end,
menu_display_null_restore_clear_color,
menu_display_null_clear_color,
menu_display_null_matrix_4x4_rotate_z,
menu_display_null_get_tex_coords,
menu_display_null_texture_load,
menu_display_null_texture_unload,
MENU_VIDEO_DRIVER_GENERIC,
"menu_display_null",
};

View File

@ -20,10 +20,7 @@
#include <gfx/math/matrix_4x4.h>
#include "../config.def.h"
#include "../gfx/font_renderer_driver.h"
#include "../gfx/video_context_driver.h"
#include "../gfx/video_thread_wrapper.h"
#include "../gfx/video_texture.h"
#include "menu.h"
#include "menu_animation.h"
@ -58,8 +55,18 @@ typedef struct menu_display
unsigned header_height;
msg_queue_t *msg_queue;
menu_display_ctx_driver_t *display_ctx;
} menu_display_t;
static menu_display_ctx_driver_t *menu_display_ctx_drivers[] = {
#ifdef HAVE_OPENGL
&menu_display_ctx_gl,
#endif
&menu_display_ctx_null,
NULL,
};
static menu_display_t menu_display_state;
static menu_framebuf_t frame_buf_state;
@ -69,6 +76,14 @@ static menu_display_t *menu_display_get_ptr(void)
return &menu_display_state;
}
static menu_display_ctx_driver_t *menu_display_context_get_ptr(void)
{
menu_display_t *disp = menu_display_get_ptr();
if (!disp)
return NULL;
return disp->display_ctx;
}
static menu_framebuf_t *menu_display_fb_get_ptr(void)
{
return &frame_buf_state;
@ -187,6 +202,58 @@ void menu_display_free_main_font(void)
}
}
static const char *menu_video_get_ident(void)
{
#ifdef HAVE_THREADS
settings_t *settings = config_get_ptr();
if (settings->video.threaded)
return rarch_threaded_video_get_ident();
#endif
return video_driver_get_ident();
}
static bool menu_display_check_compatibility(enum menu_display_driver_type type)
{
const char *video_driver = menu_video_get_ident();
switch (type)
{
case MENU_VIDEO_DRIVER_GENERIC:
return true;
case MENU_VIDEO_DRIVER_OPENGL:
if (!strcmp(video_driver, "gl"))
return true;
break;
case MENU_VIDEO_DRIVER_DIRECT3D:
if (!strcmp(video_driver, "d3d"))
return true;
break;
}
return false;
}
const bool menu_display_driver_init_first(void)
{
unsigned i;
menu_display_t *disp = menu_display_get_ptr();
for (i = 0; menu_display_ctx_drivers[i]; i++)
{
if (!menu_display_check_compatibility(menu_display_ctx_drivers[i]->type))
continue;
RARCH_LOG("Found menu display driver: \"%s\".\n",
menu_display_ctx_drivers[i]->ident);
disp->display_ctx = menu_display_ctx_drivers[i];
return true;
}
return false;
}
bool menu_display_init_main_font(void *data,
const char *font_path, float font_size)
{
@ -491,248 +558,114 @@ void menu_display_msg_queue_push(const char *msg, unsigned prio, unsigned durati
rarch_main_msg_queue_push(msg, prio, duration, flush);
}
#ifdef HAVE_OPENGL
static const float gl_vertexes[] = {
0, 0,
1, 0,
0, 1,
1, 1
};
static const float gl_tex_coords[] = {
0, 1,
1, 1,
0, 0,
1, 0
};
static math_matrix_4x4 *menu_display_get_default_mvp(void)
{
gl_t *gl = (gl_t*)video_driver_get_ptr(NULL);
if (!gl)
return NULL;
return (math_matrix_4x4*)&gl->mvp_no_rot;
}
const float *menu_display_get_tex_coords(void)
{
return &gl_tex_coords[0];
}
static GLenum menu_display_prim_to_gl_enum(enum menu_display_prim_type prim_type)
{
switch (prim_type)
{
case MENU_DISPLAY_PRIM_TRIANGLESTRIP:
return GL_TRIANGLE_STRIP;
case MENU_DISPLAY_PRIM_TRIANGLES:
return GL_TRIANGLES;
case MENU_DISPLAY_PRIM_NONE:
default:
break;
}
return 0;
}
void menu_display_blend_begin(void)
{
gl_t *gl = (gl_t*)video_driver_get_ptr(NULL);
if (!gl)
menu_display_ctx_driver_t *menu_disp = menu_display_context_get_ptr();
if (!menu_disp || !menu_disp->blend_begin)
return;
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
if (gl->shader && gl->shader->use)
gl->shader->use(gl, GL_SHADER_STOCK_BLEND);
menu_disp->blend_begin();
}
void menu_display_blend_end(void)
{
glDisable(GL_BLEND);
}
void menu_display_draw_frame(
unsigned x, unsigned y,
unsigned width, unsigned height,
struct gfx_coords *coords,
void *matrix_data,
GLuint texture,
enum menu_display_prim_type prim_type
)
{
driver_t *driver = driver_get_ptr();
gl_t *gl = (gl_t*)video_driver_get_ptr(NULL);
math_matrix_4x4 *mat = (math_matrix_4x4*)matrix_data;
if (!gl)
menu_display_ctx_driver_t *menu_disp = menu_display_context_get_ptr();
if (!menu_disp || !menu_disp->blend_end)
return;
/* TODO - edge case */
if (height <= 0)
height = 1;
if (!mat)
mat = &gl->mvp_no_rot;
if (!coords->vertex)
coords->vertex = &gl_vertexes[0];
if (!coords->tex_coord)
coords->tex_coord = &gl_tex_coords[0];
if (!coords->lut_tex_coord)
coords->lut_tex_coord = &gl_tex_coords[0];
glViewport(x, y, width, height);
glBindTexture(GL_TEXTURE_2D, texture);
gl->shader->set_coords(coords);
gl->shader->set_mvp(driver->video_data, mat);
glDrawArrays(menu_display_prim_to_gl_enum(prim_type), 0, coords->vertices);
gl->coords.color = gl->white_color_ptr;
}
void menu_display_frame_background(
unsigned width,
unsigned height,
GLuint texture,
float handle_alpha,
bool force_transparency,
GRfloat *coord_color,
GRfloat *coord_color2,
const GRfloat *vertex,
const GRfloat *tex_coord,
size_t vertex_count,
enum menu_display_prim_type prim_type)
{
struct gfx_coords coords;
const GRfloat *new_vertex = NULL;
const GRfloat *new_tex_coord = NULL;
global_t *global = global_get_ptr();
settings_t *settings = config_get_ptr();
gl_t *gl = (gl_t*)video_driver_get_ptr(NULL);
if (!gl)
return;
new_vertex = vertex;
new_tex_coord = tex_coord;
if (!new_vertex)
new_vertex = &gl_vertexes[0];
if (!new_tex_coord)
new_tex_coord = &gl_tex_coords[0];
coords.vertices = vertex_count;
coords.vertex = new_vertex;
coords.tex_coord = new_tex_coord;
coords.lut_tex_coord = new_tex_coord;
coords.color = (const float*)coord_color;
menu_display_blend_begin();
menu_display_ctl(MENU_DISPLAY_CTL_SET_VIEWPORT, NULL);
if ((settings->menu.pause_libretro
|| !global->inited.main || (global->inited.core.type == CORE_TYPE_DUMMY))
&& !force_transparency
&& texture)
coords.color = (const float*)coord_color2;
menu_display_draw_frame(0, 0, width, height,
&coords, &gl->mvp_no_rot,
texture, prim_type);
menu_display_blend_end();
gl->coords.color = gl->white_color_ptr;
}
void menu_display_restore_clear_color(void)
{
glClearColor(0.0f, 0.0f, 0.0f, 0.00f);
}
void menu_display_clear_color(float r, float g, float b, float a)
{
glClearColor(r, g, b, a);
glClear(GL_COLOR_BUFFER_BIT);
if (menu_disp)
menu_disp->blend_end();
}
void menu_display_matrix_4x4_rotate_z(void *data, float rotation,
float scale_x, float scale_y, float scale_z, bool scale_enable)
{
math_matrix_4x4 matrix_rotated;
math_matrix_4x4 matrix_scaled;
math_matrix_4x4 *matrix = (math_matrix_4x4*)data;
math_matrix_4x4 *b = menu_display_get_default_mvp();
if (!matrix)
menu_display_ctx_driver_t *menu_disp = menu_display_context_get_ptr();
if (!menu_disp)
return;
matrix_4x4_rotate_z(&matrix_rotated, rotation);
matrix_4x4_multiply(matrix, &matrix_rotated, b);
if (!scale_enable)
return;
matrix_4x4_scale(&matrix_scaled, scale_x, scale_y, scale_z);
matrix_4x4_multiply(matrix, &matrix_scaled, matrix);
menu_disp->matrix_4x4_rotate_z(data, rotation, scale_x, scale_y, scale_z, scale_enable);
}
unsigned menu_display_texture_load(void *data, enum texture_filter_type type)
unsigned menu_display_texture_load(void *data,
enum texture_filter_type filter_type)
{
return video_texture_load(data, TEXTURE_BACKEND_OPENGL, type);
menu_display_ctx_driver_t *menu_disp = menu_display_context_get_ptr();
if (!menu_disp || !menu_disp->texture_load)
return 0;
return menu_disp->texture_load(data, filter_type);
}
void menu_display_texture_unload(uintptr_t *id)
{
if (!id)
menu_display_ctx_driver_t *menu_disp = menu_display_context_get_ptr();
if (!menu_disp || !menu_disp->texture_unload)
return;
video_texture_unload(id);
menu_disp->texture_unload(id);
}
#else
static math_matrix_4x4 *menu_display_get_default_mvp(void)
void menu_display_draw(unsigned x, unsigned y,
unsigned width, unsigned height,
struct gfx_coords *coords,
void *matrix_data,
uintptr_t texture,
enum menu_display_prim_type prim_type
)
{
return NULL;
menu_display_ctx_driver_t *menu_disp = menu_display_context_get_ptr();
if (!menu_disp || !menu_disp->draw)
return;
menu_disp->draw(x, y, width, height, coords, matrix_data, texture, prim_type);
}
#endif
static const char *menu_video_get_ident(void)
void menu_display_draw_bg(
unsigned width, unsigned height,
uintptr_t texture,
float handle_alpha,
bool force_transparency,
float *color,
float *color2,
const float *vertex,
const float *tex_coord,
size_t vertex_count,
enum menu_display_prim_type prim_type
)
{
#ifdef HAVE_THREADS
settings_t *settings = config_get_ptr();
menu_display_ctx_driver_t *menu_disp = menu_display_context_get_ptr();
if (!menu_disp || !menu_disp->draw_bg)
return;
if (settings->video.threaded)
return rarch_threaded_video_get_ident();
#endif
return video_driver_get_ident();
menu_disp->draw_bg(width, height, texture, handle_alpha, force_transparency, color,
color2, vertex, tex_coord, vertex_count, prim_type);
}
bool menu_display_check_compatibility(enum menu_display_driver_type type)
void menu_display_restore_clear_color(void)
{
const char *video_driver = menu_video_get_ident();
menu_display_ctx_driver_t *menu_disp = menu_display_context_get_ptr();
if (!menu_disp || !menu_disp->restore_clear_color)
return;
switch (type)
{
case MENU_VIDEO_DRIVER_GENERIC:
return true;
case MENU_VIDEO_DRIVER_OPENGL:
if (!strcmp(video_driver, "gl"))
return true;
break;
case MENU_VIDEO_DRIVER_DIRECT3D:
if (!strcmp(video_driver, "d3d"))
return true;
break;
}
RARCH_ERR("Cannot initialize menu driver: video driver of type %d is not active.\n", type);
return false;
menu_disp->restore_clear_color();
}
void menu_display_clear_color(float r, float g, float b, float a)
{
menu_display_ctx_driver_t *menu_disp = menu_display_context_get_ptr();
if (!menu_disp || !menu_disp->clear_color)
return;
menu_disp->clear_color(r, g, b, a);
}
const float *menu_display_get_tex_coords(void)
{
menu_display_ctx_driver_t *menu_disp = menu_display_context_get_ptr();
if (!menu_disp || !menu_disp->get_tex_coords)
return NULL;
return menu_disp->get_tex_coords();
}

View File

@ -21,18 +21,14 @@
#include <boolean.h>
#include "../gfx/video_texture.h"
#include "../gfx/video_context_driver.h"
#include "../gfx/font_renderer_driver.h"
#include "../gfx/video_common.h"
#ifdef __cplusplus
extern "C" {
#endif
enum menu_display_driver_type
{
MENU_VIDEO_DRIVER_GENERIC = 0,
MENU_VIDEO_DRIVER_OPENGL,
MENU_VIDEO_DRIVER_DIRECT3D
};
enum menu_display_ctl_state
{
MENU_DISPLAY_CTL_SET_VIEWPORT = 0,
@ -73,6 +69,49 @@ enum menu_display_prim_type
MENU_DISPLAY_PRIM_TRIANGLES
};
enum menu_display_driver_type
{
MENU_VIDEO_DRIVER_GENERIC = 0,
MENU_VIDEO_DRIVER_OPENGL,
MENU_VIDEO_DRIVER_DIRECT3D
};
typedef struct menu_display_ctx_driver
{
void (*draw)(unsigned x, unsigned y,
unsigned width, unsigned height,
struct gfx_coords *coords,
void *matrix_data,
uintptr_t texture,
enum menu_display_prim_type prim_type
);
void (*draw_bg)(
unsigned width, unsigned height,
uintptr_t texture,
float handle_alpha,
bool force_transparency,
float *color,
float *color2,
const float *vertex,
const float *tex_coord,
size_t vertex_count,
enum menu_display_prim_type prim_type
);
void (*blend_begin)(void);
void (*blend_end)(void);
void (*restore_clear_color)(void);
void (*clear_color)(float r, float g, float b, float a);
void (*matrix_4x4_rotate_z)(void *data, float rotation,
float scale_x, float scale_y, float scale_z, bool scale_enable);
const float *(*get_tex_coords)(void);
unsigned (*texture_load)(void *data, enum texture_filter_type type);
void (*texture_unload)(uintptr_t *id);
enum menu_display_driver_type type;
const char *ident;
} menu_display_ctx_driver_t;
void menu_display_free(void);
bool menu_display_init(void);
@ -97,52 +136,50 @@ void menu_display_timedate(char *s, size_t len, unsigned time_mode);
void menu_display_msg_queue_push(const char *msg, unsigned prio, unsigned duration,
bool flush);
#ifdef HAVE_OPENGL
#include "../gfx/drivers/gl_common.h"
void menu_display_draw_frame(
unsigned x, unsigned y,
const bool menu_display_driver_init_first(void);
void menu_display_draw(unsigned x, unsigned y,
unsigned width, unsigned height,
struct gfx_coords *coords,
void *matrix_data,
GLuint texture,
uintptr_t texture,
enum menu_display_prim_type prim_type
);
void menu_display_draw_bg(
unsigned width, unsigned height,
uintptr_t texture,
float handle_alpha,
bool force_transparency,
float *color,
float *color2,
const float *vertex,
const float *tex_coord,
size_t vertex_count,
enum menu_display_prim_type prim_type
);
void menu_display_matrix_4x4_rotate_z(void *data, float rotation,
float scale_x, float scale_y, float scale_z, bool scale_enable);
void menu_display_blend_begin(void);
void menu_display_blend_end(void);
void menu_display_frame_background(
unsigned width, unsigned height,
GLuint texture,
float handle_alpha,
bool force_transparency,
GRfloat *color,
GRfloat *color2,
const GRfloat *vertex,
const GRfloat *tex_coord,
size_t vertex_count,
enum menu_display_prim_type prim_type
);
unsigned menu_display_texture_load(void *data,
enum texture_filter_type filter_type);
void menu_display_restore_clear_color(void);
void menu_display_clear_color(float r, float g, float b, float a);
void menu_display_matrix_4x4_rotate_z(void *data, float rotation,
float scale_x, float scale_y, float scale_z, bool scale_enable);
#endif
void menu_display_texture_unload(uintptr_t *id);
const float *menu_display_get_tex_coords(void);
unsigned menu_display_texture_load(void *data,
enum texture_filter_type filter_type);
void menu_display_texture_unload(uintptr_t *id);
bool menu_display_check_compatibility(enum menu_display_driver_type type);
extern menu_display_ctx_driver_t menu_display_ctx_gl;
extern menu_display_ctx_driver_t menu_display_ctx_null;
#ifdef __cplusplus
}

View File

@ -115,22 +115,6 @@ void find_menu_driver(void)
}
}
static void init_menu_fallback(void)
{
#ifdef HAVE_RGUI
settings_t *settings = config_get_ptr();
driver_t *driver = driver_get_ptr();
int i = find_driver_index("menu_driver", "rgui");
if (i >= 0)
{
driver->menu_ctx = (const menu_ctx_driver_t*)menu_driver_find_handle(i);
if (settings)
strlcpy(settings->menu.driver, "rgui", sizeof(settings->menu.driver));
}
#endif
}
menu_handle_t *menu_driver_get_ptr(void)
{
driver_t *driver = driver_get_ptr();
@ -156,9 +140,6 @@ void init_menu(void)
find_menu_driver();
if (!menu_display_check_compatibility((enum menu_display_driver_type)driver->menu_ctx->type))
init_menu_fallback();
if (!(driver->menu = (menu_handle_t*)menu_init(driver->menu_ctx)))
retro_fail(1, "init_menu()");

View File

@ -135,7 +135,6 @@ typedef struct menu_ctx_driver
uint32_t label_hash, uint32_t menu_label_hash);
bool (*load_image)(void *data, menu_image_type_t type);
const char *ident;
unsigned type;
int (*environ_cb)(menu_environ_cb_t type, void *data);
int (*pointer_tap)(unsigned x, unsigned y, unsigned ptr,
menu_file_list_cbs_t *cbs,