mirror of
https://github.com/libretro/RetroArch
synced 2025-04-11 00:44:20 +00:00
(font drivers) Simplify render_line functions
This commit is contained in:
parent
281a498474
commit
c19e24a584
@ -163,17 +163,12 @@ 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 delta_x = 0;
|
||||
int delta_y = 0;
|
||||
|
||||
if (!ctr)
|
||||
return;
|
||||
|
||||
x = roundf(pos_x * width);
|
||||
y = roundf((1.0f - pos_y) * height);
|
||||
int x = roundf(pos_x * width);
|
||||
int y = roundf((1.0f - pos_y) * height);
|
||||
|
||||
switch (text_align)
|
||||
{
|
||||
@ -312,7 +307,8 @@ static void ctr_font_render_message(
|
||||
if (!font->font_driver->get_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,
|
||||
width, height, text_align);
|
||||
return;
|
||||
|
@ -131,23 +131,16 @@ static void d3d10_font_render_line(
|
||||
unsigned height,
|
||||
unsigned text_align)
|
||||
{
|
||||
int x, y;
|
||||
unsigned i, count;
|
||||
void* mapped_vbo;
|
||||
d3d10_sprite_t* v;
|
||||
void * mapped_vbo;
|
||||
d3d10_sprite_t * v;
|
||||
const struct font_glyph* glyph_q = NULL;
|
||||
|
||||
if ( !d3d10 ||
|
||||
!d3d10->sprites.enabled ||
|
||||
msg_len > (unsigned)d3d10->sprites.capacity)
|
||||
return;
|
||||
int x = roundf(pos_x * width);
|
||||
int y = roundf((1.0 - pos_y) * height);
|
||||
|
||||
if (d3d10->sprites.offset + msg_len > (unsigned)d3d10->sprites.capacity)
|
||||
d3d10->sprites.offset = 0;
|
||||
|
||||
x = roundf(pos_x * width);
|
||||
y = roundf((1.0 - pos_y) * height);
|
||||
|
||||
switch (text_align)
|
||||
{
|
||||
case TEXT_ALIGN_RIGHT:
|
||||
@ -167,10 +160,10 @@ static void d3d10_font_render_line(
|
||||
|
||||
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];
|
||||
const struct font_glyph *glyph;
|
||||
const char *msg_tmp = &msg[i];
|
||||
unsigned code = utf8_walk(&msg_tmp);
|
||||
unsigned skip = msg_tmp - &msg[i];
|
||||
|
||||
if (skip > 1)
|
||||
i += skip - 1;
|
||||
@ -250,14 +243,18 @@ static void d3d10_font_render_message(
|
||||
|
||||
if (!msg || !*msg)
|
||||
return;
|
||||
if (!d3d10 || !d3d10->sprites.enabled)
|
||||
return;
|
||||
|
||||
/* If font line metrics are not supported just draw as usual */
|
||||
if (!font->font_driver->get_line_metrics ||
|
||||
!font->font_driver->get_line_metrics(font->font_data, &line_metrics))
|
||||
{
|
||||
d3d10_font_render_line(d3d10,
|
||||
font, msg, strlen(msg), scale, color, pos_x, pos_y,
|
||||
width, height, text_align);
|
||||
unsigned msg_len = strlen(msg);
|
||||
if (msg_len <= (unsigned)d3d10->sprites.capacity)
|
||||
d3d10_font_render_line(d3d10,
|
||||
font, msg, msg_len, scale, color, pos_x, pos_y,
|
||||
width, height, text_align);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -270,10 +267,11 @@ static void d3d10_font_render_message(
|
||||
(unsigned)(delim - msg) : strlen(msg);
|
||||
|
||||
/* Draw the line */
|
||||
d3d10_font_render_line(d3d10,
|
||||
font, msg, msg_len, scale, color, pos_x,
|
||||
pos_y - (float)lines * line_height,
|
||||
width, height, text_align);
|
||||
if (msg_len <= (unsigned)d3d10->sprites.capacity)
|
||||
d3d10_font_render_line(d3d10,
|
||||
font, msg, msg_len, scale, color, pos_x,
|
||||
pos_y - (float)lines * line_height,
|
||||
width, height, text_align);
|
||||
|
||||
if (!delim)
|
||||
break;
|
||||
|
@ -130,23 +130,16 @@ static void d3d11_font_render_line(
|
||||
unsigned height,
|
||||
unsigned text_align)
|
||||
{
|
||||
int x, y;
|
||||
unsigned i, count;
|
||||
D3D11_MAPPED_SUBRESOURCE mapped_vbo;
|
||||
d3d11_sprite_t *v = NULL;
|
||||
const struct font_glyph* glyph_q = NULL;
|
||||
|
||||
if ( !d3d11 ||
|
||||
!d3d11->sprites.enabled ||
|
||||
msg_len > (unsigned)d3d11->sprites.capacity)
|
||||
return;
|
||||
int x = roundf(pos_x * width);
|
||||
int y = roundf((1.0 - pos_y) * height);
|
||||
|
||||
if (d3d11->sprites.offset + msg_len > (unsigned)d3d11->sprites.capacity)
|
||||
d3d11->sprites.offset = 0;
|
||||
|
||||
x = roundf(pos_x * width);
|
||||
y = roundf((1.0 - pos_y) * height);
|
||||
|
||||
switch (text_align)
|
||||
{
|
||||
case TEXT_ALIGN_RIGHT:
|
||||
@ -254,14 +247,18 @@ static void d3d11_font_render_message(
|
||||
|
||||
if (!msg || !*msg)
|
||||
return;
|
||||
if (!d3d11->sprites.enabled)
|
||||
return;
|
||||
|
||||
/* If font line metrics are not supported just draw as usual */
|
||||
if (!font->font_driver->get_line_metrics ||
|
||||
!font->font_driver->get_line_metrics(font->font_data, &line_metrics))
|
||||
{
|
||||
d3d11_font_render_line(d3d11,
|
||||
font, msg, strlen(msg), scale, color, pos_x, pos_y,
|
||||
width, height, text_align);
|
||||
unsigned msg_len = strlen(msg);
|
||||
if (msg_len <= (unsigned)d3d11->sprites.capacity)
|
||||
d3d11_font_render_line(d3d11,
|
||||
font, msg, strlen(msg), scale, color, pos_x, pos_y,
|
||||
width, height, text_align);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -274,10 +271,11 @@ static void d3d11_font_render_message(
|
||||
(unsigned)(delim - msg) : strlen(msg);
|
||||
|
||||
/* Draw the line */
|
||||
d3d11_font_render_line(d3d11,
|
||||
font, msg, msg_len, scale, color, pos_x,
|
||||
pos_y - (float)lines * line_height,
|
||||
width, height, text_align);
|
||||
if (msg_len <= (unsigned)d3d11->sprites.capacity)
|
||||
d3d11_font_render_line(d3d11,
|
||||
font, msg, msg_len, scale, color, pos_x,
|
||||
pos_y - (float)lines * line_height,
|
||||
width, height, text_align);
|
||||
|
||||
if (!delim)
|
||||
break;
|
||||
|
@ -131,25 +131,18 @@ static void d3d12_font_render_line(
|
||||
unsigned height,
|
||||
unsigned text_align)
|
||||
{
|
||||
int x, y;
|
||||
D3D12_RANGE range;
|
||||
unsigned i, count;
|
||||
const struct font_glyph* glyph_q = NULL;
|
||||
void* mapped_vbo = NULL;
|
||||
d3d12_sprite_t* v = NULL;
|
||||
d3d12_sprite_t* vbo_start = NULL;
|
||||
D3D12_RANGE range;
|
||||
|
||||
if ( !d3d12 ||
|
||||
!d3d12->sprites.enabled ||
|
||||
msg_len > (unsigned)d3d12->sprites.capacity)
|
||||
return;
|
||||
int x = roundf(pos_x * width);
|
||||
int y = roundf((1.0 - pos_y) * height);
|
||||
|
||||
if (d3d12->sprites.offset + msg_len > (unsigned)d3d12->sprites.capacity)
|
||||
d3d12->sprites.offset = 0;
|
||||
|
||||
x = roundf(pos_x * width);
|
||||
y = roundf((1.0 - pos_y) * height);
|
||||
|
||||
switch (text_align)
|
||||
{
|
||||
case TEXT_ALIGN_RIGHT:
|
||||
@ -256,14 +249,18 @@ static void d3d12_font_render_message(
|
||||
|
||||
if (!msg || !*msg)
|
||||
return;
|
||||
if (!d3d12 || !d3d12->sprites.enabled)
|
||||
return;
|
||||
|
||||
/* If font line metrics are not supported just draw as usual */
|
||||
if (!font->font_driver->get_line_metrics ||
|
||||
!font->font_driver->get_line_metrics(font->font_data, &line_metrics))
|
||||
{
|
||||
d3d12_font_render_line(d3d12,
|
||||
font, msg, strlen(msg),
|
||||
scale, color, pos_x, pos_y, width, height, text_align);
|
||||
unsigned msg_len = strlen(msg);
|
||||
if (msg_len <= (unsigned)d3d12->sprites.capacity)
|
||||
d3d12_font_render_line(d3d12,
|
||||
font, msg, msg_len,
|
||||
scale, color, pos_x, pos_y, width, height, text_align);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -276,9 +273,10 @@ static void d3d12_font_render_message(
|
||||
(unsigned)(delim - msg) : strlen(msg);
|
||||
|
||||
/* Draw the line */
|
||||
d3d12_font_render_line(d3d12,
|
||||
font, msg, msg_len, scale, color, pos_x,
|
||||
pos_y - (float)lines * line_height, width, height, text_align);
|
||||
if (msg_len <= (unsigned)d3d12->sprites.capacity)
|
||||
d3d12_font_render_line(d3d12,
|
||||
font, msg, msg_len, scale, color, pos_x,
|
||||
pos_y - (float)lines * line_height, width, height, text_align);
|
||||
|
||||
if (!delim)
|
||||
break;
|
||||
|
@ -301,7 +301,7 @@ static void gl1_raster_font_draw_vertices(gl1_raster_t *font,
|
||||
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,
|
||||
GLfloat scale, const GLfloat color[4], GLfloat pos_x,
|
||||
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_color[4 * 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;
|
||||
int x = roundf(pos_x * gl->vp.width);
|
||||
int y = roundf(pos_y * gl->vp.height);
|
||||
@ -321,8 +320,8 @@ static void gl1_raster_font_render_line(
|
||||
int delta_y = 0;
|
||||
float inv_tex_size_x = 1.0f / font->tex_width;
|
||||
float inv_tex_size_y = 1.0f / font->tex_height;
|
||||
float inv_win_width = 1.0f / font->gl->vp.width;
|
||||
float inv_win_height = 1.0f / font->gl->vp.height;
|
||||
float inv_win_width = 1.0f / gl->vp.width;
|
||||
float inv_win_height = 1.0f / gl->vp.height;
|
||||
|
||||
switch (text_align)
|
||||
{
|
||||
@ -398,7 +397,7 @@ static void gl1_raster_font_render_message(
|
||||
if (!font->font_driver->get_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,
|
||||
pos_y, text_align);
|
||||
return;
|
||||
@ -413,7 +412,7 @@ static void gl1_raster_font_render_message(
|
||||
? (unsigned)(delim - msg) : (unsigned)strlen(msg);
|
||||
|
||||
/* Draw the line */
|
||||
gl1_raster_font_render_line(font,
|
||||
gl1_raster_font_render_line(font->gl, font,
|
||||
msg, msg_len, scale, color, pos_x,
|
||||
pos_y - (float)lines*line_height, text_align);
|
||||
|
||||
|
@ -282,7 +282,7 @@ static void gl2_raster_font_draw_vertices(gl2_raster_t *font,
|
||||
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,
|
||||
GLfloat scale, const GLfloat color[4], GLfloat pos_x,
|
||||
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_color[4 * 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;
|
||||
int x = roundf(pos_x * gl->vp.width);
|
||||
int y = roundf(pos_y * gl->vp.height);
|
||||
@ -302,8 +301,8 @@ static void gl2_raster_font_render_line(
|
||||
int delta_y = 0;
|
||||
float inv_tex_size_x = 1.0f / font->tex_width;
|
||||
float inv_tex_size_y = 1.0f / font->tex_height;
|
||||
float inv_win_width = 1.0f / font->gl->vp.width;
|
||||
float inv_win_height = 1.0f / font->gl->vp.height;
|
||||
float inv_win_width = 1.0f / gl->vp.width;
|
||||
float inv_win_height = 1.0f / gl->vp.height;
|
||||
|
||||
switch (text_align)
|
||||
{
|
||||
@ -379,7 +378,7 @@ static void gl2_raster_font_render_message(
|
||||
if (!font->font_driver->get_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,
|
||||
pos_y, text_align);
|
||||
return;
|
||||
@ -394,7 +393,7 @@ static void gl2_raster_font_render_message(
|
||||
? (unsigned)(delim - msg) : (unsigned)strlen(msg);
|
||||
|
||||
/* Draw the line */
|
||||
gl2_raster_font_render_line(font,
|
||||
gl2_raster_font_render_line(font->gl, font,
|
||||
msg, msg_len, scale, color, pos_x,
|
||||
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;
|
||||
bool full_screen = false ;
|
||||
gl2_raster_t *font = (gl2_raster_t*)data;
|
||||
unsigned width = font->gl->video_width;
|
||||
unsigned height = font->gl->video_height;
|
||||
unsigned width = font->gl->video_width;
|
||||
unsigned height = font->gl->video_height;
|
||||
|
||||
if (!font || string_is_empty(msg))
|
||||
return;
|
||||
|
@ -207,7 +207,7 @@ static void gl3_raster_font_draw_vertices(gl3_raster_t *font,
|
||||
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,
|
||||
GLfloat scale, const GLfloat color[4], GLfloat pos_x,
|
||||
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_vertex[2 * 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;
|
||||
int x = roundf(pos_x * gl->vp.width);
|
||||
int y = roundf(pos_y * gl->vp.height);
|
||||
@ -226,8 +225,8 @@ static void gl3_raster_font_render_line(
|
||||
int delta_y = 0;
|
||||
float inv_tex_size_x = 1.0f / font->atlas->width;
|
||||
float inv_tex_size_y = 1.0f / font->atlas->height;
|
||||
float inv_win_width = 1.0f / font->gl->vp.width;
|
||||
float inv_win_height = 1.0f / font->gl->vp.height;
|
||||
float inv_win_width = 1.0f / gl->vp.width;
|
||||
float inv_win_height = 1.0f / gl->vp.height;
|
||||
|
||||
switch (text_align)
|
||||
{
|
||||
@ -303,7 +302,7 @@ static void gl3_raster_font_render_message(
|
||||
if (!font->font_driver->get_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,
|
||||
pos_y, text_align);
|
||||
return;
|
||||
@ -318,7 +317,7 @@ static void gl3_raster_font_render_message(
|
||||
? (unsigned)(delim - msg) : (unsigned)strlen(msg);
|
||||
|
||||
/* Draw the line */
|
||||
gl3_raster_font_render_line(font,
|
||||
gl3_raster_font_render_line(font->gl, font,
|
||||
msg, msg_len, scale, color, pos_x,
|
||||
pos_y - (float)lines*line_height, text_align);
|
||||
|
||||
|
@ -148,10 +148,11 @@ static void ps2_font_render_line(
|
||||
int y = roundf((1.0f - pos_y) * height);
|
||||
int delta_x = 0;
|
||||
int delta_y = 0;
|
||||
int colorR, colorG, colorB, colorA;
|
||||
|
||||
if (!ps2)
|
||||
return;
|
||||
/* We need to >> 1, because GS_SETREG_RGBAQ expects 0x80 as max color */
|
||||
int colorA = (int)(((color & 0xFF000000) >> 24) >> 2);
|
||||
int colorB = (int)(((color & 0x00FF0000) >> 16) >> 1);
|
||||
int colorG = (int)(((color & 0x0000FF00) >> 8) >> 1);
|
||||
int colorR = (int)(((color & 0x000000FF) >> 0) >> 1);
|
||||
|
||||
/* Enable Alpha for font */
|
||||
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;
|
||||
}
|
||||
|
||||
/* 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, '?');
|
||||
|
||||
for (i = 0; i < msg_len; i++)
|
||||
@ -202,8 +198,7 @@ static void ps2_font_render_line(
|
||||
height = glyph->height;
|
||||
|
||||
/* The -0.5 is needed to achieve pixel perfect.
|
||||
* More info here (PS2 uses
|
||||
* same logic as Direct3D 9)
|
||||
* More info here (PS2 GSKit uses same logic as Direct3D9)
|
||||
* https://docs.microsoft.com/en-us/windows/win32/direct3d10/d3d10-graphics-programming-guide-resources-coordinates
|
||||
*/
|
||||
x1 = -0.5f + x + (off_x + delta_x) * scale;
|
||||
|
@ -75,7 +75,8 @@ static void rsx_font_free(void *data,
|
||||
if (font->font_driver && font->font_data)
|
||||
font->font_driver->free(font->font_data);
|
||||
|
||||
if (is_threaded) {
|
||||
if (is_threaded)
|
||||
{
|
||||
if (
|
||||
font->rsx &&
|
||||
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(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->fpo = font->rsx->fpo;
|
||||
font->fp_ucode = font->rsx->fp_ucode;
|
||||
font->vp_ucode = font->rsx->vp_ucode;
|
||||
font->fp_offset = font->rsx->fp_offset;
|
||||
font->vpo = font->rsx->vpo;
|
||||
font->fpo = font->rsx->fpo;
|
||||
font->fp_ucode = font->rsx->fp_ucode;
|
||||
font->vp_ucode = font->rsx->vp_ucode;
|
||||
font->fp_offset = font->rsx->fp_offset;
|
||||
|
||||
font->proj_matrix = font->rsx->proj_matrix;
|
||||
font->pos_index = font->rsx->pos_index;
|
||||
font->uv_index = font->rsx->uv_index;
|
||||
font->col_index = font->rsx->col_index;
|
||||
font->tex_unit = font->rsx->tex_unit;
|
||||
font->proj_matrix = font->rsx->proj_matrix;
|
||||
font->pos_index = font->rsx->pos_index;
|
||||
font->uv_index = font->rsx->uv_index;
|
||||
font->col_index = font->rsx->col_index;
|
||||
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].u, &font->uv_offset);
|
||||
rsxAddressToOffset(&font->vertices[0].r, &font->col_offset);
|
||||
|
||||
font->tex_width = font->atlas->width;
|
||||
font->tex_height = font->atlas->height;
|
||||
font->tex_width = font->atlas->width;
|
||||
font->tex_height = font->atlas->height;
|
||||
font->texture.data = (u8 *)rsxMemalign(128, (font->tex_height * font->tex_width));
|
||||
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;
|
||||
enum text_alignment text_align = TEXT_ALIGN_LEFT;
|
||||
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 height = font->rsx->height;
|
||||
settings_t *settings = config_get_ptr();
|
||||
|
@ -115,74 +115,70 @@ static void switch_font_render_line(
|
||||
float scale, const unsigned int color, float pos_x,
|
||||
float pos_y, unsigned text_align)
|
||||
{
|
||||
int delta_x = 0;
|
||||
int delta_y = 0;
|
||||
unsigned fb_width = sw->vp.full_width;
|
||||
unsigned fb_height = sw->vp.full_height;
|
||||
unsigned i;
|
||||
const struct font_glyph* glyph_q = NULL;
|
||||
int delta_x = 0;
|
||||
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;
|
||||
const struct font_glyph* glyph_q = NULL;
|
||||
int x = roundf(pos_x * fb_width);
|
||||
int y = roundf((1.0f - pos_y) * fb_height);
|
||||
case TEXT_ALIGN_RIGHT:
|
||||
x -= switch_font_get_message_width(font, msg, msg_len, scale);
|
||||
break;
|
||||
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:
|
||||
x -= switch_font_get_message_width(font, msg, msg_len, scale);
|
||||
break;
|
||||
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;
|
||||
uint8_t *row = &font->atlas->buffer[y * font->atlas->width];
|
||||
for (x = tex_x; x < tex_x + width; x++)
|
||||
{
|
||||
int x;
|
||||
uint8_t *row = &font->atlas->buffer[y * font->atlas->width];
|
||||
for (x = tex_x; x < tex_x + width; x++)
|
||||
{
|
||||
int x1, y1;
|
||||
if (!row[x])
|
||||
continue;
|
||||
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;
|
||||
}
|
||||
int x1, y1;
|
||||
if (!row[x])
|
||||
continue;
|
||||
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)
|
||||
return;
|
||||
if (!sw || !sw->out_buffer)
|
||||
return;
|
||||
|
||||
/* If font line metrics are not supported just draw as usual */
|
||||
if (!font->font_driver->get_line_metrics ||
|
||||
@ -205,13 +203,11 @@ static void switch_font_render_message(
|
||||
{
|
||||
int msg_len = strlen(msg);
|
||||
if (msg_len <= AVG_GLPYH_LIMIT)
|
||||
{
|
||||
if (sw)
|
||||
switch_font_render_line(sw, font, msg, strlen(msg),
|
||||
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;
|
||||
}
|
||||
|
||||
line_height = scale / line_metrics->height;
|
||||
|
||||
for (;;)
|
||||
|
@ -148,28 +148,27 @@ static int vulkan_get_message_width(void *data, const char *msg,
|
||||
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,
|
||||
float scale, const float color[4], float pos_x,
|
||||
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);
|
||||
int y = roundf((1.0f - pos_y) * vk->vp.height);
|
||||
int delta_x = 0;
|
||||
int delta_y = 0;
|
||||
float inv_tex_size_x = 1.0f / font->texture.width;
|
||||
float inv_tex_size_y = 1.0f / font->texture.height;
|
||||
float inv_win_width = 1.0f / font->vk->vp.width;
|
||||
float inv_win_height = 1.0f / font->vk->vp.height;
|
||||
const char* msg_end = msg + msg_len;
|
||||
int x = roundf(pos_x * vk->vp.width);
|
||||
int y = roundf((1.0f - pos_y) * vk->vp.height);
|
||||
int delta_x = 0;
|
||||
int delta_y = 0;
|
||||
float inv_tex_size_x = 1.0f / font->texture.width;
|
||||
float inv_tex_size_y = 1.0f / font->texture.height;
|
||||
float inv_win_width = 1.0f / font->vk->vp.width;
|
||||
float inv_win_height = 1.0f / font->vk->vp.height;
|
||||
|
||||
vk_color.r = color[0];
|
||||
vk_color.g = color[1];
|
||||
vk_color.b = color[2];
|
||||
vk_color.a = color[3];
|
||||
vk_color.r = color[0];
|
||||
vk_color.g = color[1];
|
||||
vk_color.b = color[2];
|
||||
vk_color.a = color[3];
|
||||
|
||||
switch (text_align)
|
||||
{
|
||||
@ -187,7 +186,7 @@ static void vulkan_font_render_line(
|
||||
{
|
||||
const struct font_glyph *glyph;
|
||||
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 ... */
|
||||
if (!(glyph =
|
||||
@ -249,7 +248,7 @@ static void vulkan_font_render_message(
|
||||
if (!font->font_driver->get_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);
|
||||
return;
|
||||
}
|
||||
@ -263,7 +262,7 @@ static void vulkan_font_render_message(
|
||||
? (unsigned)(delim - msg) : (unsigned)strlen(msg);
|
||||
|
||||
/* 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,
|
||||
text_align);
|
||||
|
||||
|
@ -154,16 +154,11 @@ static void wiiu_font_render_line(
|
||||
unsigned width, unsigned height, unsigned text_align)
|
||||
{
|
||||
unsigned i;
|
||||
int count, x, y;
|
||||
int count;
|
||||
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);
|
||||
int x = roundf(pos_x * width);
|
||||
int y = roundf((1.0 - pos_y) * height);
|
||||
|
||||
switch (text_align)
|
||||
{
|
||||
@ -257,14 +252,18 @@ static void wiiu_font_render_message(
|
||||
|
||||
if (!msg || !*msg)
|
||||
return;
|
||||
if (!wiiu)
|
||||
return;
|
||||
|
||||
/* If font line metrics are not supported just draw as usual */
|
||||
if (!font->font_driver->get_line_metrics ||
|
||||
!font->font_driver->get_line_metrics(font->font_data, &line_metrics))
|
||||
{
|
||||
wiiu_font_render_line(wiiu, font, msg, strlen(msg),
|
||||
scale, color, pos_x, pos_y,
|
||||
width, height, text_align);
|
||||
unsigned msg_len = strlen(msg);
|
||||
if (wiiu->vertex_cache.current + (msg_len * 4) <= wiiu->vertex_cache.size)
|
||||
wiiu_font_render_line(wiiu, font, msg, msg_len,
|
||||
scale, color, pos_x, pos_y,
|
||||
width, height, text_align);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -277,9 +276,10 @@ static void wiiu_font_render_message(
|
||||
(unsigned)(delim - msg) : strlen(msg);
|
||||
|
||||
/* Draw the line */
|
||||
wiiu_font_render_line(wiiu, font, msg, msg_len,
|
||||
scale, color, pos_x, pos_y - (float)lines * line_height,
|
||||
width, height, text_align);
|
||||
if (wiiu->vertex_cache.current + (msg_len * 4) <= wiiu->vertex_cache.size)
|
||||
wiiu_font_render_line(wiiu, font, msg, msg_len,
|
||||
scale, color, pos_x, pos_y - (float)lines * line_height,
|
||||
width, height, text_align);
|
||||
|
||||
if (!delim)
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user