(font drivers) Simplify render_line functions

This commit is contained in:
libretroadmin 2022-07-07 19:51:36 +02:00
parent 281a498474
commit c19e24a584
12 changed files with 185 additions and 207 deletions

View File

@ -163,17 +163,12 @@ static void ctr_font_render_line(
unsigned width, unsigned height, unsigned text_align) unsigned width, unsigned height, unsigned text_align)
{ {
unsigned i; unsigned i;
int x, y;
const struct font_glyph* glyph_q = NULL; const struct font_glyph* glyph_q = NULL;
ctr_vertex_t* v = NULL; ctr_vertex_t* v = NULL;
int delta_x = 0; int delta_x = 0;
int delta_y = 0; int delta_y = 0;
int x = roundf(pos_x * width);
if (!ctr) int y = roundf((1.0f - pos_y) * height);
return;
x = roundf(pos_x * width);
y = roundf((1.0f - pos_y) * height);
switch (text_align) switch (text_align)
{ {
@ -312,7 +307,8 @@ static void ctr_font_render_message(
if (!font->font_driver->get_line_metrics || if (!font->font_driver->get_line_metrics ||
!font->font_driver->get_line_metrics(font->font_data, &line_metrics)) !font->font_driver->get_line_metrics(font->font_data, &line_metrics))
{ {
ctr_font_render_line(ctr, font, msg, strlen(msg), unsigned msg_len = strlen(msg);
ctr_font_render_line(ctr, font, msg, msg_len,
scale, color, pos_x, pos_y, scale, color, pos_x, pos_y,
width, height, text_align); width, height, text_align);
return; return;

View File

@ -131,23 +131,16 @@ static void d3d10_font_render_line(
unsigned height, unsigned height,
unsigned text_align) unsigned text_align)
{ {
int x, y;
unsigned i, count; unsigned i, count;
void* mapped_vbo; void * mapped_vbo;
d3d10_sprite_t* v; d3d10_sprite_t * v;
const struct font_glyph* glyph_q = NULL; const struct font_glyph* glyph_q = NULL;
int x = roundf(pos_x * width);
if ( !d3d10 || int y = roundf((1.0 - pos_y) * height);
!d3d10->sprites.enabled ||
msg_len > (unsigned)d3d10->sprites.capacity)
return;
if (d3d10->sprites.offset + msg_len > (unsigned)d3d10->sprites.capacity) if (d3d10->sprites.offset + msg_len > (unsigned)d3d10->sprites.capacity)
d3d10->sprites.offset = 0; d3d10->sprites.offset = 0;
x = roundf(pos_x * width);
y = roundf((1.0 - pos_y) * height);
switch (text_align) switch (text_align)
{ {
case TEXT_ALIGN_RIGHT: case TEXT_ALIGN_RIGHT:
@ -167,10 +160,10 @@ static void d3d10_font_render_line(
for (i = 0; i < msg_len; i++) for (i = 0; i < msg_len; i++)
{ {
const struct font_glyph* glyph; const struct font_glyph *glyph;
const char *msg_tmp= &msg[i]; const char *msg_tmp = &msg[i];
unsigned code = utf8_walk(&msg_tmp); unsigned code = utf8_walk(&msg_tmp);
unsigned skip = msg_tmp - &msg[i]; unsigned skip = msg_tmp - &msg[i];
if (skip > 1) if (skip > 1)
i += skip - 1; i += skip - 1;
@ -250,14 +243,18 @@ static void d3d10_font_render_message(
if (!msg || !*msg) if (!msg || !*msg)
return; return;
if (!d3d10 || !d3d10->sprites.enabled)
return;
/* If font line metrics are not supported just draw as usual */ /* If font line metrics are not supported just draw as usual */
if (!font->font_driver->get_line_metrics || if (!font->font_driver->get_line_metrics ||
!font->font_driver->get_line_metrics(font->font_data, &line_metrics)) !font->font_driver->get_line_metrics(font->font_data, &line_metrics))
{ {
d3d10_font_render_line(d3d10, unsigned msg_len = strlen(msg);
font, msg, strlen(msg), scale, color, pos_x, pos_y, if (msg_len <= (unsigned)d3d10->sprites.capacity)
width, height, text_align); d3d10_font_render_line(d3d10,
font, msg, msg_len, scale, color, pos_x, pos_y,
width, height, text_align);
return; return;
} }
@ -270,10 +267,11 @@ static void d3d10_font_render_message(
(unsigned)(delim - msg) : strlen(msg); (unsigned)(delim - msg) : strlen(msg);
/* Draw the line */ /* Draw the line */
d3d10_font_render_line(d3d10, if (msg_len <= (unsigned)d3d10->sprites.capacity)
font, msg, msg_len, scale, color, pos_x, d3d10_font_render_line(d3d10,
pos_y - (float)lines * line_height, font, msg, msg_len, scale, color, pos_x,
width, height, text_align); pos_y - (float)lines * line_height,
width, height, text_align);
if (!delim) if (!delim)
break; break;

View File

@ -130,23 +130,16 @@ static void d3d11_font_render_line(
unsigned height, unsigned height,
unsigned text_align) unsigned text_align)
{ {
int x, y;
unsigned i, count; unsigned i, count;
D3D11_MAPPED_SUBRESOURCE mapped_vbo; D3D11_MAPPED_SUBRESOURCE mapped_vbo;
d3d11_sprite_t *v = NULL; d3d11_sprite_t *v = NULL;
const struct font_glyph* glyph_q = NULL; const struct font_glyph* glyph_q = NULL;
int x = roundf(pos_x * width);
if ( !d3d11 || int y = roundf((1.0 - pos_y) * height);
!d3d11->sprites.enabled ||
msg_len > (unsigned)d3d11->sprites.capacity)
return;
if (d3d11->sprites.offset + msg_len > (unsigned)d3d11->sprites.capacity) if (d3d11->sprites.offset + msg_len > (unsigned)d3d11->sprites.capacity)
d3d11->sprites.offset = 0; d3d11->sprites.offset = 0;
x = roundf(pos_x * width);
y = roundf((1.0 - pos_y) * height);
switch (text_align) switch (text_align)
{ {
case TEXT_ALIGN_RIGHT: case TEXT_ALIGN_RIGHT:
@ -254,14 +247,18 @@ static void d3d11_font_render_message(
if (!msg || !*msg) if (!msg || !*msg)
return; return;
if (!d3d11->sprites.enabled)
return;
/* If font line metrics are not supported just draw as usual */ /* If font line metrics are not supported just draw as usual */
if (!font->font_driver->get_line_metrics || if (!font->font_driver->get_line_metrics ||
!font->font_driver->get_line_metrics(font->font_data, &line_metrics)) !font->font_driver->get_line_metrics(font->font_data, &line_metrics))
{ {
d3d11_font_render_line(d3d11, unsigned msg_len = strlen(msg);
font, msg, strlen(msg), scale, color, pos_x, pos_y, if (msg_len <= (unsigned)d3d11->sprites.capacity)
width, height, text_align); d3d11_font_render_line(d3d11,
font, msg, strlen(msg), scale, color, pos_x, pos_y,
width, height, text_align);
return; return;
} }
@ -274,10 +271,11 @@ static void d3d11_font_render_message(
(unsigned)(delim - msg) : strlen(msg); (unsigned)(delim - msg) : strlen(msg);
/* Draw the line */ /* Draw the line */
d3d11_font_render_line(d3d11, if (msg_len <= (unsigned)d3d11->sprites.capacity)
font, msg, msg_len, scale, color, pos_x, d3d11_font_render_line(d3d11,
pos_y - (float)lines * line_height, font, msg, msg_len, scale, color, pos_x,
width, height, text_align); pos_y - (float)lines * line_height,
width, height, text_align);
if (!delim) if (!delim)
break; break;

View File

@ -131,25 +131,18 @@ static void d3d12_font_render_line(
unsigned height, unsigned height,
unsigned text_align) unsigned text_align)
{ {
int x, y; D3D12_RANGE range;
unsigned i, count; unsigned i, count;
const struct font_glyph* glyph_q = NULL; const struct font_glyph* glyph_q = NULL;
void* mapped_vbo = NULL; void* mapped_vbo = NULL;
d3d12_sprite_t* v = NULL; d3d12_sprite_t* v = NULL;
d3d12_sprite_t* vbo_start = NULL; d3d12_sprite_t* vbo_start = NULL;
D3D12_RANGE range; int x = roundf(pos_x * width);
int y = roundf((1.0 - pos_y) * height);
if ( !d3d12 ||
!d3d12->sprites.enabled ||
msg_len > (unsigned)d3d12->sprites.capacity)
return;
if (d3d12->sprites.offset + msg_len > (unsigned)d3d12->sprites.capacity) if (d3d12->sprites.offset + msg_len > (unsigned)d3d12->sprites.capacity)
d3d12->sprites.offset = 0; d3d12->sprites.offset = 0;
x = roundf(pos_x * width);
y = roundf((1.0 - pos_y) * height);
switch (text_align) switch (text_align)
{ {
case TEXT_ALIGN_RIGHT: case TEXT_ALIGN_RIGHT:
@ -256,14 +249,18 @@ static void d3d12_font_render_message(
if (!msg || !*msg) if (!msg || !*msg)
return; return;
if (!d3d12 || !d3d12->sprites.enabled)
return;
/* If font line metrics are not supported just draw as usual */ /* If font line metrics are not supported just draw as usual */
if (!font->font_driver->get_line_metrics || if (!font->font_driver->get_line_metrics ||
!font->font_driver->get_line_metrics(font->font_data, &line_metrics)) !font->font_driver->get_line_metrics(font->font_data, &line_metrics))
{ {
d3d12_font_render_line(d3d12, unsigned msg_len = strlen(msg);
font, msg, strlen(msg), if (msg_len <= (unsigned)d3d12->sprites.capacity)
scale, color, pos_x, pos_y, width, height, text_align); d3d12_font_render_line(d3d12,
font, msg, msg_len,
scale, color, pos_x, pos_y, width, height, text_align);
return; return;
} }
@ -276,9 +273,10 @@ static void d3d12_font_render_message(
(unsigned)(delim - msg) : strlen(msg); (unsigned)(delim - msg) : strlen(msg);
/* Draw the line */ /* Draw the line */
d3d12_font_render_line(d3d12, if (msg_len <= (unsigned)d3d12->sprites.capacity)
font, msg, msg_len, scale, color, pos_x, d3d12_font_render_line(d3d12,
pos_y - (float)lines * line_height, width, height, text_align); font, msg, msg_len, scale, color, pos_x,
pos_y - (float)lines * line_height, width, height, text_align);
if (!delim) if (!delim)
break; break;

View File

@ -301,7 +301,7 @@ static void gl1_raster_font_draw_vertices(gl1_raster_t *font,
glPopMatrix(); glPopMatrix();
} }
static void gl1_raster_font_render_line( static void gl1_raster_font_render_line(gl1_t *gl,
gl1_raster_t *font, const char *msg, unsigned msg_len, gl1_raster_t *font, const char *msg, unsigned msg_len,
GLfloat scale, const GLfloat color[4], GLfloat pos_x, GLfloat scale, const GLfloat color[4], GLfloat pos_x,
GLfloat pos_y, unsigned text_align) GLfloat pos_y, unsigned text_align)
@ -313,7 +313,6 @@ static void gl1_raster_font_render_line(
GLfloat font_vertex[2 * 6 * MAX_MSG_LEN_CHUNK]; GLfloat font_vertex[2 * 6 * MAX_MSG_LEN_CHUNK];
GLfloat font_color[4 * 6 * MAX_MSG_LEN_CHUNK]; GLfloat font_color[4 * 6 * MAX_MSG_LEN_CHUNK];
GLfloat font_lut_tex_coord[2 * 6 * MAX_MSG_LEN_CHUNK]; GLfloat font_lut_tex_coord[2 * 6 * MAX_MSG_LEN_CHUNK];
gl1_t *gl = font->gl;
const char* msg_end = msg + msg_len; const char* msg_end = msg + msg_len;
int x = roundf(pos_x * gl->vp.width); int x = roundf(pos_x * gl->vp.width);
int y = roundf(pos_y * gl->vp.height); int y = roundf(pos_y * gl->vp.height);
@ -321,8 +320,8 @@ static void gl1_raster_font_render_line(
int delta_y = 0; int delta_y = 0;
float inv_tex_size_x = 1.0f / font->tex_width; float inv_tex_size_x = 1.0f / font->tex_width;
float inv_tex_size_y = 1.0f / font->tex_height; float inv_tex_size_y = 1.0f / font->tex_height;
float inv_win_width = 1.0f / font->gl->vp.width; float inv_win_width = 1.0f / gl->vp.width;
float inv_win_height = 1.0f / font->gl->vp.height; float inv_win_height = 1.0f / gl->vp.height;
switch (text_align) switch (text_align)
{ {
@ -398,7 +397,7 @@ static void gl1_raster_font_render_message(
if (!font->font_driver->get_line_metrics || if (!font->font_driver->get_line_metrics ||
!font->font_driver->get_line_metrics(font->font_data, &line_metrics)) !font->font_driver->get_line_metrics(font->font_data, &line_metrics))
{ {
gl1_raster_font_render_line(font, gl1_raster_font_render_line(font->gl, font,
msg, (unsigned)strlen(msg), scale, color, pos_x, msg, (unsigned)strlen(msg), scale, color, pos_x,
pos_y, text_align); pos_y, text_align);
return; return;
@ -413,7 +412,7 @@ static void gl1_raster_font_render_message(
? (unsigned)(delim - msg) : (unsigned)strlen(msg); ? (unsigned)(delim - msg) : (unsigned)strlen(msg);
/* Draw the line */ /* Draw the line */
gl1_raster_font_render_line(font, gl1_raster_font_render_line(font->gl, font,
msg, msg_len, scale, color, pos_x, msg, msg_len, scale, color, pos_x,
pos_y - (float)lines*line_height, text_align); pos_y - (float)lines*line_height, text_align);

View File

@ -282,7 +282,7 @@ static void gl2_raster_font_draw_vertices(gl2_raster_t *font,
glDrawArrays(GL_TRIANGLES, 0, coords->vertices); glDrawArrays(GL_TRIANGLES, 0, coords->vertices);
} }
static void gl2_raster_font_render_line( static void gl2_raster_font_render_line(gl2_t *gl,
gl2_raster_t *font, const char *msg, unsigned msg_len, gl2_raster_t *font, const char *msg, unsigned msg_len,
GLfloat scale, const GLfloat color[4], GLfloat pos_x, GLfloat scale, const GLfloat color[4], GLfloat pos_x,
GLfloat pos_y, unsigned text_align) GLfloat pos_y, unsigned text_align)
@ -294,7 +294,6 @@ static void gl2_raster_font_render_line(
GLfloat font_vertex[2 * 6 * MAX_MSG_LEN_CHUNK]; GLfloat font_vertex[2 * 6 * MAX_MSG_LEN_CHUNK];
GLfloat font_color[4 * 6 * MAX_MSG_LEN_CHUNK]; GLfloat font_color[4 * 6 * MAX_MSG_LEN_CHUNK];
GLfloat font_lut_tex_coord[2 * 6 * MAX_MSG_LEN_CHUNK]; GLfloat font_lut_tex_coord[2 * 6 * MAX_MSG_LEN_CHUNK];
gl2_t *gl = font->gl;
const char* msg_end = msg + msg_len; const char* msg_end = msg + msg_len;
int x = roundf(pos_x * gl->vp.width); int x = roundf(pos_x * gl->vp.width);
int y = roundf(pos_y * gl->vp.height); int y = roundf(pos_y * gl->vp.height);
@ -302,8 +301,8 @@ static void gl2_raster_font_render_line(
int delta_y = 0; int delta_y = 0;
float inv_tex_size_x = 1.0f / font->tex_width; float inv_tex_size_x = 1.0f / font->tex_width;
float inv_tex_size_y = 1.0f / font->tex_height; float inv_tex_size_y = 1.0f / font->tex_height;
float inv_win_width = 1.0f / font->gl->vp.width; float inv_win_width = 1.0f / gl->vp.width;
float inv_win_height = 1.0f / font->gl->vp.height; float inv_win_height = 1.0f / gl->vp.height;
switch (text_align) switch (text_align)
{ {
@ -379,7 +378,7 @@ static void gl2_raster_font_render_message(
if (!font->font_driver->get_line_metrics || if (!font->font_driver->get_line_metrics ||
!font->font_driver->get_line_metrics(font->font_data, &line_metrics)) !font->font_driver->get_line_metrics(font->font_data, &line_metrics))
{ {
gl2_raster_font_render_line(font, gl2_raster_font_render_line(font->gl, font,
msg, (unsigned)strlen(msg), scale, color, pos_x, msg, (unsigned)strlen(msg), scale, color, pos_x,
pos_y, text_align); pos_y, text_align);
return; return;
@ -394,7 +393,7 @@ static void gl2_raster_font_render_message(
? (unsigned)(delim - msg) : (unsigned)strlen(msg); ? (unsigned)(delim - msg) : (unsigned)strlen(msg);
/* Draw the line */ /* Draw the line */
gl2_raster_font_render_line(font, gl2_raster_font_render_line(font->gl, font,
msg, msg_len, scale, color, pos_x, msg, msg_len, scale, color, pos_x,
pos_y - (float)lines*line_height, text_align); pos_y - (float)lines*line_height, text_align);
@ -436,8 +435,8 @@ static void gl2_raster_font_render_msg(
enum text_alignment text_align = TEXT_ALIGN_LEFT; enum text_alignment text_align = TEXT_ALIGN_LEFT;
bool full_screen = false ; bool full_screen = false ;
gl2_raster_t *font = (gl2_raster_t*)data; gl2_raster_t *font = (gl2_raster_t*)data;
unsigned width = font->gl->video_width; unsigned width = font->gl->video_width;
unsigned height = font->gl->video_height; unsigned height = font->gl->video_height;
if (!font || string_is_empty(msg)) if (!font || string_is_empty(msg))
return; return;

View File

@ -207,7 +207,7 @@ static void gl3_raster_font_draw_vertices(gl3_raster_t *font,
glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, 0);
} }
static void gl3_raster_font_render_line( static void gl3_raster_font_render_line(gl3_t *gl,
gl3_raster_t *font, const char *msg, unsigned msg_len, gl3_raster_t *font, const char *msg, unsigned msg_len,
GLfloat scale, const GLfloat color[4], GLfloat pos_x, GLfloat scale, const GLfloat color[4], GLfloat pos_x,
GLfloat pos_y, unsigned text_align) GLfloat pos_y, unsigned text_align)
@ -218,7 +218,6 @@ static void gl3_raster_font_render_line(
GLfloat font_tex_coords[2 * 6 * MAX_MSG_LEN_CHUNK]; GLfloat font_tex_coords[2 * 6 * MAX_MSG_LEN_CHUNK];
GLfloat font_vertex[2 * 6 * MAX_MSG_LEN_CHUNK]; GLfloat font_vertex[2 * 6 * MAX_MSG_LEN_CHUNK];
GLfloat font_color[4 * 6 * MAX_MSG_LEN_CHUNK]; GLfloat font_color[4 * 6 * MAX_MSG_LEN_CHUNK];
gl3_t *gl = font->gl;
const char* msg_end = msg + msg_len; const char* msg_end = msg + msg_len;
int x = roundf(pos_x * gl->vp.width); int x = roundf(pos_x * gl->vp.width);
int y = roundf(pos_y * gl->vp.height); int y = roundf(pos_y * gl->vp.height);
@ -226,8 +225,8 @@ static void gl3_raster_font_render_line(
int delta_y = 0; int delta_y = 0;
float inv_tex_size_x = 1.0f / font->atlas->width; float inv_tex_size_x = 1.0f / font->atlas->width;
float inv_tex_size_y = 1.0f / font->atlas->height; float inv_tex_size_y = 1.0f / font->atlas->height;
float inv_win_width = 1.0f / font->gl->vp.width; float inv_win_width = 1.0f / gl->vp.width;
float inv_win_height = 1.0f / font->gl->vp.height; float inv_win_height = 1.0f / gl->vp.height;
switch (text_align) switch (text_align)
{ {
@ -303,7 +302,7 @@ static void gl3_raster_font_render_message(
if (!font->font_driver->get_line_metrics || if (!font->font_driver->get_line_metrics ||
!font->font_driver->get_line_metrics(font->font_data, &line_metrics)) !font->font_driver->get_line_metrics(font->font_data, &line_metrics))
{ {
gl3_raster_font_render_line(font, gl3_raster_font_render_line(font->gl, font,
msg, (unsigned)strlen(msg), scale, color, pos_x, msg, (unsigned)strlen(msg), scale, color, pos_x,
pos_y, text_align); pos_y, text_align);
return; return;
@ -318,7 +317,7 @@ static void gl3_raster_font_render_message(
? (unsigned)(delim - msg) : (unsigned)strlen(msg); ? (unsigned)(delim - msg) : (unsigned)strlen(msg);
/* Draw the line */ /* Draw the line */
gl3_raster_font_render_line(font, gl3_raster_font_render_line(font->gl, font,
msg, msg_len, scale, color, pos_x, msg, msg_len, scale, color, pos_x,
pos_y - (float)lines*line_height, text_align); pos_y - (float)lines*line_height, text_align);

View File

@ -148,10 +148,11 @@ static void ps2_font_render_line(
int y = roundf((1.0f - pos_y) * height); int y = roundf((1.0f - pos_y) * height);
int delta_x = 0; int delta_x = 0;
int delta_y = 0; int delta_y = 0;
int colorR, colorG, colorB, colorA; /* We need to >> 1, because GS_SETREG_RGBAQ expects 0x80 as max color */
int colorA = (int)(((color & 0xFF000000) >> 24) >> 2);
if (!ps2) int colorB = (int)(((color & 0x00FF0000) >> 16) >> 1);
return; int colorG = (int)(((color & 0x0000FF00) >> 8) >> 1);
int colorR = (int)(((color & 0x000000FF) >> 0) >> 1);
/* Enable Alpha for font */ /* Enable Alpha for font */
gsKit_set_primalpha(ps2->gsGlobal, GS_SETREG_ALPHA(0, 1, 0, 1, 0), 0); gsKit_set_primalpha(ps2->gsGlobal, GS_SETREG_ALPHA(0, 1, 0, 1, 0), 0);
@ -169,11 +170,6 @@ static void ps2_font_render_line(
break; break;
} }
/* 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);
glyph_q = font->font_driver->get_glyph(font->font_data, '?'); glyph_q = font->font_driver->get_glyph(font->font_data, '?');
for (i = 0; i < msg_len; i++) for (i = 0; i < msg_len; i++)
@ -202,8 +198,7 @@ static void ps2_font_render_line(
height = glyph->height; height = glyph->height;
/* The -0.5 is needed to achieve pixel perfect. /* The -0.5 is needed to achieve pixel perfect.
* More info here (PS2 uses * More info here (PS2 GSKit uses same logic as Direct3D9)
* same logic as Direct3D 9)
* https://docs.microsoft.com/en-us/windows/win32/direct3d10/d3d10-graphics-programming-guide-resources-coordinates * https://docs.microsoft.com/en-us/windows/win32/direct3d10/d3d10-graphics-programming-guide-resources-coordinates
*/ */
x1 = -0.5f + x + (off_x + delta_x) * scale; x1 = -0.5f + x + (off_x + delta_x) * scale;

View File

@ -75,7 +75,8 @@ static void rsx_font_free(void *data,
if (font->font_driver && font->font_data) if (font->font_driver && font->font_data)
font->font_driver->free(font->font_data); font->font_driver->free(font->font_data);
if (is_threaded) { if (is_threaded)
{
if ( if (
font->rsx && font->rsx &&
font->rsx->ctx_driver && font->rsx->ctx_driver &&
@ -158,28 +159,28 @@ static void *rsx_font_init(void *data,
font->rsx->ctx_driver->make_current) font->rsx->ctx_driver->make_current)
font->rsx->ctx_driver->make_current(false); font->rsx->ctx_driver->make_current(false);
font->atlas = font->font_driver->get_atlas(font->font_data); font->atlas = font->font_driver->get_atlas(font->font_data);
font->vpo = font->rsx->vpo; font->vpo = font->rsx->vpo;
font->fpo = font->rsx->fpo; font->fpo = font->rsx->fpo;
font->fp_ucode = font->rsx->fp_ucode; font->fp_ucode = font->rsx->fp_ucode;
font->vp_ucode = font->rsx->vp_ucode; font->vp_ucode = font->rsx->vp_ucode;
font->fp_offset = font->rsx->fp_offset; font->fp_offset = font->rsx->fp_offset;
font->proj_matrix = font->rsx->proj_matrix; font->proj_matrix = font->rsx->proj_matrix;
font->pos_index = font->rsx->pos_index; font->pos_index = font->rsx->pos_index;
font->uv_index = font->rsx->uv_index; font->uv_index = font->rsx->uv_index;
font->col_index = font->rsx->col_index; font->col_index = font->rsx->col_index;
font->tex_unit = font->rsx->tex_unit; font->tex_unit = font->rsx->tex_unit;
font->vertices = (rsx_vertex_t *)rsxMemalign(128, MAX_MSG_LEN_CHUNK*sizeof(rsx_vertex_t)*6); font->vertices = (rsx_vertex_t *)rsxMemalign(128, MAX_MSG_LEN_CHUNK*sizeof(rsx_vertex_t)*6);
rsxAddressToOffset(&font->vertices[0].x, &font->pos_offset); rsxAddressToOffset(&font->vertices[0].x, &font->pos_offset);
rsxAddressToOffset(&font->vertices[0].u, &font->uv_offset); rsxAddressToOffset(&font->vertices[0].u, &font->uv_offset);
rsxAddressToOffset(&font->vertices[0].r, &font->col_offset); rsxAddressToOffset(&font->vertices[0].r, &font->col_offset);
font->tex_width = font->atlas->width; font->tex_width = font->atlas->width;
font->tex_height = font->atlas->height; font->tex_height = font->atlas->height;
font->texture.data = (u8 *)rsxMemalign(128, (font->tex_height * font->tex_width)); font->texture.data = (u8 *)rsxMemalign(128, (font->tex_height * font->tex_width));
rsxAddressToOffset(font->texture.data, &font->texture.offset); rsxAddressToOffset(font->texture.data, &font->texture.offset);
@ -421,7 +422,7 @@ static void rsx_font_render_msg(
float x, y, scale, drop_mod, drop_alpha; float x, y, scale, drop_mod, drop_alpha;
enum text_alignment text_align = TEXT_ALIGN_LEFT; enum text_alignment text_align = TEXT_ALIGN_LEFT;
bool full_screen = false ; bool full_screen = false ;
rsx_font_t *font = (rsx_font_t*)data; rsx_font_t *font = (rsx_font_t*)data;
unsigned width = font->rsx->width; unsigned width = font->rsx->width;
unsigned height = font->rsx->height; unsigned height = font->rsx->height;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();

View File

@ -115,74 +115,70 @@ static void switch_font_render_line(
float scale, const unsigned int color, float pos_x, float scale, const unsigned int color, float pos_x,
float pos_y, unsigned text_align) float pos_y, unsigned text_align)
{ {
int delta_x = 0; unsigned i;
int delta_y = 0; const struct font_glyph* glyph_q = NULL;
unsigned fb_width = sw->vp.full_width; int delta_x = 0;
unsigned fb_height = sw->vp.full_height; int delta_y = 0;
unsigned fb_width = sw->vp.full_width;
unsigned fb_height = sw->vp.full_height;
int x = roundf(pos_x * fb_width);
int y = roundf((1.0f - pos_y) * fb_height);
if (sw->out_buffer) switch (text_align)
{ {
unsigned i; case TEXT_ALIGN_RIGHT:
const struct font_glyph* glyph_q = NULL; x -= switch_font_get_message_width(font, msg, msg_len, scale);
int x = roundf(pos_x * fb_width); break;
int y = roundf((1.0f - pos_y) * fb_height); case TEXT_ALIGN_CENTER:
x -= switch_font_get_message_width(font, msg, msg_len, scale) / 2;
break;
}
switch (text_align) 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);
unsigned skip = msg_tmp - &msg[i];
if (skip > 1)
i += skip - 1;
/* 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;
width = glyph->width;
height = glyph->height;
tex_x = glyph->atlas_offset_x;
tex_y = glyph->atlas_offset_y;
for (y = tex_y; y < tex_y + height; y++)
{ {
case TEXT_ALIGN_RIGHT: int x;
x -= switch_font_get_message_width(font, msg, msg_len, scale); uint8_t *row = &font->atlas->buffer[y * font->atlas->width];
break; for (x = tex_x; x < tex_x + width; x++)
case TEXT_ALIGN_CENTER:
x -= switch_font_get_message_width(font, msg, msg_len, scale) / 2;
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);
unsigned skip = msg_tmp - &msg[i];
if (skip > 1)
i += skip - 1;
/* 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;
width = glyph->width;
height = glyph->height;
tex_x = glyph->atlas_offset_x;
tex_y = glyph->atlas_offset_y;
for (y = tex_y; y < tex_y + height; y++)
{ {
int x; int x1, y1;
uint8_t *row = &font->atlas->buffer[y * font->atlas->width]; if (!row[x])
for (x = tex_x; x < tex_x + width; x++) continue;
{ x1 = off_x + (x - tex_x);
int x1, y1; y1 = off_y + (y - tex_y);
if (!row[x]) if (x1 < fb_width && y1 < fb_height)
continue; sw->out_buffer[y1 * sw->stride / sizeof(uint32_t) + x1] = color;
x1 = off_x + (x - tex_x);
y1 = off_y + (y - tex_y);
if (x1 < fb_width && y1 < fb_height)
sw->out_buffer[y1 * sw->stride / sizeof(uint32_t) + x1] = color;
}
} }
delta_x += glyph->advance_x;
delta_y += glyph->advance_y;
} }
delta_x += glyph->advance_x;
delta_y += glyph->advance_y;
} }
} }
@ -198,6 +194,8 @@ static void switch_font_render_message(
if (!msg || !*msg || !sw) if (!msg || !*msg || !sw)
return; return;
if (!sw || !sw->out_buffer)
return;
/* If font line metrics are not supported just draw as usual */ /* If font line metrics are not supported just draw as usual */
if (!font->font_driver->get_line_metrics || if (!font->font_driver->get_line_metrics ||
@ -205,13 +203,11 @@ static void switch_font_render_message(
{ {
int msg_len = strlen(msg); int msg_len = strlen(msg);
if (msg_len <= AVG_GLPYH_LIMIT) if (msg_len <= AVG_GLPYH_LIMIT)
{ switch_font_render_line(sw, font, msg, strlen(msg),
if (sw) scale, color, pos_x, pos_y, text_align);
switch_font_render_line(sw, font, msg, strlen(msg),
scale, color, pos_x, pos_y, text_align);
}
return; return;
} }
line_height = scale / line_metrics->height; line_height = scale / line_metrics->height;
for (;;) for (;;)

View File

@ -148,28 +148,27 @@ static int vulkan_get_message_width(void *data, const char *msg,
return delta_x * scale; return delta_x * scale;
} }
static void vulkan_font_render_line( static void vulkan_font_render_line(vk_t *vk,
vulkan_raster_t *font, const char *msg, unsigned msg_len, vulkan_raster_t *font, const char *msg, unsigned msg_len,
float scale, const float color[4], float pos_x, float scale, const float color[4], float pos_x,
float pos_y, unsigned text_align) float pos_y, unsigned text_align)
{ {
struct vk_color vk_color; struct vk_color vk_color;
const struct font_glyph* glyph_q = NULL; const struct font_glyph* glyph_q = NULL;
vk_t *vk = font->vk; const char* msg_end = msg + msg_len;
const char* msg_end = msg + msg_len; int x = roundf(pos_x * vk->vp.width);
int x = roundf(pos_x * vk->vp.width); int y = roundf((1.0f - pos_y) * vk->vp.height);
int y = roundf((1.0f - pos_y) * vk->vp.height); int delta_x = 0;
int delta_x = 0; int delta_y = 0;
int delta_y = 0; float inv_tex_size_x = 1.0f / font->texture.width;
float inv_tex_size_x = 1.0f / font->texture.width; float inv_tex_size_y = 1.0f / font->texture.height;
float inv_tex_size_y = 1.0f / font->texture.height; float inv_win_width = 1.0f / font->vk->vp.width;
float inv_win_width = 1.0f / font->vk->vp.width; float inv_win_height = 1.0f / font->vk->vp.height;
float inv_win_height = 1.0f / font->vk->vp.height;
vk_color.r = color[0]; vk_color.r = color[0];
vk_color.g = color[1]; vk_color.g = color[1];
vk_color.b = color[2]; vk_color.b = color[2];
vk_color.a = color[3]; vk_color.a = color[3];
switch (text_align) switch (text_align)
{ {
@ -187,7 +186,7 @@ static void vulkan_font_render_line(
{ {
const struct font_glyph *glyph; const struct font_glyph *glyph;
int off_x, off_y, tex_x, tex_y, width, height; int off_x, off_y, tex_x, tex_y, width, height;
unsigned code = utf8_walk(&msg); unsigned code = utf8_walk(&msg);
/* Do something smarter here ... */ /* Do something smarter here ... */
if (!(glyph = if (!(glyph =
@ -249,7 +248,7 @@ static void vulkan_font_render_message(
if (!font->font_driver->get_line_metrics || if (!font->font_driver->get_line_metrics ||
!font->font_driver->get_line_metrics(font->font_data, &line_metrics)) !font->font_driver->get_line_metrics(font->font_data, &line_metrics))
{ {
vulkan_font_render_line(font, msg, strlen(msg), vulkan_font_render_line(font->vk, font, msg, strlen(msg),
scale, color, pos_x, pos_y, text_align); scale, color, pos_x, pos_y, text_align);
return; return;
} }
@ -263,7 +262,7 @@ static void vulkan_font_render_message(
? (unsigned)(delim - msg) : (unsigned)strlen(msg); ? (unsigned)(delim - msg) : (unsigned)strlen(msg);
/* Draw the line */ /* Draw the line */
vulkan_font_render_line(font, msg, msg_len, vulkan_font_render_line(font->vk, font, msg, msg_len,
scale, color, pos_x, pos_y - (float)lines * line_height, scale, color, pos_x, pos_y - (float)lines * line_height,
text_align); text_align);

View File

@ -154,16 +154,11 @@ static void wiiu_font_render_line(
unsigned width, unsigned height, unsigned text_align) unsigned width, unsigned height, unsigned text_align)
{ {
unsigned i; unsigned i;
int count, x, y; int count;
sprite_vertex_t *v; sprite_vertex_t *v;
const struct font_glyph* glyph_q = NULL; const struct font_glyph* glyph_q = NULL;
int x = roundf(pos_x * width);
if( !wiiu || int y = roundf((1.0 - pos_y) * height);
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) switch (text_align)
{ {
@ -257,14 +252,18 @@ static void wiiu_font_render_message(
if (!msg || !*msg) if (!msg || !*msg)
return; return;
if (!wiiu)
return;
/* If font line metrics are not supported just draw as usual */ /* If font line metrics are not supported just draw as usual */
if (!font->font_driver->get_line_metrics || if (!font->font_driver->get_line_metrics ||
!font->font_driver->get_line_metrics(font->font_data, &line_metrics)) !font->font_driver->get_line_metrics(font->font_data, &line_metrics))
{ {
wiiu_font_render_line(wiiu, font, msg, strlen(msg), unsigned msg_len = strlen(msg);
scale, color, pos_x, pos_y, if (wiiu->vertex_cache.current + (msg_len * 4) <= wiiu->vertex_cache.size)
width, height, text_align); wiiu_font_render_line(wiiu, font, msg, msg_len,
scale, color, pos_x, pos_y,
width, height, text_align);
return; return;
} }
@ -277,9 +276,10 @@ static void wiiu_font_render_message(
(unsigned)(delim - msg) : strlen(msg); (unsigned)(delim - msg) : strlen(msg);
/* Draw the line */ /* Draw the line */
wiiu_font_render_line(wiiu, font, msg, msg_len, if (wiiu->vertex_cache.current + (msg_len * 4) <= wiiu->vertex_cache.size)
scale, color, pos_x, pos_y - (float)lines * line_height, wiiu_font_render_line(wiiu, font, msg, msg_len,
width, height, text_align); scale, color, pos_x, pos_y - (float)lines * line_height,
width, height, text_align);
if (!delim) if (!delim)
break; break;