mirror of
https://github.com/libretro/RetroArch
synced 2025-01-30 12:32:52 +00:00
(Font drivers) Font driver cleanups
This commit is contained in:
parent
93dfa0217d
commit
ee0749e884
@ -31,14 +31,6 @@
|
||||
#include "../../configuration.h"
|
||||
#include "../../verbosity.h"
|
||||
|
||||
/* FIXME: this is just a workaround to avoid
|
||||
* using ctrGuCopyImage, since it seems to cause
|
||||
* a freeze/blackscreen when used here. */
|
||||
|
||||
#if 0
|
||||
#define FONT_TEXTURE_IN_VRAM
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ctr_texture_t texture;
|
||||
@ -130,16 +122,19 @@ static void ctr_font_free_font(void* data, bool is_threaded)
|
||||
static int ctr_font_get_message_width(void* data, const char* msg,
|
||||
unsigned msg_len, float scale)
|
||||
{
|
||||
ctr_font_t* font = (ctr_font_t*)data;
|
||||
|
||||
unsigned i;
|
||||
int delta_x = 0;
|
||||
const struct font_glyph* glyph_q = NULL;
|
||||
ctr_font_t* font = (ctr_font_t*)data;
|
||||
|
||||
if (!font)
|
||||
return 0;
|
||||
|
||||
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
|
||||
|
||||
for (i = 0; i < msg_len; i++)
|
||||
{
|
||||
const struct font_glyph* glyph;
|
||||
const char* msg_tmp = &msg[i];
|
||||
unsigned code = utf8_walk(&msg_tmp);
|
||||
unsigned skip = msg_tmp - &msg[i];
|
||||
@ -147,14 +142,12 @@ static int ctr_font_get_message_width(void* data, const char* msg,
|
||||
if (skip > 1)
|
||||
i += skip - 1;
|
||||
|
||||
const struct font_glyph* glyph =
|
||||
font->font_driver->get_glyph(font->font_data, code);
|
||||
|
||||
if (!glyph) /* Do something smarter here ... */
|
||||
glyph = font->font_driver->get_glyph(font->font_data, '?');
|
||||
|
||||
if (!glyph)
|
||||
continue;
|
||||
/* Do something smarter here ... */
|
||||
if (!(glyph =
|
||||
font->font_driver->get_glyph(font->font_data, code)))
|
||||
if (!(glyph = glyph_q))
|
||||
continue;
|
||||
|
||||
delta_x += glyph->advance_x;
|
||||
}
|
||||
@ -170,16 +163,18 @@ static void ctr_font_render_line(
|
||||
unsigned width, unsigned height, unsigned text_align)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
int x, y;
|
||||
const struct font_glyph* glyph_q = NULL;
|
||||
ctr_vertex_t* v = NULL;
|
||||
int x = roundf(pos_x * width);
|
||||
int y = roundf((1.0f - pos_y) * height);
|
||||
int delta_x = 0;
|
||||
int delta_y = 0;
|
||||
|
||||
if (!ctr)
|
||||
return;
|
||||
|
||||
x = roundf(pos_x * width);
|
||||
y = roundf((1.0f - pos_y) * height);
|
||||
|
||||
switch (text_align)
|
||||
{
|
||||
case TEXT_ALIGN_RIGHT:
|
||||
@ -195,10 +190,12 @@ static void ctr_font_render_line(
|
||||
if ((ctr->vertex_cache.size - (ctr->vertex_cache.current - ctr->vertex_cache.buffer)) < msg_len)
|
||||
ctr->vertex_cache.current = ctr->vertex_cache.buffer;
|
||||
|
||||
v = ctr->vertex_cache.current;
|
||||
v = ctr->vertex_cache.current;
|
||||
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
|
||||
|
||||
for (i = 0; i < msg_len; i++)
|
||||
{
|
||||
const struct font_glyph* glyph;
|
||||
int off_x, off_y, tex_x, tex_y, width, height;
|
||||
const char* msg_tmp = &msg[i];
|
||||
unsigned code = utf8_walk(&msg_tmp);
|
||||
@ -207,30 +204,27 @@ static void ctr_font_render_line(
|
||||
if (skip > 1)
|
||||
i += skip - 1;
|
||||
|
||||
const struct font_glyph* glyph =
|
||||
font->font_driver->get_glyph(font->font_data, code);
|
||||
/* Do something smarter here ... */
|
||||
if (!(glyph =
|
||||
font->font_driver->get_glyph(font->font_data, code)))
|
||||
if (!(glyph = glyph_q))
|
||||
continue;
|
||||
|
||||
if (!glyph) /* Do something smarter here ... */
|
||||
glyph = font->font_driver->get_glyph(font->font_data, '?');
|
||||
off_x = glyph->draw_offset_x;
|
||||
off_y = glyph->draw_offset_y;
|
||||
tex_x = glyph->atlas_offset_x;
|
||||
tex_y = glyph->atlas_offset_y;
|
||||
width = glyph->width;
|
||||
height = glyph->height;
|
||||
|
||||
if (!glyph)
|
||||
continue;
|
||||
|
||||
off_x = glyph->draw_offset_x;
|
||||
off_y = glyph->draw_offset_y;
|
||||
tex_x = glyph->atlas_offset_x;
|
||||
tex_y = glyph->atlas_offset_y;
|
||||
width = glyph->width;
|
||||
height = glyph->height;
|
||||
|
||||
v->x0 = x + (off_x + delta_x) * scale;
|
||||
v->y0 = y + (off_y + delta_y) * scale;
|
||||
v->u0 = tex_x;
|
||||
v->v0 = tex_y;
|
||||
v->x1 = v->x0 + width * scale;
|
||||
v->y1 = v->y0 + height * scale;
|
||||
v->u1 = v->u0 + width;
|
||||
v->v1 = v->v0 + height;
|
||||
v->x0 = x + (off_x + delta_x) * scale;
|
||||
v->y0 = y + (off_y + delta_y) * scale;
|
||||
v->u0 = tex_x;
|
||||
v->v0 = tex_y;
|
||||
v->x1 = v->x0 + width * scale;
|
||||
v->y1 = v->y0 + height * scale;
|
||||
v->u1 = v->u0 + width;
|
||||
v->v1 = v->v0 + height;
|
||||
|
||||
v++;
|
||||
delta_x += glyph->advance_x;
|
||||
@ -262,13 +256,6 @@ static void ctr_font_render_line(
|
||||
GPU_MODULATE, GPU_MODULATE,
|
||||
color);
|
||||
|
||||
#if 0
|
||||
printf("%s\n", msg);
|
||||
DEBUG_VAR(color);
|
||||
GPU_SetTexEnv(0, GPU_TEXTURE0, GPU_TEXTURE0, 0,
|
||||
GPU_TEVOPERANDS(GPU_TEVOP_RGB_SRC_R, 0, 0), GPU_REPLACE, GPU_REPLACE, 0);
|
||||
#endif
|
||||
|
||||
ctrGuSetTexture(GPU_TEXUNIT0, VIRT_TO_PHYS(font->texture.data),
|
||||
font->texture.width, font->texture.height,
|
||||
GPU_TEXTURE_MAG_FILTER(GPU_NEAREST) | GPU_TEXTURE_MIN_FILTER(GPU_NEAREST) |
|
||||
@ -303,32 +290,8 @@ static void ctr_font_render_line(
|
||||
GPU_DrawArray(GPU_GEOMETRY_PRIM, 0, v - ctr->vertex_cache.current);
|
||||
}
|
||||
|
||||
#if 0
|
||||
v = font->vertices;
|
||||
v->x0 = 0;
|
||||
v->y0 = 0;
|
||||
v->u0 = 0;
|
||||
v->v0 = 0;
|
||||
v->x1 = font->texture.width;
|
||||
v->y1 = font->texture.height;
|
||||
v->u1 = font->texture.width;
|
||||
v->v1 = font->texture.height;
|
||||
GPU_DrawArray(GPU_GEOMETRY_PRIM, 0, 1);
|
||||
#endif
|
||||
|
||||
GPU_SetTexEnv(0, GPU_TEXTURE0, GPU_TEXTURE0, 0, 0, GPU_REPLACE, GPU_REPLACE, 0);
|
||||
|
||||
#if 0
|
||||
DEBUG_VAR(v - font->vertices);
|
||||
v = font->vertices;
|
||||
printf("OSDMSG: %s\n", msg);
|
||||
printf("vertex : (%i,%i,%i,%i) - (%i,%i,%i,%i)\n",
|
||||
v->x0, v->y0, v->x1, v->y1,
|
||||
v->u0, v->v0, v->u1, v->v1);
|
||||
|
||||
printf("%s\n", msg);
|
||||
#endif
|
||||
|
||||
ctr->vertex_cache.current = v;
|
||||
}
|
||||
|
||||
@ -382,7 +345,6 @@ static void ctr_font_render_msg(
|
||||
{
|
||||
float x, y, scale, drop_mod, drop_alpha;
|
||||
int drop_x, drop_y;
|
||||
unsigned max_glyphs;
|
||||
enum text_alignment text_align;
|
||||
unsigned color, color_dark, r, g, b,
|
||||
alpha, r_dark, g_dark, b_dark, alpha_dark;
|
||||
@ -439,11 +401,6 @@ static void ctr_font_render_msg(
|
||||
drop_alpha = 0.75f;
|
||||
}
|
||||
|
||||
max_glyphs = strlen(msg);
|
||||
|
||||
if (drop_x || drop_y)
|
||||
max_glyphs *= 2;
|
||||
|
||||
if (drop_x || drop_y)
|
||||
{
|
||||
r_dark = r * drop_mod;
|
||||
@ -467,24 +424,17 @@ static const struct font_glyph* ctr_font_get_glyph(
|
||||
void* data, uint32_t code)
|
||||
{
|
||||
ctr_font_t* font = (ctr_font_t*)data;
|
||||
|
||||
if (!font || !font->font_driver)
|
||||
return NULL;
|
||||
|
||||
if (!font->font_driver->ident)
|
||||
return NULL;
|
||||
|
||||
return font->font_driver->get_glyph((void*)font->font_driver, code);
|
||||
if (font && font->font_driver && font->font_driver->ident)
|
||||
return font->font_driver->get_glyph((void*)font->font_driver, code);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool ctr_font_get_line_metrics(void* data, struct font_line_metrics **metrics)
|
||||
{
|
||||
ctr_font_t* font = (ctr_font_t*)data;
|
||||
|
||||
if (!font || !font->font_driver || !font->font_data)
|
||||
return -1;
|
||||
|
||||
return font->font_driver->get_line_metrics(font->font_data, metrics);
|
||||
if (font && font->font_driver && font->font_data)
|
||||
return font->font_driver->get_line_metrics(font->font_data, metrics);
|
||||
return -1;
|
||||
}
|
||||
|
||||
font_renderer_t ctr_font =
|
||||
|
@ -35,7 +35,6 @@
|
||||
#include "../../configuration.h"
|
||||
#include "../../verbosity.h"
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const font_renderer_driver_t *gdi_font_driver;
|
||||
@ -96,7 +95,6 @@ static void gdi_render_msg(
|
||||
unsigned newX, newY, newDropX, newDropY;
|
||||
unsigned align;
|
||||
unsigned red, green, blue;
|
||||
unsigned drop_red, drop_green, drop_blue;
|
||||
gdi_t *gdi = (gdi_t*)userdata;
|
||||
gdi_raster_t *font = (gdi_raster_t*)data;
|
||||
unsigned width = gdi->video_width;
|
||||
@ -168,8 +166,8 @@ static void gdi_render_msg(
|
||||
break;
|
||||
}
|
||||
|
||||
newY = height - (y * height * scale) - textSize.cy;
|
||||
newDropY = height - (drop_y * height * scale) - textSize.cy;
|
||||
newY = height - (y * height * scale) - textSize.cy;
|
||||
newDropY = height - (drop_y * height * scale) - textSize.cy;
|
||||
|
||||
font->gdi->bmp_old = (HBITMAP)SelectObject(font->gdi->memDC, font->gdi->bmp);
|
||||
|
||||
@ -180,10 +178,10 @@ static void gdi_render_msg(
|
||||
|
||||
if (drop_x || drop_y)
|
||||
{
|
||||
float dark_alpha = drop_alpha;
|
||||
drop_red = red * drop_mod * dark_alpha;
|
||||
drop_green = green * drop_mod * dark_alpha;
|
||||
drop_blue = blue * drop_mod * dark_alpha;
|
||||
float dark_alpha = drop_alpha;
|
||||
unsigned drop_red = red * drop_mod * dark_alpha;
|
||||
unsigned drop_green = green * drop_mod * dark_alpha;
|
||||
unsigned drop_blue = blue * drop_mod * dark_alpha;
|
||||
|
||||
SetTextColor(font->gdi->memDC, RGB(drop_red, drop_green, drop_blue));
|
||||
|
||||
|
@ -214,6 +214,7 @@ error:
|
||||
static int gl1_get_message_width(void *data, const char *msg,
|
||||
unsigned msg_len, float scale)
|
||||
{
|
||||
const struct font_glyph* glyph_q = NULL;
|
||||
gl1_raster_t *font = (gl1_raster_t*)data;
|
||||
const char* msg_end = msg + msg_len;
|
||||
int delta_x = 0;
|
||||
@ -224,16 +225,18 @@ static int gl1_get_message_width(void *data, const char *msg,
|
||||
|| !font->font_data )
|
||||
return 0;
|
||||
|
||||
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
|
||||
|
||||
while (msg < msg_end)
|
||||
{
|
||||
const struct font_glyph *glyph;
|
||||
unsigned code = utf8_walk(&msg);
|
||||
const struct font_glyph *glyph = font->font_driver->get_glyph(
|
||||
font->font_data, code);
|
||||
|
||||
if (!glyph) /* Do something smarter here ... */
|
||||
glyph = font->font_driver->get_glyph(font->font_data, '?');
|
||||
if (!glyph)
|
||||
continue;
|
||||
/* Do something smarter here ... */
|
||||
if (!(glyph = font->font_driver->get_glyph(
|
||||
font->font_data, code)))
|
||||
if (!(glyph = glyph_q))
|
||||
continue;
|
||||
|
||||
delta_x += glyph->advance_x;
|
||||
}
|
||||
@ -305,6 +308,7 @@ static void gl1_raster_font_render_line(
|
||||
{
|
||||
unsigned i;
|
||||
struct video_coords coords;
|
||||
const struct font_glyph* glyph_q = NULL;
|
||||
GLfloat font_tex_coords[2 * 6 * MAX_MSG_LEN_CHUNK];
|
||||
GLfloat font_vertex[2 * 6 * MAX_MSG_LEN_CHUNK];
|
||||
GLfloat font_color[4 * 6 * MAX_MSG_LEN_CHUNK];
|
||||
@ -330,21 +334,22 @@ static void gl1_raster_font_render_line(
|
||||
break;
|
||||
}
|
||||
|
||||
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
|
||||
|
||||
while (msg < msg_end)
|
||||
{
|
||||
i = 0;
|
||||
while ((i < MAX_MSG_LEN_CHUNK) && (msg < msg_end))
|
||||
{
|
||||
const struct font_glyph *glyph;
|
||||
int off_x, off_y, tex_x, tex_y, width, height;
|
||||
unsigned code = utf8_walk(&msg);
|
||||
const struct font_glyph *glyph = font->font_driver->get_glyph(
|
||||
font->font_data, code);
|
||||
|
||||
if (!glyph) /* Do something smarter here ... */
|
||||
glyph = font->font_driver->get_glyph(font->font_data, '?');
|
||||
|
||||
if (!glyph)
|
||||
continue;
|
||||
/* Do something smarter here ... */
|
||||
if (!(glyph = font->font_driver->get_glyph(
|
||||
font->font_data, code)))
|
||||
if (!(glyph = glyph_q))
|
||||
continue;
|
||||
|
||||
off_x = glyph->draw_offset_x;
|
||||
off_y = glyph->draw_offset_y;
|
||||
@ -540,12 +545,9 @@ static const struct font_glyph *gl1_raster_font_get_glyph(
|
||||
void *data, uint32_t code)
|
||||
{
|
||||
gl1_raster_t *font = (gl1_raster_t*)data;
|
||||
|
||||
if (!font || !font->font_driver)
|
||||
return NULL;
|
||||
if (!font->font_driver->ident)
|
||||
return NULL;
|
||||
return font->font_driver->get_glyph((void*)font->font_driver, code);
|
||||
if (font && font->font_driver && font->font_driver->ident)
|
||||
return font->font_driver->get_glyph((void*)font->font_driver, code);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void gl1_raster_font_flush_block(unsigned width, unsigned height,
|
||||
@ -583,11 +585,9 @@ static void gl1_raster_font_bind_block(void *data, void *userdata)
|
||||
static bool gl1_get_line_metrics(void* data, struct font_line_metrics **metrics)
|
||||
{
|
||||
gl1_raster_t *font = (gl1_raster_t*)data;
|
||||
|
||||
if (!font || !font->font_driver || !font->font_data)
|
||||
return -1;
|
||||
|
||||
return font->font_driver->get_line_metrics(font->font_data, metrics);
|
||||
if (font && font->font_driver && font->font_data)
|
||||
return font->font_driver->get_line_metrics(font->font_data, metrics);
|
||||
return -1;
|
||||
}
|
||||
|
||||
font_renderer_t gl1_raster_font = {
|
||||
|
@ -233,6 +233,7 @@ error:
|
||||
static int gl_get_message_width(void *data, const char *msg,
|
||||
unsigned msg_len, float scale)
|
||||
{
|
||||
const struct font_glyph* glyph_q = NULL;
|
||||
gl_raster_t *font = (gl_raster_t*)data;
|
||||
const char* msg_end = msg + msg_len;
|
||||
int delta_x = 0;
|
||||
@ -243,16 +244,18 @@ static int gl_get_message_width(void *data, const char *msg,
|
||||
|| !font->font_data )
|
||||
return 0;
|
||||
|
||||
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
|
||||
|
||||
while (msg < msg_end)
|
||||
{
|
||||
const struct font_glyph *glyph;
|
||||
unsigned code = utf8_walk(&msg);
|
||||
const struct font_glyph *glyph = font->font_driver->get_glyph(
|
||||
font->font_data, code);
|
||||
|
||||
if (!glyph) /* Do something smarter here ... */
|
||||
glyph = font->font_driver->get_glyph(font->font_data, '?');
|
||||
if (!glyph)
|
||||
continue;
|
||||
/* Do something smarter here ... */
|
||||
if (!(glyph = font->font_driver->get_glyph(
|
||||
font->font_data, code)))
|
||||
if (!(glyph = glyph_q))
|
||||
continue;
|
||||
|
||||
delta_x += glyph->advance_x;
|
||||
}
|
||||
@ -286,6 +289,7 @@ static void gl_raster_font_render_line(
|
||||
{
|
||||
unsigned i;
|
||||
struct video_coords coords;
|
||||
const struct font_glyph* glyph_q = NULL;
|
||||
GLfloat font_tex_coords[2 * 6 * MAX_MSG_LEN_CHUNK];
|
||||
GLfloat font_vertex[2 * 6 * MAX_MSG_LEN_CHUNK];
|
||||
GLfloat font_color[4 * 6 * MAX_MSG_LEN_CHUNK];
|
||||
@ -311,21 +315,22 @@ static void gl_raster_font_render_line(
|
||||
break;
|
||||
}
|
||||
|
||||
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
|
||||
|
||||
while (msg < msg_end)
|
||||
{
|
||||
i = 0;
|
||||
while ((i < MAX_MSG_LEN_CHUNK) && (msg < msg_end))
|
||||
{
|
||||
const struct font_glyph *glyph;
|
||||
int off_x, off_y, tex_x, tex_y, width, height;
|
||||
unsigned code = utf8_walk(&msg);
|
||||
const struct font_glyph *glyph = font->font_driver->get_glyph(
|
||||
font->font_data, code);
|
||||
|
||||
if (!glyph) /* Do something smarter here ... */
|
||||
glyph = font->font_driver->get_glyph(font->font_data, '?');
|
||||
|
||||
if (!glyph)
|
||||
continue;
|
||||
/* Do something smarter here ... */
|
||||
if (!(glyph = font->font_driver->get_glyph(
|
||||
font->font_data, code)))
|
||||
if (!(glyph = glyph_q))
|
||||
continue;
|
||||
|
||||
off_x = glyph->draw_offset_x;
|
||||
off_y = glyph->draw_offset_y;
|
||||
@ -527,12 +532,9 @@ static const struct font_glyph *gl_raster_font_get_glyph(
|
||||
void *data, uint32_t code)
|
||||
{
|
||||
gl_raster_t *font = (gl_raster_t*)data;
|
||||
|
||||
if (!font || !font->font_driver)
|
||||
return NULL;
|
||||
if (!font->font_driver->ident)
|
||||
return NULL;
|
||||
return font->font_driver->get_glyph((void*)font->font_driver, code);
|
||||
if (font && font->font_driver && font->font_driver->ident)
|
||||
return font->font_driver->get_glyph((void*)font->font_driver, code);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void gl_raster_font_flush_block(unsigned width, unsigned height,
|
||||
@ -569,11 +571,9 @@ static void gl_raster_font_bind_block(void *data, void *userdata)
|
||||
static bool gl_get_line_metrics(void* data, struct font_line_metrics **metrics)
|
||||
{
|
||||
gl_raster_t *font = (gl_raster_t*)data;
|
||||
|
||||
if (!font || !font->font_driver || !font->font_data)
|
||||
return -1;
|
||||
|
||||
return font->font_driver->get_line_metrics(font->font_data, metrics);
|
||||
if (font && font->font_driver && font->font_data)
|
||||
return font->font_driver->get_line_metrics(font->font_data, metrics);
|
||||
return -1;
|
||||
}
|
||||
|
||||
font_renderer_t gl_raster_font = {
|
||||
|
@ -139,6 +139,7 @@ error:
|
||||
static int gl3_get_message_width(void *data, const char *msg,
|
||||
unsigned msg_len, float scale)
|
||||
{
|
||||
const struct font_glyph* glyph_q = NULL;
|
||||
gl3_raster_t *font = (gl3_raster_t*)data;
|
||||
const char* msg_end = msg + msg_len;
|
||||
int delta_x = 0;
|
||||
@ -149,16 +150,18 @@ static int gl3_get_message_width(void *data, const char *msg,
|
||||
|| !font->font_data )
|
||||
return 0;
|
||||
|
||||
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
|
||||
|
||||
while (msg < msg_end)
|
||||
{
|
||||
const struct font_glyph *glyph;
|
||||
unsigned code = utf8_walk(&msg);
|
||||
const struct font_glyph *glyph = font->font_driver->get_glyph(
|
||||
font->font_data, code);
|
||||
|
||||
if (!glyph) /* Do something smarter here ... */
|
||||
glyph = font->font_driver->get_glyph(font->font_data, '?');
|
||||
if (!glyph)
|
||||
continue;
|
||||
/* Do something smarter here ... */
|
||||
if (!(glyph = font->font_driver->get_glyph(
|
||||
font->font_data, code)))
|
||||
if (!(glyph = glyph_q))
|
||||
continue;
|
||||
|
||||
delta_x += glyph->advance_x;
|
||||
}
|
||||
@ -211,10 +214,11 @@ static void gl3_raster_font_render_line(
|
||||
{
|
||||
unsigned i;
|
||||
struct video_coords coords;
|
||||
const struct font_glyph* glyph_q = NULL;
|
||||
GLfloat font_tex_coords[2 * 6 * MAX_MSG_LEN_CHUNK];
|
||||
GLfloat font_vertex[2 * 6 * MAX_MSG_LEN_CHUNK];
|
||||
GLfloat font_color[4 * 6 * MAX_MSG_LEN_CHUNK];
|
||||
gl3_t *gl = font->gl;
|
||||
gl3_t *gl = font->gl;
|
||||
const char* msg_end = msg + msg_len;
|
||||
int x = roundf(pos_x * gl->vp.width);
|
||||
int y = roundf(pos_y * gl->vp.height);
|
||||
@ -235,21 +239,22 @@ static void gl3_raster_font_render_line(
|
||||
break;
|
||||
}
|
||||
|
||||
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
|
||||
|
||||
while (msg < msg_end)
|
||||
{
|
||||
i = 0;
|
||||
while ((i < MAX_MSG_LEN_CHUNK) && (msg < msg_end))
|
||||
{
|
||||
const struct font_glyph *glyph;
|
||||
int off_x, off_y, tex_x, tex_y, width, height;
|
||||
unsigned code = utf8_walk(&msg);
|
||||
const struct font_glyph *glyph = font->font_driver->get_glyph(
|
||||
font->font_data, code);
|
||||
|
||||
if (!glyph) /* Do something smarter here ... */
|
||||
glyph = font->font_driver->get_glyph(font->font_data, '?');
|
||||
|
||||
if (!glyph)
|
||||
continue;
|
||||
/* Do something smarter here ... */
|
||||
if (!(glyph = font->font_driver->get_glyph(
|
||||
font->font_data, code)))
|
||||
if (!(glyph = glyph_q))
|
||||
continue;
|
||||
|
||||
off_x = glyph->draw_offset_x;
|
||||
off_y = glyph->draw_offset_y;
|
||||
@ -441,12 +446,9 @@ static const struct font_glyph *gl3_raster_font_get_glyph(
|
||||
void *data, uint32_t code)
|
||||
{
|
||||
gl3_raster_t *font = (gl3_raster_t*)data;
|
||||
|
||||
if (!font || !font->font_driver)
|
||||
return NULL;
|
||||
if (!font->font_driver->ident)
|
||||
return NULL;
|
||||
return font->font_driver->get_glyph((void*)font->font_driver, code);
|
||||
if (font && font->font_driver && font->font_driver->ident)
|
||||
return font->font_driver->get_glyph((void*)font->font_driver, code);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void gl3_raster_font_flush_block(unsigned width, unsigned height,
|
||||
@ -480,11 +482,9 @@ static void gl3_raster_font_bind_block(void *data, void *userdata)
|
||||
static bool gl3_get_line_metrics(void* data, struct font_line_metrics **metrics)
|
||||
{
|
||||
gl3_raster_t *font = (gl3_raster_t*)data;
|
||||
|
||||
if (!font || !font->font_driver || !font->font_data)
|
||||
return -1;
|
||||
|
||||
return font->font_driver->get_line_metrics(font->font_data, metrics);
|
||||
if (font && font->font_driver && font->font_data)
|
||||
return font->font_driver->get_line_metrics(font->font_data, metrics);
|
||||
return -1;
|
||||
}
|
||||
|
||||
font_renderer_t gl3_raster_font = {
|
||||
|
@ -206,18 +206,18 @@
|
||||
- (int)getWidthForMessage:(const char *)msg length:(NSUInteger)length scale:(float)scale
|
||||
{
|
||||
int delta_x = 0;
|
||||
const struct font_glyph* glyph_q = _font_driver->get_glyph(_font_data, '?');
|
||||
|
||||
for (NSUInteger i = 0; i < length; i++)
|
||||
{
|
||||
const struct font_glyph *glyph = _font_driver->get_glyph(_font_data, (uint8_t)msg[i]);
|
||||
if (!glyph) /* Do something smarter here ... */
|
||||
glyph = _font_driver->get_glyph(_font_data, '?');
|
||||
const struct font_glyph *glyph;
|
||||
/* Do something smarter here ... */
|
||||
if (!(glyph = _font_driver->get_glyph(_font_data, (uint8_t)msg[i])))
|
||||
if (!(glyph = glyph_q))
|
||||
continue;
|
||||
|
||||
if (glyph)
|
||||
{
|
||||
[self updateGlyph:glyph];
|
||||
delta_x += glyph->advance_x;
|
||||
}
|
||||
[self updateGlyph:glyph];
|
||||
delta_x += glyph->advance_x;
|
||||
}
|
||||
|
||||
return (int)(delta_x * scale);
|
||||
@ -238,9 +238,9 @@
|
||||
}
|
||||
|
||||
static INLINE void write_quad6(SpriteVertex *pv,
|
||||
float x, float y, float width, float height,
|
||||
float tex_x, float tex_y, float tex_width, float tex_height,
|
||||
const vector_float4 *color)
|
||||
float x, float y, float width, float height,
|
||||
float tex_x, float tex_y, float tex_width, float tex_height,
|
||||
const vector_float4 *color)
|
||||
{
|
||||
unsigned i;
|
||||
static const float strip[2 * 6] = {
|
||||
@ -254,11 +254,13 @@ static INLINE void write_quad6(SpriteVertex *pv,
|
||||
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
pv[i].position = simd_make_float2(x + strip[2 * i + 0] * width,
|
||||
y + strip[2 * i + 1] * height);
|
||||
pv[i].texCoord = simd_make_float2(tex_x + strip[2 * i + 0] * tex_width,
|
||||
tex_y + strip[2 * i + 1] * tex_height);
|
||||
pv[i].color = *color;
|
||||
pv[i].position = simd_make_float2(
|
||||
x + strip[2 * i + 0] * width,
|
||||
y + strip[2 * i + 1] * height);
|
||||
pv[i].texCoord = simd_make_float2(
|
||||
tex_x + strip[2 * i + 0] * tex_width,
|
||||
tex_y + strip[2 * i + 1] * tex_height);
|
||||
pv[i].color = *color;
|
||||
}
|
||||
}
|
||||
|
||||
@ -270,14 +272,14 @@ static INLINE void write_quad6(SpriteVertex *pv,
|
||||
posY:(float)posY
|
||||
aligned:(unsigned)aligned
|
||||
{
|
||||
const char *msg_end = msg + length;
|
||||
int x = (int)roundf(posX * _driver.viewport->full_width);
|
||||
int y = (int)roundf((1.0f - posY) * _driver.viewport->full_height);
|
||||
int delta_x = 0;
|
||||
int delta_y = 0;
|
||||
const char *msg_end = msg + length;
|
||||
int x = (int)roundf(posX * _driver.viewport->full_width);
|
||||
int y = (int)roundf((1.0f - posY) * _driver.viewport->full_height);
|
||||
int delta_x = 0;
|
||||
int delta_y = 0;
|
||||
float inv_tex_size_x = 1.0f / _texture.width;
|
||||
float inv_tex_size_y = 1.0f / _texture.height;
|
||||
float inv_win_width = 1.0f / _driver.viewport->full_width;
|
||||
float inv_win_width = 1.0f / _driver.viewport->full_width;
|
||||
float inv_win_height = 1.0f / _driver.viewport->full_height;
|
||||
|
||||
switch (aligned)
|
||||
@ -295,27 +297,27 @@ static INLINE void write_quad6(SpriteVertex *pv,
|
||||
}
|
||||
|
||||
SpriteVertex *v = (SpriteVertex *)_vert.contents;
|
||||
v += _offset + _vertices;
|
||||
v += _offset + _vertices;
|
||||
glyph_q = _font_driver->get_glyph(_font_data, '?');
|
||||
|
||||
while (msg < msg_end)
|
||||
{
|
||||
int off_x, off_y, tex_x, tex_y, width, height;
|
||||
const struct font_glyph *glyph;
|
||||
unsigned code = utf8_walk(&msg);
|
||||
const struct font_glyph *glyph = _font_driver->get_glyph(_font_data, code);
|
||||
|
||||
if (!glyph) /* Do something smarter here ... */
|
||||
glyph = _font_driver->get_glyph(_font_data, '?');
|
||||
|
||||
if (!glyph)
|
||||
continue;
|
||||
/* Do something smarter here .. */
|
||||
if (!(glyph = _font_driver->get_glyph(_font_data, code)))
|
||||
if (!(glyph = glyph_q))
|
||||
continue;
|
||||
|
||||
[self updateGlyph:glyph];
|
||||
|
||||
int off_x, off_y, tex_x, tex_y, width, height;
|
||||
off_x = glyph->draw_offset_x;
|
||||
off_y = glyph->draw_offset_y;
|
||||
tex_x = glyph->atlas_offset_x;
|
||||
tex_y = glyph->atlas_offset_y;
|
||||
width = glyph->width;
|
||||
off_x = glyph->draw_offset_x;
|
||||
off_y = glyph->draw_offset_y;
|
||||
tex_x = glyph->atlas_offset_x;
|
||||
tex_y = glyph->atlas_offset_y;
|
||||
width = glyph->width;
|
||||
height = glyph->height;
|
||||
|
||||
write_quad6(v,
|
||||
@ -330,10 +332,10 @@ static INLINE void write_quad6(SpriteVertex *pv,
|
||||
&color);
|
||||
|
||||
_vertices += 6;
|
||||
v += 6;
|
||||
v += 6;
|
||||
|
||||
delta_x += glyph->advance_x;
|
||||
delta_y += glyph->advance_y;
|
||||
delta_x += glyph->advance_x;
|
||||
delta_y += glyph->advance_y;
|
||||
}
|
||||
}
|
||||
|
||||
@ -368,6 +370,8 @@ static INLINE void write_quad6(SpriteVertex *pv,
|
||||
posY:(float)posY
|
||||
aligned:(unsigned)aligned
|
||||
{
|
||||
int lines = 0;
|
||||
float line_height;
|
||||
struct font_line_metrics *line_metrics = NULL;
|
||||
|
||||
/* If font line metrics are not supported just draw as usual */
|
||||
@ -378,8 +382,7 @@ static INLINE void write_quad6(SpriteVertex *pv,
|
||||
return;
|
||||
}
|
||||
|
||||
int lines = 0;
|
||||
float line_height = line_metrics->height * scale / height;
|
||||
line_height = line_metrics->height * scale / height;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
@ -504,8 +507,8 @@ static INLINE void write_quad6(SpriteVertex *pv,
|
||||
static void metal_raster_font_free_font(void *data, bool is_threaded);
|
||||
|
||||
static void *metal_raster_font_init_font(void *data,
|
||||
const char *font_path, float font_size,
|
||||
bool is_threaded)
|
||||
const char *font_path, float font_size,
|
||||
bool is_threaded)
|
||||
{
|
||||
MetalRaster *r = [[MetalRaster alloc] initWithDriver:(__bridge MetalDriver *)data fontPath:font_path fontSize:(unsigned)font_size];
|
||||
|
||||
@ -535,11 +538,11 @@ static void metal_raster_font_render_msg(
|
||||
void *data, const char *msg,
|
||||
const struct font_params *params)
|
||||
{
|
||||
MetalRaster *r = (__bridge MetalRaster *)data;
|
||||
MetalDriver *d = (__bridge MetalDriver *)userdata;
|
||||
MetalRaster *r = (__bridge MetalRaster *)data;
|
||||
MetalDriver *d = (__bridge MetalDriver *)userdata;
|
||||
video_viewport_t *vp = [d viewport];
|
||||
unsigned width = vp->full_width;
|
||||
unsigned height = vp->full_height;
|
||||
unsigned width = vp->full_width;
|
||||
unsigned height = vp->full_height;
|
||||
[r renderMessage:msg width:width height:height params:params];
|
||||
}
|
||||
|
||||
|
@ -103,16 +103,19 @@ static void ps2_font_free_font(void* data, bool is_threaded)
|
||||
static int ps2_font_get_message_width(void* data, const char* msg,
|
||||
unsigned msg_len, float scale)
|
||||
{
|
||||
ps2_font_t* font = (ps2_font_t*)data;
|
||||
|
||||
const struct font_glyph* glyph_q = NULL;
|
||||
unsigned i;
|
||||
int delta_x = 0;
|
||||
int delta_x = 0;
|
||||
ps2_font_t* font = (ps2_font_t*)data;
|
||||
|
||||
if (!font)
|
||||
return 0;
|
||||
|
||||
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
|
||||
|
||||
for (i = 0; i < msg_len; i++)
|
||||
{
|
||||
const struct font_glyph* glyph;
|
||||
const char* msg_tmp = &msg[i];
|
||||
unsigned code = utf8_walk(&msg_tmp);
|
||||
unsigned skip = msg_tmp - &msg[i];
|
||||
@ -120,14 +123,11 @@ static int ps2_font_get_message_width(void* data, const char* msg,
|
||||
if (skip > 1)
|
||||
i += skip - 1;
|
||||
|
||||
const struct font_glyph* glyph =
|
||||
font->font_driver->get_glyph(font->font_data, code);
|
||||
|
||||
if (!glyph) /* Do something smarter here ... */
|
||||
glyph = font->font_driver->get_glyph(font->font_data, '?');
|
||||
|
||||
if (!glyph)
|
||||
continue;
|
||||
/* Do something smarter here ... */
|
||||
if (!(glyph =
|
||||
font->font_driver->get_glyph(font->font_data, code)))
|
||||
if (!(glyph = glyph_q))
|
||||
continue;
|
||||
|
||||
delta_x += glyph->advance_x;
|
||||
}
|
||||
@ -143,7 +143,7 @@ static void ps2_font_render_line(
|
||||
unsigned width, unsigned height, unsigned text_align)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
const struct font_glyph* glyph_q = NULL;
|
||||
int x = roundf(pos_x * width);
|
||||
int y = roundf((1.0f - pos_y) * height);
|
||||
int delta_x = 0;
|
||||
@ -170,13 +170,15 @@ static void ps2_font_render_line(
|
||||
}
|
||||
|
||||
/* We need to >> 1, because GS_SETREG_RGBAQ expect 0x80 as max color */
|
||||
colorA = (int)(((color & 0xFF000000) >> 24) >> 2);
|
||||
colorB = (int)(((color & 0x00FF0000) >> 16) >> 1);
|
||||
colorG = (int)(((color & 0x0000FF00) >> 8) >> 1);
|
||||
colorR = (int)(((color & 0x000000FF) >> 0) >> 1);
|
||||
colorA = (int)(((color & 0xFF000000) >> 24) >> 2);
|
||||
colorB = (int)(((color & 0x00FF0000) >> 16) >> 1);
|
||||
colorG = (int)(((color & 0x0000FF00) >> 8) >> 1);
|
||||
colorR = (int)(((color & 0x000000FF) >> 0) >> 1);
|
||||
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
|
||||
|
||||
for (i = 0; i < msg_len; i++)
|
||||
{
|
||||
const struct font_glyph* glyph;
|
||||
int off_x, off_y, tex_x, tex_y, width, height;
|
||||
float x1, y1, u1, v1, x2, y2, u2, v2;
|
||||
const char* msg_tmp = &msg[i];
|
||||
@ -186,14 +188,11 @@ static void ps2_font_render_line(
|
||||
if (skip > 1)
|
||||
i += skip - 1;
|
||||
|
||||
const struct font_glyph* glyph =
|
||||
font->font_driver->get_glyph(font->font_data, code);
|
||||
|
||||
if (!glyph) /* Do something smarter here ... */
|
||||
glyph = font->font_driver->get_glyph(font->font_data, '?');
|
||||
|
||||
if (!glyph)
|
||||
continue;
|
||||
/* Do something smarter here ... */
|
||||
if (!(glyph =
|
||||
font->font_driver->get_glyph(font->font_data, code)))
|
||||
if (!(glyph = glyph_q))
|
||||
continue;
|
||||
|
||||
off_x = glyph->draw_offset_x;
|
||||
off_y = glyph->draw_offset_y;
|
||||
@ -202,17 +201,19 @@ static void ps2_font_render_line(
|
||||
width = glyph->width;
|
||||
height = glyph->height;
|
||||
|
||||
/* The -0.5 is needed to achieve pixel perfect. More info here (PS2 uses same logic than Directx 9)
|
||||
* https://docs.microsoft.com/en-us/windows/win32/direct3d10/d3d10-graphics-programming-guide-resources-coordinates
|
||||
/* The -0.5 is needed to achieve pixel perfect.
|
||||
* More info here (PS2 uses
|
||||
* same logic as Direct3D 9)
|
||||
* https://docs.microsoft.com/en-us/windows/win32/direct3d10/d3d10-graphics-programming-guide-resources-coordinates
|
||||
*/
|
||||
x1 = -0.5f + x + (off_x + delta_x) * scale;
|
||||
y1 = -0.5f + y + (off_y + delta_y) * scale;
|
||||
u1 = tex_x;
|
||||
v1 = tex_y;
|
||||
x2 = x1 + width * scale;
|
||||
y2 = y1 + height * scale;
|
||||
u2 = u1 + width;
|
||||
v2 = v1 + height;
|
||||
x1 = -0.5f + x + (off_x + delta_x) * scale;
|
||||
y1 = -0.5f + y + (off_y + delta_y) * scale;
|
||||
u1 = tex_x;
|
||||
v1 = tex_y;
|
||||
x2 = x1 + width * scale;
|
||||
y2 = y1 + height * scale;
|
||||
u2 = u1 + width;
|
||||
v2 = v1 + height;
|
||||
|
||||
gsKit_prim_sprite_texture(ps2->gsGlobal, font->texture,
|
||||
x1, /* X1 */
|
||||
@ -281,10 +282,8 @@ static void ps2_font_render_msg(
|
||||
{
|
||||
float x, y, scale, drop_mod, drop_alpha;
|
||||
int drop_x, drop_y;
|
||||
unsigned max_glyphs;
|
||||
enum text_alignment text_align;
|
||||
unsigned color, color_dark, r, g, b,
|
||||
alpha, r_dark, g_dark, b_dark, alpha_dark;
|
||||
unsigned color, r, g, b, alpha;
|
||||
ps2_font_t * font = (ps2_font_t*)data;
|
||||
ps2_video_t *ps2 = (ps2_video_t*)userdata;
|
||||
unsigned width = ps2->vp.full_width;
|
||||
@ -336,21 +335,15 @@ static void ps2_font_render_msg(
|
||||
drop_alpha = 0.75f;
|
||||
}
|
||||
|
||||
max_glyphs = strlen(msg);
|
||||
|
||||
if (drop_x || drop_y)
|
||||
max_glyphs *= 2;
|
||||
|
||||
gsKit_TexManager_bind(ps2->gsGlobal, font->texture);
|
||||
|
||||
if (drop_x || drop_y)
|
||||
{
|
||||
r_dark = r * drop_mod;
|
||||
g_dark = g * drop_mod;
|
||||
b_dark = b * drop_mod;
|
||||
alpha_dark = alpha * drop_alpha;
|
||||
color_dark = COLOR_ABGR(r_dark, g_dark, b_dark, alpha_dark);
|
||||
|
||||
unsigned r_dark = r * drop_mod;
|
||||
unsigned g_dark = g * drop_mod;
|
||||
unsigned b_dark = b * drop_mod;
|
||||
unsigned alpha_dark = alpha * drop_alpha;
|
||||
unsigned color_dark = COLOR_ABGR(r_dark, g_dark, b_dark, alpha_dark);
|
||||
ps2_font_render_message(ps2, font, msg, scale, color_dark,
|
||||
x + scale * drop_x / width, y +
|
||||
scale * drop_y / height,
|
||||
@ -366,24 +359,17 @@ static const struct font_glyph* ps2_font_get_glyph(
|
||||
void* data, uint32_t code)
|
||||
{
|
||||
ps2_font_t* font = (ps2_font_t*)data;
|
||||
|
||||
if (!font || !font->font_driver)
|
||||
return NULL;
|
||||
|
||||
if (!font->font_driver->ident)
|
||||
return NULL;
|
||||
|
||||
return font->font_driver->get_glyph((void*)font->font_driver, code);
|
||||
if (font && font->font_driver && font->font_driver->ident)
|
||||
return font->font_driver->get_glyph((void*)font->font_driver, code);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool ps2_font_get_line_metrics(void* data, struct font_line_metrics **metrics)
|
||||
{
|
||||
ps2_font_t* font = (ps2_font_t*)data;
|
||||
|
||||
if (!font || !font->font_driver || !font->font_data)
|
||||
return -1;
|
||||
|
||||
return font->font_driver->get_line_metrics(font->font_data, metrics);
|
||||
if (font && font->font_driver && font->font_data)
|
||||
return font->font_driver->get_line_metrics(font->font_data, metrics);
|
||||
return -1;
|
||||
}
|
||||
|
||||
font_renderer_t ps2_font = {
|
||||
|
@ -202,6 +202,7 @@ error:
|
||||
static int rsx_font_get_message_width(void *data, const char *msg,
|
||||
unsigned msg_len, float scale)
|
||||
{
|
||||
const struct font_glyph* glyph_q = NULL;
|
||||
rsx_font_t *font = (rsx_font_t*)data;
|
||||
const char* msg_end = msg + msg_len;
|
||||
int delta_x = 0;
|
||||
@ -212,16 +213,18 @@ static int rsx_font_get_message_width(void *data, const char *msg,
|
||||
|| !font->font_data )
|
||||
return 0;
|
||||
|
||||
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
|
||||
|
||||
while (msg < msg_end)
|
||||
{
|
||||
const struct font_glyph *glyph;
|
||||
unsigned code = utf8_walk(&msg);
|
||||
const struct font_glyph *glyph = font->font_driver->get_glyph(
|
||||
font->font_data, code);
|
||||
|
||||
if (!glyph) /* Do something smarter here ... */
|
||||
glyph = font->font_driver->get_glyph(font->font_data, '?');
|
||||
if (!glyph)
|
||||
continue;
|
||||
/* Do something smarter here ... */
|
||||
if (!(glyph = font->font_driver->get_glyph(
|
||||
font->font_data, code)))
|
||||
if (!(glyph = glyph_q))
|
||||
continue;
|
||||
|
||||
delta_x += glyph->advance_x;
|
||||
}
|
||||
@ -232,17 +235,19 @@ static int rsx_font_get_message_width(void *data, const char *msg,
|
||||
static void rsx_font_draw_vertices(rsx_font_t *font,
|
||||
const video_coords_t *coords)
|
||||
{
|
||||
unsigned i;
|
||||
const float *vertex = coords->vertex;
|
||||
const float *tex_coord = coords->tex_coord;
|
||||
const float *color = coords->color;
|
||||
|
||||
if (font->atlas->dirty)
|
||||
{
|
||||
rsx_font_upload_atlas(font);
|
||||
font->atlas->dirty = false;
|
||||
}
|
||||
|
||||
const float *vertex = coords->vertex;
|
||||
const float *tex_coord = coords->tex_coord;
|
||||
const float *color = coords->color;
|
||||
|
||||
for (u32 i = 0; i < coords->vertices; i++) {
|
||||
for (i = 0; i < coords->vertices; i++)
|
||||
{
|
||||
font->vertices[i].x = *vertex++;
|
||||
font->vertices[i].y = *vertex++;
|
||||
font->vertices[i].z = 0.0f;
|
||||
@ -270,6 +275,7 @@ static void rsx_font_render_line(
|
||||
{
|
||||
unsigned i;
|
||||
struct video_coords coords;
|
||||
const struct font_glyph* glyph_q = NULL;
|
||||
float font_tex_coords[2 * 6 * MAX_MSG_LEN_CHUNK];
|
||||
float font_vertex[2 * 6 * MAX_MSG_LEN_CHUNK];
|
||||
float font_color[4 * 6 * MAX_MSG_LEN_CHUNK];
|
||||
@ -294,21 +300,22 @@ static void rsx_font_render_line(
|
||||
break;
|
||||
}
|
||||
|
||||
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
|
||||
|
||||
while (msg < msg_end)
|
||||
{
|
||||
i = 0;
|
||||
while ((i < MAX_MSG_LEN_CHUNK) && (msg < msg_end))
|
||||
{
|
||||
const struct font_glyph *glyph;
|
||||
int off_x, off_y, tex_x, tex_y, width, height;
|
||||
unsigned code = utf8_walk(&msg);
|
||||
const struct font_glyph *glyph = font->font_driver->get_glyph(
|
||||
font->font_data, code);
|
||||
|
||||
if (!glyph) /* Do something smarter here ... */
|
||||
glyph = font->font_driver->get_glyph(font->font_data, '?');
|
||||
|
||||
if (!glyph)
|
||||
continue;
|
||||
/* Do something smarter here ... */
|
||||
if (!(glyph = font->font_driver->get_glyph(
|
||||
font->font_data, code)))
|
||||
if (!(glyph = glyph_q))
|
||||
continue;
|
||||
|
||||
off_x = glyph->draw_offset_x;
|
||||
off_y = glyph->draw_offset_y;
|
||||
@ -389,7 +396,8 @@ static void rsx_font_setup_viewport(unsigned width, unsigned height,
|
||||
{
|
||||
video_driver_set_viewport(width, height, full_screen, false);
|
||||
|
||||
if (font->rsx) {
|
||||
if (font->rsx)
|
||||
{
|
||||
rsxSetBlendFunc(font->rsx->context, GCM_SRC_ALPHA, GCM_ONE_MINUS_SRC_ALPHA, GCM_SRC_ALPHA, GCM_ONE_MINUS_SRC_ALPHA);
|
||||
rsxSetBlendEquation(font->rsx->context, GCM_FUNC_ADD, GCM_FUNC_ADD);
|
||||
rsxSetBlendEnable(font->rsx->context, GCM_TRUE);
|
||||
@ -507,10 +515,9 @@ static const struct font_glyph *rsx_font_get_glyph(
|
||||
void *data, uint32_t code)
|
||||
{
|
||||
rsx_font_t *font = (rsx_font_t*)data;
|
||||
|
||||
if (!font || !font->font_driver || !font->font_driver->ident)
|
||||
return NULL;
|
||||
return font->font_driver->get_glyph((void*)font->font_driver, code);
|
||||
if (font && font->font_driver && font->font_driver->ident)
|
||||
return font->font_driver->get_glyph((void*)font->font_driver, code);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void rsx_font_flush_block(unsigned width, unsigned height,
|
||||
@ -545,11 +552,9 @@ static void rsx_font_bind_block(void *data, void *userdata)
|
||||
static bool rsx_font_get_line_metrics(void* data, struct font_line_metrics **metrics)
|
||||
{
|
||||
rsx_font_t *font = (rsx_font_t*)data;
|
||||
|
||||
if (!font || !font->font_driver || !font->font_data)
|
||||
return -1;
|
||||
|
||||
return font->font_driver->get_line_metrics(font->font_data, metrics);
|
||||
if (font && font->font_driver && font->font_data)
|
||||
return font->font_driver->get_line_metrics(font->font_data, metrics);
|
||||
return -1;
|
||||
}
|
||||
|
||||
font_renderer_t rsx_font = {
|
||||
|
@ -58,9 +58,6 @@ static void *switch_font_init_font(void *data, const char *font_path,
|
||||
|
||||
font->atlas = font->font_driver->get_atlas(font->font_data);
|
||||
|
||||
RARCH_LOG("Switch font driver initialized with backend %s\n",
|
||||
font->font_driver->ident);
|
||||
|
||||
return font;
|
||||
}
|
||||
|
||||
@ -81,14 +78,18 @@ static int switch_font_get_message_width(void *data, const char *msg,
|
||||
unsigned msg_len, float scale)
|
||||
{
|
||||
unsigned i;
|
||||
const struct font_glyph* glyph_q = NULL;
|
||||
int delta_x = 0;
|
||||
switch_font_t *font = (switch_font_t *)data;
|
||||
|
||||
if (!font)
|
||||
return 0;
|
||||
|
||||
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
|
||||
|
||||
for (i = 0; i < msg_len; i++)
|
||||
{
|
||||
const struct font_glyph *glyph;
|
||||
const char *msg_tmp = &msg[i];
|
||||
unsigned code = utf8_walk(&msg_tmp);
|
||||
unsigned skip = msg_tmp - &msg[i];
|
||||
@ -96,14 +97,11 @@ static int switch_font_get_message_width(void *data, const char *msg,
|
||||
if (skip > 1)
|
||||
i += skip - 1;
|
||||
|
||||
const struct font_glyph *glyph =
|
||||
font->font_driver->get_glyph(font->font_data, code);
|
||||
|
||||
if (!glyph) /* Do something smarter here ... */
|
||||
glyph = font->font_driver->get_glyph(font->font_data, '?');
|
||||
|
||||
if (!glyph)
|
||||
continue;
|
||||
/* Do something smarter here ... */
|
||||
if (!(glyph =
|
||||
font->font_driver->get_glyph(font->font_data, code)))
|
||||
if (!(glyph = glyph_q))
|
||||
continue;
|
||||
|
||||
delta_x += glyph->advance_x;
|
||||
}
|
||||
@ -117,6 +115,7 @@ static void switch_font_render_line(
|
||||
float scale, const unsigned int color, float pos_x,
|
||||
float pos_y, unsigned text_align)
|
||||
{
|
||||
const struct font_glyph* glyph_q = NULL;
|
||||
int delta_x = 0;
|
||||
int delta_y = 0;
|
||||
unsigned fb_width = sw->vp.full_width;
|
||||
@ -125,6 +124,7 @@ static void switch_font_render_line(
|
||||
if (sw->out_buffer)
|
||||
{
|
||||
unsigned i;
|
||||
const struct font_glyph* glyph_q = NULL;
|
||||
int x = roundf(pos_x * fb_width);
|
||||
int y = roundf((1.0f - pos_y) * fb_height);
|
||||
|
||||
@ -138,8 +138,11 @@ static void switch_font_render_line(
|
||||
break;
|
||||
}
|
||||
|
||||
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
|
||||
|
||||
for (i = 0; i < msg_len; i++)
|
||||
{
|
||||
const struct font_glyph *glyph;
|
||||
int off_x, off_y, tex_x, tex_y, width, height;
|
||||
const char *msg_tmp = &msg[i];
|
||||
unsigned code = utf8_walk(&msg_tmp);
|
||||
@ -148,14 +151,11 @@ static void switch_font_render_line(
|
||||
if (skip > 1)
|
||||
i += skip - 1;
|
||||
|
||||
const struct font_glyph *glyph =
|
||||
font->font_driver->get_glyph(font->font_data, code);
|
||||
|
||||
if (!glyph) /* Do something smarter here ... */
|
||||
glyph = font->font_driver->get_glyph(font->font_data, '?');
|
||||
|
||||
if (!glyph)
|
||||
continue;
|
||||
/* Do something smarter here ... */
|
||||
if (!(glyph =
|
||||
font->font_driver->get_glyph(font->font_data, code)))
|
||||
if (!(glyph = glyph_q))
|
||||
continue;
|
||||
|
||||
off_x = x + glyph->draw_offset_x + delta_x;
|
||||
off_y = y + glyph->draw_offset_y + delta_y;
|
||||
@ -204,8 +204,8 @@ static void switch_font_render_message(
|
||||
if (!font->font_driver->get_line_metrics ||
|
||||
!font->font_driver->get_line_metrics(font->font_data, &line_metrics))
|
||||
{
|
||||
int msgLen = strlen(msg);
|
||||
if (msgLen <= AVG_GLPYH_LIMIT)
|
||||
int msg_len = strlen(msg);
|
||||
if (msg_len <= AVG_GLPYH_LIMIT)
|
||||
{
|
||||
if (sw)
|
||||
switch_font_render_line(sw, font, msg, strlen(msg),
|
||||
@ -291,23 +291,17 @@ static const struct font_glyph *switch_font_get_glyph(
|
||||
void *data, uint32_t code)
|
||||
{
|
||||
switch_font_t *font = (switch_font_t *)data;
|
||||
|
||||
if (!font || !font->font_driver)
|
||||
return NULL;
|
||||
|
||||
if (!font->font_driver->ident)
|
||||
return NULL;
|
||||
|
||||
return font->font_driver->get_glyph((void *)font->font_driver, code);
|
||||
if (font && font->font_driver && font->font_driver->ident)
|
||||
return font->font_driver->get_glyph((void *)font->font_driver, code);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool switch_font_get_line_metrics(void* data, struct font_line_metrics **metrics)
|
||||
{
|
||||
switch_font_t *font = (switch_font_t *)data;
|
||||
if (!font || !font->font_driver || !font->font_data)
|
||||
return -1;
|
||||
|
||||
return font->font_driver->get_line_metrics(font->font_data, metrics);
|
||||
if (font && font->font_driver && font->font_data)
|
||||
return font->font_driver->get_line_metrics(font->font_data, metrics);
|
||||
return -1;
|
||||
}
|
||||
|
||||
font_renderer_t switch_font =
|
||||
|
@ -110,12 +110,15 @@ static int vita2d_font_get_message_width(void *data, const char *msg,
|
||||
unsigned msg_len, float scale)
|
||||
{
|
||||
unsigned i;
|
||||
const struct font_glyph* glyph_q = NULL;
|
||||
int delta_x = 0;
|
||||
vita_font_t *font = (vita_font_t*)data;
|
||||
|
||||
if (!font)
|
||||
return 0;
|
||||
|
||||
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
|
||||
|
||||
for (i = 0; i < msg_len; i++)
|
||||
{
|
||||
const struct font_glyph *glyph = NULL;
|
||||
@ -126,13 +129,10 @@ static int vita2d_font_get_message_width(void *data, const char *msg,
|
||||
if (skip > 1)
|
||||
i += skip - 1;
|
||||
|
||||
glyph = font->font_driver->get_glyph(font->font_data, code);
|
||||
|
||||
if (!glyph) /* Do something smarter here ... */
|
||||
glyph = font->font_driver->get_glyph(font->font_data, '?');
|
||||
|
||||
if (!glyph)
|
||||
continue;
|
||||
/* Do something smarter here ... */
|
||||
if (!(glyph = font->font_driver->get_glyph(font->font_data, code)))
|
||||
if (!(glyph = glyph_q))
|
||||
continue;
|
||||
|
||||
delta_x += glyph->advance_x;
|
||||
}
|
||||
@ -147,6 +147,7 @@ static void vita2d_font_render_line(
|
||||
unsigned width, unsigned height, unsigned text_align)
|
||||
{
|
||||
unsigned i;
|
||||
const struct font_glyph* glyph_q = NULL;
|
||||
int x = roundf(pos_x * width);
|
||||
int y = roundf((1.0f - pos_y) * height);
|
||||
int delta_x = 0;
|
||||
@ -162,6 +163,8 @@ static void vita2d_font_render_line(
|
||||
break;
|
||||
}
|
||||
|
||||
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
|
||||
|
||||
for (i = 0; i < msg_len; i++)
|
||||
{
|
||||
int off_x, off_y, tex_x, tex_y, width, height;
|
||||
@ -176,13 +179,10 @@ static void vita2d_font_render_line(
|
||||
if (skip > 1)
|
||||
i += skip - 1;
|
||||
|
||||
glyph = font->font_driver->get_glyph(font->font_data, code);
|
||||
|
||||
if (!glyph) /* Do something smarter here ... */
|
||||
glyph = font->font_driver->get_glyph(font->font_data, '?');
|
||||
|
||||
if (!glyph)
|
||||
continue;
|
||||
/* Do something smarter here ... */
|
||||
if (!(glyph = font->font_driver->get_glyph(font->font_data, code)))
|
||||
if (!(glyph = glyph_q))
|
||||
continue;
|
||||
|
||||
off_x = glyph->draw_offset_x;
|
||||
off_y = glyph->draw_offset_y;
|
||||
@ -268,11 +268,9 @@ static void vita2d_font_render_msg(
|
||||
{
|
||||
float x, y, scale, drop_mod, drop_alpha;
|
||||
int drop_x, drop_y;
|
||||
unsigned max_glyphs;
|
||||
enum text_alignment text_align;
|
||||
unsigned color, r, g, b, alpha;
|
||||
bool full_screen = false ;
|
||||
unsigned color, color_dark, r, g, b,
|
||||
alpha, r_dark, g_dark, b_dark, alpha_dark;
|
||||
vita_video_t *vita = (vita_video_t *)userdata;
|
||||
vita_font_t *font = (vita_font_t *)data;
|
||||
unsigned width = vita->video_width;
|
||||
@ -326,18 +324,13 @@ static void vita2d_font_render_msg(
|
||||
|
||||
video_driver_set_viewport(width, height, full_screen, false);
|
||||
|
||||
max_glyphs = strlen(msg);
|
||||
|
||||
if (drop_x || drop_y)
|
||||
max_glyphs *= 2;
|
||||
|
||||
if (drop_x || drop_y)
|
||||
{
|
||||
r_dark = r * drop_mod;
|
||||
g_dark = g * drop_mod;
|
||||
b_dark = b * drop_mod;
|
||||
alpha_dark = alpha * drop_alpha;
|
||||
color_dark = RGBA8(r_dark,g_dark,b_dark,alpha_dark);
|
||||
unsigned r_dark = r * drop_mod;
|
||||
unsigned g_dark = g * drop_mod;
|
||||
unsigned b_dark = b * drop_mod;
|
||||
unsigned alpha_dark = alpha * drop_alpha;
|
||||
unsigned color_dark = RGBA8(r_dark,g_dark,b_dark,alpha_dark);
|
||||
|
||||
vita2d_font_render_message(font, msg, scale, color_dark,
|
||||
x + scale * drop_x / width, y +
|
||||
@ -352,20 +345,17 @@ static const struct font_glyph *vita2d_font_get_glyph(
|
||||
void *data, uint32_t code)
|
||||
{
|
||||
vita_font_t *font = (vita_font_t*)data;
|
||||
|
||||
if (!font || !font->font_driver || !font->font_driver->ident)
|
||||
return NULL;
|
||||
return font->font_driver->get_glyph((void*)font->font_driver, code);
|
||||
if (font && font->font_driver && font->font_driver->ident)
|
||||
return font->font_driver->get_glyph((void*)font->font_driver, code);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool vita2d_font_get_line_metrics(void* data, struct font_line_metrics **metrics)
|
||||
{
|
||||
vita_font_t *font = (vita_font_t*)data;
|
||||
|
||||
if (!font || !font->font_driver || !font->font_data)
|
||||
return -1;
|
||||
|
||||
return font->font_driver->get_line_metrics(font->font_data, metrics);
|
||||
if (font && font->font_driver && font->font_data)
|
||||
return font->font_driver->get_line_metrics(font->font_data, metrics);
|
||||
return -1;
|
||||
}
|
||||
|
||||
font_renderer_t vita2d_vita_font = {
|
||||
|
@ -42,19 +42,16 @@ typedef struct
|
||||
static INLINE void vulkan_raster_font_update_glyph(
|
||||
vulkan_raster_t *font, const struct font_glyph *glyph)
|
||||
{
|
||||
if(font->atlas->dirty)
|
||||
unsigned row;
|
||||
for (row = glyph->atlas_offset_y; row < (glyph->atlas_offset_y + glyph->height); row++)
|
||||
{
|
||||
unsigned row;
|
||||
for (row = glyph->atlas_offset_y; row < (glyph->atlas_offset_y + glyph->height); row++)
|
||||
{
|
||||
uint8_t *src = font->atlas->buffer + row * font->atlas->width + glyph->atlas_offset_x;
|
||||
uint8_t *dst = (uint8_t*)font->texture.mapped + row * font->texture.stride + glyph->atlas_offset_x;
|
||||
memcpy(dst, src, glyph->width);
|
||||
}
|
||||
|
||||
font->atlas->dirty = false;
|
||||
font->needs_update = true;
|
||||
uint8_t *src = font->atlas->buffer + row * font->atlas->width + glyph->atlas_offset_x;
|
||||
uint8_t *dst = (uint8_t*)font->texture.mapped + row * font->texture.stride + glyph->atlas_offset_x;
|
||||
memcpy(dst, src, glyph->width);
|
||||
}
|
||||
|
||||
font->atlas->dirty = false;
|
||||
font->needs_update = true;
|
||||
}
|
||||
|
||||
|
||||
@ -128,6 +125,7 @@ static void *vulkan_raster_font_init_font(void *data,
|
||||
static int vulkan_get_message_width(void *data, const char *msg,
|
||||
unsigned msg_len, float scale)
|
||||
{
|
||||
const struct font_glyph* glyph_q = NULL;
|
||||
vulkan_raster_t *font = (vulkan_raster_t*)data;
|
||||
const char* msg_end = msg + msg_len;
|
||||
int delta_x = 0;
|
||||
@ -138,20 +136,22 @@ static int vulkan_get_message_width(void *data, const char *msg,
|
||||
|| !font->font_data )
|
||||
return 0;
|
||||
|
||||
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
|
||||
|
||||
while (msg < msg_end)
|
||||
{
|
||||
const struct font_glyph *glyph;
|
||||
uint32_t code = utf8_walk(&msg);
|
||||
const struct font_glyph *glyph = font->font_driver->get_glyph(
|
||||
font->font_data, code);
|
||||
|
||||
if (!glyph) /* Do something smarter here ... */
|
||||
glyph = font->font_driver->get_glyph(font->font_data, '?');
|
||||
/* Do something smarter here ... */
|
||||
if (!(glyph = font->font_driver->get_glyph(
|
||||
font->font_data, code)))
|
||||
if (!(glyph = glyph_q))
|
||||
continue;
|
||||
|
||||
if (glyph)
|
||||
{
|
||||
if(font->atlas->dirty)
|
||||
vulkan_raster_font_update_glyph(font, glyph);
|
||||
delta_x += glyph->advance_x;
|
||||
}
|
||||
delta_x += glyph->advance_x;
|
||||
}
|
||||
|
||||
return delta_x * scale;
|
||||
@ -163,6 +163,7 @@ static void vulkan_raster_font_render_line(
|
||||
float pos_y, unsigned text_align)
|
||||
{
|
||||
struct vk_color vk_color;
|
||||
const struct font_glyph* glyph_q = NULL;
|
||||
vk_t *vk = font->vk;
|
||||
const char* msg_end = msg + msg_len;
|
||||
int x = roundf(pos_x * vk->vp.width);
|
||||
@ -189,19 +190,22 @@ static void vulkan_raster_font_render_line(
|
||||
break;
|
||||
}
|
||||
|
||||
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
|
||||
|
||||
while (msg < msg_end)
|
||||
{
|
||||
const struct font_glyph *glyph;
|
||||
int off_x, off_y, tex_x, tex_y, width, height;
|
||||
unsigned code = utf8_walk(&msg);
|
||||
const struct font_glyph *glyph =
|
||||
font->font_driver->get_glyph(font->font_data, code);
|
||||
|
||||
if (!glyph) /* Do something smarter here ... */
|
||||
glyph = font->font_driver->get_glyph(font->font_data, '?');
|
||||
if (!glyph)
|
||||
continue;
|
||||
/* Do something smarter here ... */
|
||||
if (!(glyph =
|
||||
font->font_driver->get_glyph(font->font_data, code)))
|
||||
if (!(glyph = glyph_q))
|
||||
continue;
|
||||
|
||||
vulkan_raster_font_update_glyph(font, glyph);
|
||||
if(font->atlas->dirty)
|
||||
vulkan_raster_font_update_glyph(font, glyph);
|
||||
|
||||
off_x = glyph->draw_offset_x;
|
||||
off_y = glyph->draw_offset_y;
|
||||
@ -456,16 +460,13 @@ static const struct font_glyph *vulkan_raster_font_get_glyph(
|
||||
const struct font_glyph* glyph;
|
||||
vulkan_raster_t *font = (vulkan_raster_t*)data;
|
||||
|
||||
if (!font || !font->font_driver)
|
||||
if (!font || !font->font_driver || !font->font_driver->ident)
|
||||
return NULL;
|
||||
if (!font->font_driver->ident)
|
||||
return NULL;
|
||||
|
||||
glyph = font->font_driver->get_glyph((void*)font->font_driver, code);
|
||||
|
||||
if(glyph)
|
||||
if(glyph && font->atlas->dirty)
|
||||
vulkan_raster_font_update_glyph(font, glyph);
|
||||
|
||||
return glyph;
|
||||
}
|
||||
|
||||
@ -473,11 +474,9 @@ static bool vulkan_get_line_metrics(void* data,
|
||||
struct font_line_metrics **metrics)
|
||||
{
|
||||
vulkan_raster_t *font = (vulkan_raster_t*)data;
|
||||
|
||||
if (!font || !font->font_driver || !font->font_data)
|
||||
return -1;
|
||||
|
||||
return font->font_driver->get_line_metrics(font->font_data, metrics);
|
||||
if (font && font->font_driver && font->font_data)
|
||||
return font->font_driver->get_line_metrics(font->font_data, metrics);
|
||||
return -1;
|
||||
}
|
||||
|
||||
font_renderer_t vulkan_raster_font = {
|
||||
|
@ -56,7 +56,7 @@ static void* wiiu_font_init_font(void* data, const char* font_path,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
font->atlas = font->font_driver->get_atlas(font->font_data);
|
||||
font->atlas = font->font_driver->get_atlas(font->font_data);
|
||||
font->texture.surface.width = font->atlas->width;
|
||||
font->texture.surface.height = font->atlas->height;
|
||||
font->texture.surface.depth = 1;
|
||||
@ -64,25 +64,28 @@ static void* wiiu_font_init_font(void* data, const char* font_path,
|
||||
font->texture.surface.tileMode = GX2_TILE_MODE_LINEAR_ALIGNED;
|
||||
font->texture.viewNumSlices = 1;
|
||||
|
||||
font->texture.surface.format = GX2_SURFACE_FORMAT_UNORM_R8;
|
||||
font->texture.compMap = GX2_COMP_SEL(_1, _1, _1, _R);
|
||||
font->texture.surface.format = GX2_SURFACE_FORMAT_UNORM_R8;
|
||||
font->texture.compMap = GX2_COMP_SEL(_1, _1, _1, _R);
|
||||
|
||||
GX2CalcSurfaceSizeAndAlignment(&font->texture.surface);
|
||||
GX2InitTextureRegs(&font->texture);
|
||||
font->texture.surface.image = MEM1_alloc(font->texture.surface.imageSize,
|
||||
font->texture.surface.alignment);
|
||||
font->texture.surface.image = MEM1_alloc(
|
||||
font->texture.surface.imageSize,
|
||||
font->texture.surface.alignment);
|
||||
|
||||
for (i = 0; (i < font->atlas->height) && (i < font->texture.surface.height); i++)
|
||||
memcpy((uint8_t*)font->texture.surface.image + (i * font->texture.surface.pitch),
|
||||
font->atlas->buffer + (i * font->atlas->width), font->atlas->width);
|
||||
memcpy((uint8_t*)font->texture.surface.image
|
||||
+ (i * font->texture.surface.pitch),
|
||||
font->atlas->buffer + (i * font->atlas->width),
|
||||
font->atlas->width);
|
||||
|
||||
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_TEXTURE, font->texture.surface.image,
|
||||
font->texture.surface.imageSize);
|
||||
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_TEXTURE,
|
||||
font->texture.surface.image,
|
||||
font->texture.surface.imageSize);
|
||||
|
||||
font->atlas->dirty = false;
|
||||
|
||||
font->ubo_tex = MEM1_alloc(sizeof(*font->ubo_tex), GX2_UNIFORM_BLOCK_ALIGNMENT);
|
||||
font->ubo_tex->width = font->texture.surface.width;
|
||||
font->atlas->dirty = false;
|
||||
font->ubo_tex = MEM1_alloc(sizeof(*font->ubo_tex), GX2_UNIFORM_BLOCK_ALIGNMENT);
|
||||
font->ubo_tex->width = font->texture.surface.width;
|
||||
font->ubo_tex->height = font->texture.surface.height;
|
||||
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_UNIFORM_BLOCK, font->ubo_tex,
|
||||
sizeof(*font->ubo_tex));
|
||||
@ -109,18 +112,21 @@ static void wiiu_font_free_font(void* data, bool is_threaded)
|
||||
}
|
||||
|
||||
static int wiiu_font_get_message_width(void* data, const char* msg,
|
||||
unsigned msg_len, float scale)
|
||||
unsigned msg_len, float scale)
|
||||
{
|
||||
wiiu_font_t* font = (wiiu_font_t*)data;
|
||||
|
||||
unsigned i;
|
||||
int delta_x = 0;
|
||||
const struct font_glyph* glyph_q = NULL;
|
||||
wiiu_font_t *font = (wiiu_font_t*)data;
|
||||
|
||||
if (!font)
|
||||
return 0;
|
||||
|
||||
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
|
||||
|
||||
for (i = 0; i < msg_len; i++)
|
||||
{
|
||||
const struct font_glyph* glyph;
|
||||
const char* msg_tmp = &msg[i];
|
||||
unsigned code = utf8_walk(&msg_tmp);
|
||||
unsigned skip = msg_tmp - &msg[i];
|
||||
@ -128,14 +134,11 @@ static int wiiu_font_get_message_width(void* data, const char* msg,
|
||||
if (skip > 1)
|
||||
i += skip - 1;
|
||||
|
||||
const struct font_glyph* glyph =
|
||||
font->font_driver->get_glyph(font->font_data, code);
|
||||
|
||||
if (!glyph) /* Do something smarter here ... */
|
||||
glyph = font->font_driver->get_glyph(font->font_data, '?');
|
||||
|
||||
if (!glyph)
|
||||
continue;
|
||||
/* Do something smarter here ... */
|
||||
if (!(glyph =
|
||||
font->font_driver->get_glyph(font->font_data, code)))
|
||||
if (!(glyph = glyph_q))
|
||||
continue;
|
||||
|
||||
delta_x += glyph->advance_x;
|
||||
}
|
||||
@ -151,13 +154,17 @@ static void wiiu_font_render_line(
|
||||
unsigned width, unsigned height, unsigned text_align)
|
||||
{
|
||||
unsigned i;
|
||||
int x = roundf(pos_x * width);
|
||||
int y = roundf((1.0 - pos_y) * height);
|
||||
int count, x, y;
|
||||
sprite_vertex_t *v;
|
||||
const struct font_glyph* glyph_q = NULL;
|
||||
|
||||
if( !wiiu ||
|
||||
wiiu->vertex_cache.current + (msg_len * 4) > wiiu->vertex_cache.size)
|
||||
return;
|
||||
|
||||
x = roundf(pos_x * width);
|
||||
y = roundf((1.0 - pos_y) * height);
|
||||
|
||||
switch (text_align)
|
||||
{
|
||||
case TEXT_ALIGN_RIGHT:
|
||||
@ -169,10 +176,12 @@ static void wiiu_font_render_line(
|
||||
break;
|
||||
}
|
||||
|
||||
sprite_vertex_t* v = wiiu->vertex_cache.v + wiiu->vertex_cache.current;
|
||||
v = wiiu->vertex_cache.v + wiiu->vertex_cache.current;
|
||||
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
|
||||
|
||||
for (i = 0; i < msg_len; i++)
|
||||
{
|
||||
const struct font_glyph* glyph;
|
||||
const char* msg_tmp = &msg[i];
|
||||
unsigned code = utf8_walk(&msg_tmp);
|
||||
unsigned skip = msg_tmp - &msg[i];
|
||||
@ -180,34 +189,31 @@ static void wiiu_font_render_line(
|
||||
if (skip > 1)
|
||||
i += skip - 1;
|
||||
|
||||
const struct font_glyph* glyph =
|
||||
font->font_driver->get_glyph(font->font_data, code);
|
||||
/* Do something smarter here ... */
|
||||
if (!(glyph =
|
||||
font->font_driver->get_glyph(font->font_data, code)))
|
||||
if (!(glyph = glyph_q))
|
||||
continue;
|
||||
|
||||
if (!glyph) /* Do something smarter here ... */
|
||||
glyph = font->font_driver->get_glyph(font->font_data, '?');
|
||||
v->pos.x = x + glyph->draw_offset_x * scale;
|
||||
v->pos.y = y + glyph->draw_offset_y * scale;
|
||||
v->pos.width = glyph->width * scale;
|
||||
v->pos.height = glyph->height * scale;
|
||||
|
||||
if (!glyph)
|
||||
continue;
|
||||
|
||||
v->pos.x = x + glyph->draw_offset_x * scale;
|
||||
v->pos.y = y + glyph->draw_offset_y * scale;
|
||||
v->pos.width = glyph->width * scale;
|
||||
v->pos.height = glyph->height * scale;
|
||||
|
||||
v->coord.u = glyph->atlas_offset_x;
|
||||
v->coord.v = glyph->atlas_offset_y;
|
||||
v->coord.width = glyph->width;
|
||||
v->coord.u = glyph->atlas_offset_x;
|
||||
v->coord.v = glyph->atlas_offset_y;
|
||||
v->coord.width = glyph->width;
|
||||
v->coord.height = glyph->height;
|
||||
|
||||
v->color = color;
|
||||
v->color = color;
|
||||
|
||||
v++;
|
||||
|
||||
x += glyph->advance_x * scale;
|
||||
y += glyph->advance_y * scale;
|
||||
x += glyph->advance_x * scale;
|
||||
y += glyph->advance_y * scale;
|
||||
}
|
||||
|
||||
int count = v - wiiu->vertex_cache.v - wiiu->vertex_cache.current;
|
||||
count = v - wiiu->vertex_cache.v - wiiu->vertex_cache.current;
|
||||
|
||||
if (!count)
|
||||
return;
|
||||
@ -220,13 +226,17 @@ static void wiiu_font_render_line(
|
||||
memcpy(font->texture.surface.image + (i * font->texture.surface.pitch),
|
||||
font->atlas->buffer + (i * font->atlas->width), font->atlas->width);
|
||||
|
||||
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_TEXTURE, font->texture.surface.image,
|
||||
font->texture.surface.imageSize);
|
||||
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_TEXTURE,
|
||||
font->texture.surface.image,
|
||||
font->texture.surface.imageSize);
|
||||
font->atlas->dirty = false;
|
||||
}
|
||||
|
||||
GX2SetPixelTexture(&font->texture, sprite_shader.ps.samplerVars[0].location);
|
||||
GX2SetVertexUniformBlock(sprite_shader.vs.uniformBlocks[1].offset, sprite_shader.vs.uniformBlocks[1].size, font->ubo_tex);
|
||||
GX2SetPixelTexture(&font->texture,
|
||||
sprite_shader.ps.samplerVars[0].location);
|
||||
GX2SetVertexUniformBlock(sprite_shader.vs.uniformBlocks[1].offset,
|
||||
sprite_shader.vs.uniformBlocks[1].size,
|
||||
font->ubo_tex);
|
||||
|
||||
GX2DrawEx(GX2_PRIMITIVE_MODE_POINTS, count, wiiu->vertex_cache.current, 1);
|
||||
|
||||
@ -287,10 +297,9 @@ static void wiiu_font_render_msg(
|
||||
{
|
||||
float x, y, scale, drop_mod, drop_alpha;
|
||||
int drop_x, drop_y;
|
||||
unsigned max_glyphs;
|
||||
enum text_alignment text_align;
|
||||
unsigned color, color_dark, r, g, b,
|
||||
alpha, r_dark, g_dark, b_dark, alpha_dark;
|
||||
unsigned color, r, g, b,
|
||||
alpha;
|
||||
wiiu_video_t *wiiu = (wiiu_video_t*)userdata;
|
||||
wiiu_font_t *font = (wiiu_font_t*)data;
|
||||
unsigned width = wiiu->vp.full_width;
|
||||
@ -341,19 +350,13 @@ static void wiiu_font_render_msg(
|
||||
drop_alpha = 1.0f;
|
||||
}
|
||||
|
||||
max_glyphs = strlen(msg);
|
||||
|
||||
if (drop_x || drop_y)
|
||||
max_glyphs *= 2;
|
||||
|
||||
if (drop_x || drop_y)
|
||||
{
|
||||
r_dark = r * drop_mod;
|
||||
g_dark = g * drop_mod;
|
||||
b_dark = b * drop_mod;
|
||||
alpha_dark = alpha * drop_alpha;
|
||||
color_dark = COLOR_RGBA(r_dark, g_dark, b_dark, alpha_dark);
|
||||
|
||||
unsigned r_dark = r * drop_mod;
|
||||
unsigned g_dark = g * drop_mod;
|
||||
unsigned b_dark = b * drop_mod;
|
||||
unsigned alpha_dark = alpha * drop_alpha;
|
||||
unsigned color_dark = COLOR_RGBA(r_dark, g_dark, b_dark, alpha_dark);
|
||||
wiiu_font_render_message(wiiu, font, msg, scale, color_dark,
|
||||
x + scale * drop_x / width, y +
|
||||
scale * drop_y / height, width, height, text_align);
|
||||
@ -367,24 +370,17 @@ static const struct font_glyph* wiiu_font_get_glyph(
|
||||
void* data, uint32_t code)
|
||||
{
|
||||
wiiu_font_t* font = (wiiu_font_t*)data;
|
||||
|
||||
if (!font || !font->font_driver)
|
||||
return NULL;
|
||||
|
||||
if (!font->font_driver->ident)
|
||||
return NULL;
|
||||
|
||||
return font->font_driver->get_glyph((void*)font->font_driver, code);
|
||||
if (font && font->font_driver && font->font_driver->ident)
|
||||
return font->font_driver->get_glyph((void*)font->font_driver, code);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool wiiu_font_get_line_metrics(void* data, struct font_line_metrics **metrics)
|
||||
{
|
||||
wiiu_font_t* font = (wiiu_font_t*)data;
|
||||
|
||||
if (!font || !font->font_driver || !font->font_data)
|
||||
return -1;
|
||||
|
||||
return font->font_driver->get_line_metrics(font->font_data, metrics);
|
||||
if (font && font->font_driver && font->font_data)
|
||||
return font->font_driver->get_line_metrics(font->font_data, metrics);
|
||||
return -1;
|
||||
}
|
||||
|
||||
font_renderer_t wiiu_font =
|
||||
|
Loading…
x
Reference in New Issue
Block a user