From 54c7521bf850f911a129831a7dbaf7b9ce6029ae Mon Sep 17 00:00:00 2001 From: Themaister Date: Sat, 7 Jun 2014 22:42:23 +0200 Subject: [PATCH] Drop useless win_width/height arguments to font init. --- driver.h | 9 +++++++-- gfx/fonts/gl_font.c | 4 ++-- gfx/fonts/gl_font.h | 5 ++--- gfx/fonts/gl_raster_font.c | 30 +++++++++++++++--------------- gfx/fonts/ps_libdbgfont.c | 10 ++++++---- gfx/gl.c | 3 +-- 6 files changed, 33 insertions(+), 28 deletions(-) diff --git a/driver.h b/driver.h index 3615ab6152..a5a87eaed9 100644 --- a/driver.h +++ b/driver.h @@ -346,10 +346,15 @@ struct font_params { float x; float y; - float alpha; float scale; - uint32_t color; + uint32_t color; // ABGR. + bool full_screen; }; +#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_GREEN(col) (((col) >> 8) & 0xff) +#define FONT_COLOR_GET_BLUE(col) (((col) >> 16) & 0xff) +#define FONT_COLOR_GET_ALPHA(col) (((col) >> 24) & 0xff) // Optionally implemented interface to poke more deeply into video driver. typedef struct video_poke_interface diff --git a/gfx/fonts/gl_font.c b/gfx/fonts/gl_font.c index 1a2c2740bc..37aa5ecaea 100644 --- a/gfx/fonts/gl_font.c +++ b/gfx/fonts/gl_font.c @@ -27,12 +27,12 @@ static const gl_font_renderer_t *gl_font_backends[] = { }; bool gl_font_init_first(const gl_font_renderer_t **font_driver, void **font_handle, - void *gl_data, const char *font_path, float font_size, unsigned win_width, unsigned win_height) + void *gl_data, const char *font_path, float font_size) { unsigned i; for (i = 0; gl_font_backends[i]; i++) { - void *data = gl_font_backends[i]->init(gl_data, font_path, font_size, win_width, win_height); + void *data = gl_font_backends[i]->init(gl_data, font_path, font_size); if (data) { *font_driver = gl_font_backends[i]; diff --git a/gfx/fonts/gl_font.h b/gfx/fonts/gl_font.h index 2c2151e66c..d6a687a042 100644 --- a/gfx/fonts/gl_font.h +++ b/gfx/fonts/gl_font.h @@ -21,8 +21,7 @@ typedef struct gl_font_renderer { - void *(*init)(void *data, const char *font_path, float font_size, - unsigned win_width, unsigned win_height); + void *(*init)(void *data, const char *font_path, float font_size); void (*free)(void *data); void (*render_msg)(void *data, const char *msg, const struct font_params *parms); const char *ident; @@ -32,7 +31,7 @@ extern const gl_font_renderer_t gl_raster_font; extern const gl_font_renderer_t libdbg_font; bool gl_font_init_first(const gl_font_renderer_t **font_driver, void **font_handle, - void *gl_data, const char *font_path, float font_size, unsigned win_width, unsigned win_height); + void *gl_data, const char *font_path, float font_size); #endif diff --git a/gfx/fonts/gl_raster_font.c b/gfx/fonts/gl_raster_font.c index 97d76bfbc2..1fa511b51a 100644 --- a/gfx/fonts/gl_raster_font.c +++ b/gfx/fonts/gl_raster_font.c @@ -28,11 +28,8 @@ typedef struct void *font_data; } gl_raster_t; -static void *gl_init_font(void *gl_data, const char *font_path, float font_size, unsigned win_width, unsigned win_height) +static void *gl_init_font(void *gl_data, const char *font_path, float font_size) { - (void)win_width; - (void)win_height; - gl_raster_t *font = (gl_raster_t*)calloc(1, sizeof(*font)); if (!font) return NULL; @@ -115,7 +112,7 @@ void gl_free_font(void *data) font_color[ 4 * (6 * i + c) + 3] = color[3]; \ } while(0) -static void render_message(gl_raster_t *font, const char *msg, GLfloat scale, const GLfloat color[4], GLfloat pos_x, GLfloat pos_y) +static void render_message(gl_raster_t *font, const char *msg, GLfloat scale, const GLfloat color[4], GLfloat pos_x, GLfloat pos_y, bool full_screen) { unsigned i; gl_t *gl = font->gl; @@ -123,7 +120,7 @@ static void render_message(gl_raster_t *font, const char *msg, GLfloat scale, co if (gl->shader && gl->shader->use) gl->shader->use(gl, GL_SHADER_STOCK_BLEND); - gl_set_viewport(gl, gl->win_width, gl->win_height, true, false); + gl_set_viewport(gl, gl->win_width, gl->win_height, full_screen, false); glEnable(GL_BLEND); glBindTexture(GL_TEXTURE_2D, font->tex); @@ -138,15 +135,15 @@ static void render_message(gl_raster_t *font, const char *msg, GLfloat scale, co unsigned msg_len_full = strlen(msg); unsigned msg_len = min(msg_len_full, MAX_MSG_LEN_CHUNK); - int x = roundf(pos_x * gl->win_width); - int y = roundf(pos_y * gl->win_height); + int x = roundf(pos_x * gl->vp.width); + int y = roundf(pos_y * gl->vp.height); int delta_x = 0; int delta_y = 0; float inv_tex_size_x = 1.0f / font->tex_width; float inv_tex_size_y = 1.0f / font->tex_height; - float inv_win_width = 1.0f / font->gl->win_width; - float inv_win_height = 1.0f / font->gl->win_height; + float inv_win_width = 1.0f / font->gl->vp.width; + float inv_win_height = 1.0f / font->gl->vp.height; while (msg_len_full) { @@ -213,6 +210,7 @@ static void gl_render_msg(void *data, const char *msg, const struct font_params { GLfloat x, y, scale; GLfloat color[4]; + bool full_screen; gl_raster_t *font = (gl_raster_t*)data; if (!font) @@ -223,11 +221,12 @@ static void gl_render_msg(void *data, const char *msg, const struct font_params x = params->x; y = params->y; scale = params->scale; + full_screen = params->full_screen; - color[0] = ((params->color >> 16) & 0xff) / 255.0f; - color[1] = ((params->color >> 8) & 0xff) / 255.0f; - color[2] = ((params->color >> 0) & 0xff) / 255.0f; - color[3] = params->alpha; + color[0] = FONT_COLOR_GET_RED(params->color); + color[1] = FONT_COLOR_GET_GREEN(params->color); + color[2] = FONT_COLOR_GET_BLUE(params->color); + color[3] = FONT_COLOR_GET_ALPHA(params->color); // If alpha is 0.0f, turn it into default 1.0f if (color[3] <= 0.0f) @@ -238,6 +237,7 @@ static void gl_render_msg(void *data, const char *msg, const struct font_params x = g_settings.video.msg_pos_x; y = g_settings.video.msg_pos_y; scale = 1.0f; + full_screen = false; color[0] = g_settings.video.msg_color_r; color[1] = g_settings.video.msg_color_g; @@ -245,7 +245,7 @@ static void gl_render_msg(void *data, const char *msg, const struct font_params color[3] = 1.0f; } - render_message(font, msg, scale, color, x, y); + render_message(font, msg, scale, color, x, y, full_screen); } const gl_font_renderer_t gl_raster_font = { diff --git a/gfx/fonts/ps_libdbgfont.c b/gfx/fonts/ps_libdbgfont.c index 3c2b34b6dd..3fba0b8f09 100644 --- a/gfx/fonts/ps_libdbgfont.c +++ b/gfx/fonts/ps_libdbgfont.c @@ -16,6 +16,7 @@ #include "fonts.h" #include "../gfx_common.h" +#include "../gl_common.h" #if defined(SN_TARGET_PSP2) #include @@ -32,19 +33,19 @@ #define DbgFontExit cellDbgFontExit #endif -static void *gl_init_font(void *data, const char *font_path, float font_size, - unsigned win_width, unsigned win_height) +static void *gl_init_font(void *gl_data, const char *font_path, float font_size) { (void)font_path; (void)font_size; + gl_t *gl = (gl_t*)gl_data; DbgFontConfig cfg; #if defined(SN_TARGET_PSP2) cfg.fontSize = SCE_DBGFONT_FONTSIZE_LARGE; #elif defined(__CELLOS_LV2__) cfg.bufSize = SCE_DBGFONT_BUFSIZE_LARGE; - cfg.screenWidth = win_width; - cfg.screenHeight = win_height; + cfg.screenWidth = gl->win_width; + cfg.screenHeight = gl->win_height; #endif DbgFontInit(&cfg); @@ -97,3 +98,4 @@ const gl_font_renderer_t libdbg_font = { gl_render_msg, "GL raster", }; + diff --git a/gfx/gl.c b/gfx/gl.c index 03a074f527..b2dca76c92 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -2354,8 +2354,7 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo #endif { if (!gl_font_init_first(&gl->font_driver, &gl->font_handle, - gl, *g_settings.video.font_path ? g_settings.video.font_path : NULL, g_settings.video.font_size, - gl->win_width, gl->win_height)) + gl, *g_settings.video.font_path ? g_settings.video.font_path : NULL, g_settings.video.font_size)) RARCH_ERR("[GL]: Failed to init font renderer.\n"); }