From 71ca469cda75472c5ad4c0cd6facc75b2c58dfe2 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 2 Nov 2015 20:41:42 +0100 Subject: [PATCH] GL totally abstracted away now from menu drivers --- configuration.h | 4 ++-- driver.h | 4 ++-- menu/drivers/glui.c | 18 +++++++----------- menu/drivers/null.c | 1 + menu/drivers/xmb.c | 25 +++++++------------------ menu/drivers/zarch.c | 30 +++++++++++------------------- menu/menu_display.c | 34 ++++++++++++++++++++++++++++++---- menu/menu_display.h | 11 +++++++++-- menu/menu_driver.h | 9 +-------- 9 files changed, 70 insertions(+), 66 deletions(-) diff --git a/configuration.h b/configuration.h index ef104eb25f..5da6e54b22 100644 --- a/configuration.h +++ b/configuration.h @@ -14,8 +14,8 @@ * If not, see . */ -#ifndef __RARCH_SETTINGS_H__ -#define __RARCH_SETTINGS_H__ +#ifndef __RARCH_CONFIGURATION_H__ +#define __RARCH_CONFIGURATION_H__ #include #include diff --git a/driver.h b/driver.h index fcb6749610..6bd901a0db 100644 --- a/driver.h +++ b/driver.h @@ -14,8 +14,8 @@ * If not, see . */ -#ifndef __DRIVER__H -#define __DRIVER__H +#ifndef __RARCH_DRIVER__H +#define __RARCH_DRIVER__H #include #include diff --git a/menu/drivers/glui.c b/menu/drivers/glui.c index adc162967b..5cffc47035 100644 --- a/menu/drivers/glui.c +++ b/menu/drivers/glui.c @@ -705,7 +705,7 @@ static void glui_frame(void) if (libretro_running) { - menu_display_frame_background(menu, settings, + menu_display_frame_background( width, height, glui->textures.white, 0.75f, false, &white_transp_bg[0], &white_bg[0], @@ -727,7 +727,7 @@ static void glui_frame(void) white_transp_bg[11] = 0.30; white_transp_bg[15] = 0.30; - menu_display_frame_background(menu, settings, + menu_display_frame_background( width, height, glui->textures.bg.id, 0.75f, true, &white_transp_bg[0], &white_bg[0], @@ -977,19 +977,15 @@ static void glui_layout(menu_handle_t *menu, glui_handle_t *glui) static void *glui_init(void) { glui_handle_t *glui = NULL; - const video_driver_t *video_driver = NULL; - menu_handle_t *menu = NULL; - gl_t *gl = (gl_t*) - video_driver_get_ptr(&video_driver); - - if (video_driver != &video_gl || !gl) - goto error; - - menu = (menu_handle_t*)calloc(1, sizeof(*menu)); + menu_handle_t *menu = (menu_handle_t*) + calloc(1, sizeof(*menu)); if (!menu) goto error; + if (!menu_display_check_compatibility(menu_ctx_glui.type)) + goto error; + menu->userdata = (glui_handle_t*)calloc(1, sizeof(glui_handle_t)); if (!menu->userdata) diff --git a/menu/drivers/null.c b/menu/drivers/null.c index 08e3c68d8e..aca742eff6 100644 --- a/menu/drivers/null.c +++ b/menu/drivers/null.c @@ -20,6 +20,7 @@ #include #include #include "../menu_driver.h" +#include "../menu_display.h" #include "../menu.h" #include "../../general.h" diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index e3ec111c97..bb8650f24b 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -1570,7 +1570,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, settings, + menu_display_frame_background( width, height, xmb->textures.bg.id, xmb->alpha, false, &coord_color[0], &coord_color2[0], &rmb_vertex[0], &rmb_tex_coord[0], 4, MENU_DISPLAY_PRIM_TRIANGLESTRIP); @@ -1674,7 +1674,7 @@ static void xmb_frame(void) if (render_background) { - menu_display_frame_background(menu, settings, + menu_display_frame_background( width, height, xmb->textures.bg.id, xmb->alpha, true, &coord_color[0], &coord_color2[0], @@ -1821,26 +1821,15 @@ static void xmb_layout(menu_handle_t *menu, xmb_handle_t *xmb) static void *xmb_init(void) { unsigned width, height; - menu_handle_t *menu = NULL; - xmb_handle_t *xmb = NULL; - const video_driver_t *video_driver = NULL; - float scale_factor = 1; - gl_t *gl = (gl_t*) - video_driver_get_ptr(&video_driver); - - (void)scale_factor; - - if (video_driver != &video_gl || !gl) - { - RARCH_ERR("Cannot initialize XMB menu driver: GL video driver is not active.\n"); - return NULL; - } - - menu = (menu_handle_t*)calloc(1, sizeof(*menu)); + xmb_handle_t *xmb = NULL; + menu_handle_t *menu = (menu_handle_t*)calloc(1, sizeof(*menu)); if (!menu) goto error; + if (!menu_display_check_compatibility(menu_ctx_xmb.type)) + goto error; + video_driver_get_size(&width, &height); menu->userdata = (xmb_handle_t*)calloc(1, sizeof(xmb_handle_t)); diff --git a/menu/drivers/zarch.c b/menu/drivers/zarch.c index 241a60d1b6..99b1ff77ba 100644 --- a/menu/drivers/zarch.c +++ b/menu/drivers/zarch.c @@ -1065,7 +1065,7 @@ static void zarch_frame(void) menu_display_blend_end(); - menu_display_frame_background(menu, settings, + menu_display_frame_background( zui->width, zui->height, zui->textures.bg.id, 0.75f, false, &coord_color[0], &coord_color2[0], @@ -1083,29 +1083,15 @@ static void *zarch_init(void) { int unused; zui_t *zui = NULL; - const video_driver_t *video_driver = NULL; - menu_handle_t *menu = NULL; settings_t *settings = config_get_ptr(); - gl_t *gl = (gl_t*) - video_driver_get_ptr(&video_driver); - - if (video_driver != &video_gl || !gl) - { - RARCH_ERR("Cannot initialize GLUI menu driver: gl video driver is not active.\n"); - return NULL; - } - - if (settings->menu.mouse.enable) - { - RARCH_WARN("Forcing menu_mouse_enable=false\n"); - settings->menu.mouse.enable = false; - } - - menu = (menu_handle_t*)calloc(1, sizeof(*menu)); + menu_handle_t *menu = (menu_handle_t*)calloc(1, sizeof(*menu)); if (!menu) goto error; + if (!menu_display_check_compatibility(menu_ctx_zarch.type)) + goto error; + menu->userdata = (zui_t*)calloc(1, sizeof(zui_t)); if (!menu->userdata) @@ -1113,6 +1099,12 @@ static void *zarch_init(void) zui = (zui_t*)menu->userdata; + if (settings->menu.mouse.enable) + { + RARCH_WARN("Forcing menu_mouse_enable=false\n"); + settings->menu.mouse.enable = false; + } + unused = 1000; menu_display_ctl(MENU_DISPLAY_CTL_SET_HEADER_HEIGHT, &unused); diff --git a/menu/menu_display.c b/menu/menu_display.c index cce6903ecf..73e3ffdb9e 100644 --- a/menu/menu_display.c +++ b/menu/menu_display.c @@ -584,8 +584,6 @@ void menu_display_draw_frame( } void menu_display_frame_background( - menu_handle_t *menu, - settings_t *settings, unsigned width, unsigned height, GLuint texture, @@ -599,8 +597,9 @@ void menu_display_frame_background( enum menu_display_prim_type prim_type) { struct gfx_coords coords; - global_t *global = global_get_ptr(); - gl_t *gl = (gl_t*)video_driver_get_ptr(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; @@ -642,6 +641,33 @@ void menu_display_clear_color(float r, float g, float b, float a) } #endif +bool menu_display_check_compatibility(enum menu_display_driver_type type) +{ + const video_driver_t *video_driver = NULL; +#ifdef HAVE_OPENGL + gl_t *gl = (gl_t*)video_driver_get_ptr(&video_driver); +#endif + + switch (type) + { + case MENU_VIDEO_DRIVER_GENERIC: + return true; + case MENU_VIDEO_DRIVER_OPENGL: +#ifdef HAVE_OPENGL + if (video_driver == &video_gl || gl) + return true; +#endif + break; + case MENU_VIDEO_DRIVER_DIRECT3D: + /* TODO/FIXME */ + break; + } + + RARCH_ERR("Cannot initialize menu driver: video driver of type %d is not active.\n", type); + return false; +} + + const char *menu_video_get_ident(void) { #ifdef HAVE_THREADS diff --git a/menu/menu_display.h b/menu/menu_display.h index 401d284783..7852888bf7 100644 --- a/menu/menu_display.h +++ b/menu/menu_display.h @@ -26,6 +26,13 @@ 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, @@ -107,8 +114,6 @@ void menu_display_blend_begin(void); void menu_display_blend_end(void); void menu_display_frame_background( - menu_handle_t *menu, - settings_t *settings, unsigned width, unsigned height, GLuint texture, float handle_alpha, @@ -130,6 +135,8 @@ 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); +bool menu_display_check_compatibility(enum menu_display_driver_type type); + const char *menu_video_get_ident(void); #ifdef __cplusplus diff --git a/menu/menu_driver.h b/menu/menu_driver.h index 13135a9151..7d803addd1 100644 --- a/menu/menu_driver.h +++ b/menu/menu_driver.h @@ -61,13 +61,6 @@ typedef enum MENU_HELP_LAST } menu_help_type_t; -typedef enum -{ - MENU_VIDEO_DRIVER_GENERIC = 0, - MENU_VIDEO_DRIVER_OPENGL, - MENU_VIDEO_DRIVER_DIRECT3D -} menu_video_driver_type_t; - typedef struct { void *userdata; @@ -140,7 +133,7 @@ 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; - menu_video_driver_type_t type; + 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,