(Video drivers) Small cleanups/optimizations to render_line - hose

out some variables that are never subject to change
This commit is contained in:
libretroadmin 2023-06-03 20:56:19 +02:00
parent eb509b8d8e
commit 691c09ef09
10 changed files with 495 additions and 377 deletions

View File

@ -712,12 +712,14 @@ static int d3d11_font_get_message_width(void* data, const char* msg, size_t msg_
static void d3d11_font_render_line(
d3d11_video_t* d3d11,
d3d11_font_t* font,
const struct font_glyph* glyph_q,
const char* msg,
size_t msg_len,
float scale,
const unsigned int color,
float pos_x,
float pos_y,
int pre_x,
unsigned width,
unsigned height,
unsigned text_align)
@ -726,8 +728,7 @@ static void d3d11_font_render_line(
unsigned count;
D3D11_MAPPED_SUBRESOURCE mapped_vbo;
d3d11_sprite_t *v = NULL;
const struct font_glyph* glyph_q = NULL;
int x = roundf(pos_x * width);
int x = pre_x;
int y = roundf((1.0 - pos_y) * height);
if (d3d11->sprites.offset + msg_len > (unsigned)d3d11->sprites.capacity)
@ -747,7 +748,6 @@ static void d3d11_font_render_line(
d3d11->context->lpVtbl->Map(
d3d11->context, (D3D11Resource)d3d11->sprites.vbo, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &mapped_vbo);
v = (d3d11_sprite_t*)mapped_vbo.pData + d3d11->sprites.offset;
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
for (i = 0; i < msg_len; i++)
{
@ -837,6 +837,8 @@ static void d3d11_font_render_message(
float line_height;
struct font_line_metrics *line_metrics = NULL;
int lines = 0;
int x = roundf(pos_x * width);
const struct font_glyph* glyph_q = font->font_driver->get_glyph(font->font_data, '?');
font->font_driver->get_line_metrics(font->font_data, &line_metrics);
line_height = line_metrics->height * scale / height;
@ -849,8 +851,9 @@ static void d3d11_font_render_message(
/* Draw the line */
if (msg_len <= (unsigned)d3d11->sprites.capacity)
d3d11_font_render_line(d3d11,
font, msg, msg_len, scale, color, pos_x,
font, glyph_q, msg, msg_len, scale, color, pos_x,
pos_y - (float)lines * line_height,
x,
width, height, text_align);
if (!delim)

View File

@ -834,13 +834,16 @@ static int d3d12_font_get_message_width(void* data,
static void d3d12_font_render_line(
d3d12_video_t *d3d12,
D3D12GraphicsCommandList cmd,
d3d12_font_t* font,
const struct font_glyph* glyph_q,
const char* msg,
size_t msg_len,
float scale,
const unsigned int color,
float pos_x,
float pos_y,
int pre_x,
unsigned width,
unsigned height,
unsigned text_align)
@ -848,12 +851,10 @@ static void d3d12_font_render_line(
int i;
D3D12_RANGE range;
unsigned count;
const struct font_glyph* glyph_q = NULL;
void* mapped_vbo = NULL;
d3d12_sprite_t* v = NULL;
d3d12_sprite_t* vbo_start = NULL;
D3D12GraphicsCommandList cmd = d3d12->queue.cmd;
int x = roundf(pos_x * width);
int x = pre_x;
int y = roundf((1.0 - pos_y) * height);
if (d3d12->sprites.offset + msg_len > (unsigned)d3d12->sprites.capacity)
@ -876,7 +877,6 @@ static void d3d12_font_render_line(
v = vbo_start + d3d12->sprites.offset;
range.Begin = (uintptr_t)v - (uintptr_t)vbo_start;
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
for (i = 0; i < msg_len; i++)
{
@ -963,8 +963,11 @@ static void d3d12_font_render_message(
unsigned text_align)
{
float line_height;
D3D12GraphicsCommandList cmd = d3d12->queue.cmd;
struct font_line_metrics *line_metrics = NULL;
int lines = 0;
int x = roundf(pos_x * width);
const struct font_glyph* glyph_q = font->font_driver->get_glyph(font->font_data, '?');
font->font_driver->get_line_metrics(font->font_data, &line_metrics);
line_height = line_metrics->height * scale / height;
@ -975,9 +978,11 @@ static void d3d12_font_render_message(
/* Draw the line */
if (msg_len <= 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);
d3d12_font_render_line(d3d12, cmd,
font, glyph_q, msg, msg_len, scale, color, pos_x,
pos_y - (float)lines * line_height,
x,
width, height, text_align);
if (!delim)
break;

View File

@ -225,7 +225,7 @@ static void gdi_font_render_msg(
SIZE text_size = {0};
struct string_list msg_list = {0};
if (!font || string_is_empty(msg) || !font->gdi)
if (!font || string_is_empty(msg) || !gdi)
return;
if (params)
@ -267,7 +267,7 @@ static void gdi_font_render_msg(
msg_local = utf8_to_local_string_alloc(msg);
msg_len = strlen(msg_local);
GetTextExtentPoint32(font->gdi->memDC, msg_local, (int)msg_len, &text_size);
GetTextExtentPoint32(gdi->memDC, msg_local, (int)msg_len, &text_size);
switch (align)
{
@ -289,12 +289,12 @@ static void gdi_font_render_msg(
break;
}
new_y = height - (y * height * scale) - text_size.cy;
new_drop_y = height - (drop_y * height * scale) - text_size.cy;
new_y = height - (y * height * scale) - text_size.cy;
new_drop_y = height - (drop_y * height * scale) - text_size.cy;
font->gdi->bmp_old = (HBITMAP)SelectObject(font->gdi->memDC, font->gdi->bmp);
gdi->bmp_old = (HBITMAP)SelectObject(gdi->memDC, gdi->bmp);
SetBkMode(font->gdi->memDC, TRANSPARENT);
SetBkMode(gdi->memDC, TRANSPARENT);
string_list_initialize(&msg_list);
string_split_noalloc(&msg_list, msg_local, "\n");
@ -306,26 +306,26 @@ static void gdi_font_render_msg(
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));
SetTextColor(gdi->memDC, RGB(drop_red, drop_green, drop_blue));
for (i = 0; i < msg_list.size; i++)
TextOut(font->gdi->memDC, new_drop_x,
TextOut(gdi->memDC, new_drop_x,
new_drop_y + (text_size.cy * i),
msg_list.elems[i].data,
strlen(msg_list.elems[i].data));
}
SetTextColor(font->gdi->memDC, RGB(red, green, blue));
SetTextColor(gdi->memDC, RGB(red, green, blue));
for (i = 0; i < msg_list.size; i++)
TextOut(font->gdi->memDC, new_x, new_y + (text_size.cy * i),
TextOut(gdi->memDC, new_x, new_y + (text_size.cy * i),
msg_list.elems[i].data,
strlen(msg_list.elems[i].data));
string_list_deinitialize(&msg_list);
free(msg_local);
SelectObject(font->gdi->memDC, font->gdi->bmp_old);
SelectObject(gdi->memDC, gdi->bmp_old);
}
font_renderer_t gdi_font = {

View File

@ -464,7 +464,9 @@ static int gl1_raster_font_get_message_width(void *data, const char *msg,
return delta_x * scale;
}
static void gl1_raster_font_draw_vertices(gl1_raster_t *font,
static void gl1_raster_font_draw_vertices(
gl1_t *gl,
gl1_raster_t *font,
const video_coords_t *coords)
{
#ifdef VITA
@ -479,7 +481,7 @@ static void gl1_raster_font_draw_vertices(gl1_raster_t *font,
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadMatrixf(font->gl->mvp.data);
glLoadMatrixf(gl->mvp.data);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
@ -522,26 +524,32 @@ static void gl1_raster_font_draw_vertices(gl1_raster_t *font,
}
static void gl1_raster_font_render_line(gl1_t *gl,
gl1_raster_t *font, const char *msg, size_t msg_len,
GLfloat scale, const GLfloat color[4], GLfloat pos_x,
GLfloat pos_y, unsigned text_align)
gl1_raster_t *font,
const struct font_glyph* glyph_q,
const char *msg,
size_t msg_len,
GLfloat scale,
const GLfloat color[4],
GLfloat pos_x,
GLfloat pos_y,
int pre_x,
float inv_tex_size_x,
float inv_tex_size_y,
float inv_win_width,
float inv_win_height,
unsigned text_align)
{
int 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];
GLfloat font_lut_tex_coord[2 * 6 * MAX_MSG_LEN_CHUNK];
const char* msg_end = msg + msg_len;
int x = roundf(pos_x * gl->vp.width);
int x = pre_x;
int y = roundf(pos_y * gl->vp.height);
int delta_x = 0;
int delta_y = 0;
float inv_tex_size_x = 1.0f / font->tex_width;
float inv_tex_size_y = 1.0f / font->tex_height;
float inv_win_width = 1.0f / gl->vp.width;
float inv_win_height = 1.0f / gl->vp.height;
switch (text_align)
{
@ -553,8 +561,6 @@ static void gl1_raster_font_render_line(gl1_t *gl,
break;
}
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
while (msg < msg_end)
{
i = 0;
@ -600,20 +606,26 @@ static void gl1_raster_font_render_line(gl1_t *gl,
if (font->block)
video_coord_array_append(&font->block->carr, &coords, coords.vertices);
else
gl1_raster_font_draw_vertices(font, &coords);
gl1_raster_font_draw_vertices(gl, font, &coords);
}
}
static void gl1_raster_font_render_message(
static void gl1_raster_font_render_message(gl1_t *gl,
gl1_raster_t *font, const char *msg, GLfloat scale,
const GLfloat color[4], GLfloat pos_x, GLfloat pos_y,
float inv_tex_size_x,
float inv_tex_size_y,
float inv_win_width,
float inv_win_height,
unsigned text_align)
{
float line_height;
struct font_line_metrics *line_metrics = NULL;
int lines = 0;
const struct font_glyph* glyph_q = font->font_driver->get_glyph(font->font_data, '?');
int x = roundf(pos_x * gl->vp.width);
font->font_driver->get_line_metrics(font->font_data, &line_metrics);
line_height = line_metrics->height * scale / font->gl->vp.height;
line_height = line_metrics->height * scale / gl->vp.height;
for (;;)
{
@ -621,9 +633,15 @@ static void gl1_raster_font_render_message(
size_t msg_len = delim ? (delim - msg) : strlen(msg);
/* Draw the line */
gl1_raster_font_render_line(font->gl, font,
gl1_raster_font_render_line(gl, font, glyph_q,
msg, msg_len, scale, color, pos_x,
pos_y - (float)lines*line_height, text_align);
pos_y - (float)lines*line_height,
x,
inv_tex_size_x,
inv_tex_size_y,
inv_win_width,
inv_win_height,
text_align);
if (!delim)
break;
@ -634,14 +652,13 @@ static void gl1_raster_font_render_message(
}
static void gl1_raster_font_setup_viewport(
gl1_t *gl,
unsigned width, unsigned height,
gl1_raster_t *font, bool full_screen)
{
gl1_set_viewport(font->gl, width, height, full_screen, false);
gl1_set_viewport(gl, width, height, full_screen, false);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, font->tex);
}
@ -658,10 +675,9 @@ static void gl1_raster_font_render_msg(
enum text_alignment text_align = TEXT_ALIGN_LEFT;
bool full_screen = false;
gl1_raster_t *font = (gl1_raster_t*)data;
unsigned width = font->gl->video_width;
unsigned height = font->gl->video_height;
gl1_t *gl = (gl1_t*)userdata;
if (!font || string_is_empty(msg))
if (!font || string_is_empty(msg) || !gl)
return;
if (params)
@ -712,11 +728,17 @@ static void gl1_raster_font_render_msg(
if (font->block)
font->block->fullscreen = full_screen;
else
gl1_raster_font_setup_viewport(width, height, font, full_screen);
if (font->gl)
{
unsigned width = gl->video_width;
unsigned height = gl->video_height;
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 / gl->vp.width;
float inv_win_height = 1.0f / gl->vp.height;
if (!font->block)
gl1_raster_font_setup_viewport(gl, width, height, font, full_screen);
if (!string_is_empty(msg)
&& font->font_data && font->font_driver)
{
@ -729,23 +751,33 @@ static void gl1_raster_font_render_msg(
color_dark[2] = color[2] * drop_mod;
color_dark[3] = color[3] * drop_alpha;
gl1_raster_font_render_message(font, msg, scale, color_dark,
x + scale * drop_x / font->gl->vp.width, y +
scale * drop_y / font->gl->vp.height, text_align);
gl1_raster_font_render_message(gl, font, msg, scale, color_dark,
x + scale * drop_x / gl->vp.width,
y + scale * drop_y / gl->vp.height,
inv_tex_size_x,
inv_tex_size_y,
inv_win_width,
inv_win_height,
text_align);
}
gl1_raster_font_render_message(font, msg, scale, color,
x, y, text_align);
gl1_raster_font_render_message(gl, font, msg, scale, color,
x, y,
inv_tex_size_x,
inv_tex_size_y,
inv_win_width,
inv_win_height,
text_align);
}
if (!font->block)
{
/* Restore viewport */
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, font->gl->texture[font->gl->tex_index]);
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
glDisable(GL_BLEND);
gl1_set_viewport(font->gl, width, height, false, true);
gl1_set_viewport(gl, width, height, false, true);
}
}
}
@ -764,22 +796,20 @@ static void gl1_raster_font_flush_block(unsigned width, unsigned height,
{
gl1_raster_t *font = (gl1_raster_t*)data;
video_font_raster_block_t *block = font ? font->block : NULL;
gl1_t *gl = font ? font->gl : NULL;
if (!font || !block || !block->carr.coords.vertices)
if (!font || !block || !block->carr.coords.vertices || !gl)
return;
gl1_raster_font_setup_viewport(width, height, font, block->fullscreen);
gl1_raster_font_draw_vertices(font, (video_coords_t*)&block->carr.coords);
gl1_raster_font_setup_viewport(gl, width, height, font, block->fullscreen);
gl1_raster_font_draw_vertices(gl, font, (video_coords_t*)&block->carr.coords);
if (font->gl)
{
/* Restore viewport */
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, font->gl->texture[font->gl->tex_index]);
/* Restore viewport */
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
glDisable(GL_BLEND);
gl1_set_viewport(font->gl, width, height, block->fullscreen, true);
}
glDisable(GL_BLEND);
gl1_set_viewport(gl, width, height, block->fullscreen, true);
}
static void gl1_raster_font_bind_block(void *data, void *userdata)

View File

@ -680,9 +680,9 @@ static void gl2_raster_font_free(void *data,
if (is_threaded)
{
if (
font->gl &&
font->gl->ctx_driver &&
font->gl->ctx_driver->make_current)
font->gl
&& font->gl->ctx_driver
&& font->gl->ctx_driver->make_current)
font->gl->ctx_driver->make_current(true);
}
@ -757,9 +757,9 @@ static void *gl2_raster_font_init(void *data,
if (is_threaded)
if (
font->gl &&
font->gl->ctx_driver &&
font->gl->ctx_driver->make_current)
font->gl
&& font->gl->ctx_driver
&& font->gl->ctx_driver->make_current)
font->gl->ctx_driver->make_current(false);
glGenTextures(1, &font->tex);
@ -812,7 +812,8 @@ static int gl2_raster_font_get_message_width(void *data, const char *msg,
return delta_x * scale;
}
static void gl2_raster_font_draw_vertices(gl2_raster_t *font,
static void gl2_raster_font_draw_vertices(gl2_t *gl,
gl2_raster_t *font,
const video_coords_t *coords)
{
if (font->atlas->dirty)
@ -821,11 +822,11 @@ static void gl2_raster_font_draw_vertices(gl2_raster_t *font,
font->atlas->dirty = false;
}
if (font->gl && font->gl->shader)
if (gl->shader)
{
font->gl->shader->set_coords(font->gl->shader_data, coords);
font->gl->shader->set_mvp(font->gl->shader_data,
&font->gl->mvp_no_rot);
gl->shader->set_coords(gl->shader_data, coords);
gl->shader->set_mvp(gl->shader_data,
&gl->mvp_no_rot);
}
glDrawArrays(GL_TRIANGLES, 0, coords->vertices);
@ -908,13 +909,14 @@ static void gl2_raster_font_render_line(gl2_t *gl,
coords.lut_tex_coord = font_lut_tex_coord;
if (font->block)
video_coord_array_append(&font->block->carr, &coords, coords.vertices);
video_coord_array_append(&font->block->carr,
&coords, coords.vertices);
else
gl2_raster_font_draw_vertices(font, &coords);
gl2_raster_font_draw_vertices(gl, font, &coords);
}
}
static void gl2_raster_font_render_message(
static void gl2_raster_font_render_message(gl2_t *gl,
gl2_raster_t *font, const char *msg, GLfloat scale,
const GLfloat color[4], GLfloat pos_x, GLfloat pos_y,
unsigned text_align)
@ -923,7 +925,7 @@ static void gl2_raster_font_render_message(
struct font_line_metrics *line_metrics = NULL;
int lines = 0;
font->font_driver->get_line_metrics(font->font_data, &line_metrics);
line_height = line_metrics->height * scale / font->gl->vp.height;
line_height = line_metrics->height * scale / gl->vp.height;
for (;;)
{
@ -931,7 +933,7 @@ static void gl2_raster_font_render_message(
size_t msg_len = delim ? (delim - msg) : strlen(msg);
/* Draw the line */
gl2_raster_font_render_line(font->gl, font,
gl2_raster_font_render_line(gl, font,
msg, msg_len, scale, color, pos_x,
pos_y - (float)lines*line_height, text_align);
@ -944,11 +946,12 @@ static void gl2_raster_font_render_message(
}
static void gl2_raster_font_setup_viewport(
gl2_t *gl,
gl2_raster_t *font,
unsigned width, unsigned height,
bool full_screen)
{
gl2_set_viewport(font->gl, width, height, full_screen, true);
gl2_set_viewport(gl, width, height, full_screen, true);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -956,9 +959,9 @@ static void gl2_raster_font_setup_viewport(
glBindTexture(GL_TEXTURE_2D, font->tex);
if (font->gl && font->gl->shader && font->gl->shader->use)
font->gl->shader->use(font->gl,
font->gl->shader_data, VIDEO_SHADER_STOCK_BLEND, true);
if (gl->shader && gl->shader->use)
gl->shader->use(gl,
gl->shader_data, VIDEO_SHADER_STOCK_BLEND, true);
}
static void gl2_raster_font_render_msg(
@ -973,10 +976,11 @@ 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;
gl2_t *gl = (gl2_t*)userdata;
unsigned width = gl->video_width;
unsigned height = gl->video_height;
if (!font || string_is_empty(msg))
if (!font || string_is_empty(msg) || !gl)
return;
if (params)
@ -1028,39 +1032,36 @@ static void gl2_raster_font_render_msg(
if (font->block)
font->block->fullscreen = full_screen;
else
gl2_raster_font_setup_viewport(font, width, height, full_screen);
gl2_raster_font_setup_viewport(gl, font, width, height, full_screen);
if (font->gl)
if ( !string_is_empty(msg)
&& font->font_data
&& font->font_driver)
{
if ( !string_is_empty(msg)
&& font->font_data
&& font->font_driver)
if (drop_x || drop_y)
{
if (drop_x || drop_y)
{
GLfloat color_dark[4];
color_dark[0] = color[0] * drop_mod;
color_dark[1] = color[1] * drop_mod;
color_dark[2] = color[2] * drop_mod;
color_dark[3] = color[3] * drop_alpha;
GLfloat color_dark[4];
color_dark[0] = color[0] * drop_mod;
color_dark[1] = color[1] * drop_mod;
color_dark[2] = color[2] * drop_mod;
color_dark[3] = color[3] * drop_alpha;
gl2_raster_font_render_message(font, msg, scale, color_dark,
x + scale * drop_x / font->gl->vp.width, y +
scale * drop_y / font->gl->vp.height, text_align);
}
gl2_raster_font_render_message(font, msg, scale, color,
x, y, text_align);
gl2_raster_font_render_message(gl, font, msg, scale, color_dark,
x + scale * drop_x / gl->vp.width,
y + scale * drop_y / gl->vp.height,
text_align);
}
if (!font->block)
{
/* Restore viewport */
glBindTexture(GL_TEXTURE_2D,
font->gl->texture[font->gl->tex_index]);
glDisable(GL_BLEND);
gl2_set_viewport(font->gl, width, height, false, true);
}
gl2_raster_font_render_message(gl, font, msg, scale, color,
x, y, text_align);
}
if (!font->block)
{
/* Restore viewport */
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
glDisable(GL_BLEND);
gl2_set_viewport(gl, width, height, false, true);
}
}
@ -1078,21 +1079,19 @@ static void gl2_raster_font_flush_block(unsigned width, unsigned height,
{
gl2_raster_t *font = (gl2_raster_t*)data;
video_font_raster_block_t *block = font ? font->block : NULL;
gl2_t *gl = font ? font->gl : NULL;
if (!font || !block || !block->carr.coords.vertices)
if (!font || !block || !block->carr.coords.vertices || !gl)
return;
gl2_raster_font_setup_viewport(font, width, height, block->fullscreen);
gl2_raster_font_draw_vertices(font, (video_coords_t*)&block->carr.coords);
gl2_raster_font_setup_viewport(gl, font, width, height, block->fullscreen);
gl2_raster_font_draw_vertices(gl, font, (video_coords_t*)&block->carr.coords);
if (font->gl)
{
/* Restore viewport */
glBindTexture(GL_TEXTURE_2D, font->gl->texture[font->gl->tex_index]);
/* Restore viewport */
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
glDisable(GL_BLEND);
gl2_set_viewport(font->gl, width, height, block->fullscreen, true);
}
glDisable(GL_BLEND);
gl2_set_viewport(gl, width, height, block->fullscreen, true);
}
static void gl2_raster_font_bind_block(void *data, void *userdata)

View File

@ -526,7 +526,8 @@ static int gl3_raster_font_get_message_width(void *data, const char *msg,
return delta_x * scale;
}
static void gl3_raster_font_draw_vertices(gl3_raster_t *font,
static void gl3_raster_font_draw_vertices(gl3_t *gl,
gl3_raster_t *font,
const video_coords_t *coords)
{
if (font->atlas->dirty)
@ -538,26 +539,28 @@ static void gl3_raster_font_draw_vertices(gl3_raster_t *font,
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, font->tex);
if ( font->gl &&
font->gl->pipelines.font_loc.flat_ubo_vertex >= 0)
glUniform4fv(font->gl->pipelines.font_loc.flat_ubo_vertex,
4, font->gl->mvp_no_rot.data);
if (gl->pipelines.font_loc.flat_ubo_vertex >= 0)
glUniform4fv(gl->pipelines.font_loc.flat_ubo_vertex,
4, gl->mvp_no_rot.data);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
gl3_bind_scratch_vbo(font->gl, coords->vertex, 2 * sizeof(float) * coords->vertices);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), (void *)(uintptr_t)0);
gl3_bind_scratch_vbo(font->gl, coords->tex_coord, 2 * sizeof(float) * coords->vertices);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), (void *)(uintptr_t)0);
gl3_bind_scratch_vbo(font->gl, coords->color, 4 * sizeof(float) * coords->vertices);
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void *)(uintptr_t)0);
gl3_bind_scratch_vbo(gl, coords->vertex,
2 * sizeof(float) * coords->vertices);
glVertexAttribPointer(0, 2,
GL_FLOAT, GL_FALSE, 2 * sizeof(float), (void *)(uintptr_t)0);
gl3_bind_scratch_vbo(gl, coords->tex_coord,
2 * sizeof(float) * coords->vertices);
glVertexAttribPointer(1, 2,
GL_FLOAT, GL_FALSE, 2 * sizeof(float), (void *)(uintptr_t)0);
gl3_bind_scratch_vbo(gl, coords->color,
4 * sizeof(float) * coords->vertices);
glVertexAttribPointer(2, 4,
GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void *)(uintptr_t)0);
glDrawArrays(GL_TRIANGLES, 0, coords->vertices);
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glDisableVertexAttribArray(2);
@ -565,25 +568,29 @@ static void gl3_raster_font_draw_vertices(gl3_raster_t *font,
}
static void gl3_raster_font_render_line(gl3_t *gl,
gl3_raster_t *font, const char *msg, size_t msg_len,
GLfloat scale, const GLfloat color[4], GLfloat pos_x,
GLfloat pos_y, unsigned text_align)
gl3_raster_t *font,
const struct font_glyph* glyph_q,
const char *msg, size_t msg_len,
GLfloat scale, const GLfloat color[4],
GLfloat pos_x,
GLfloat pos_y,
int pre_x,
float inv_tex_size_x,
float inv_tex_size_y,
float inv_win_width,
float inv_win_height,
unsigned text_align)
{
int 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];
GLfloat font_vertex [2 * 6 * MAX_MSG_LEN_CHUNK];
GLfloat font_color [4 * 6 * MAX_MSG_LEN_CHUNK];
const char* msg_end = msg + msg_len;
int x = roundf(pos_x * gl->vp.width);
int x = pre_x;
int y = roundf(pos_y * gl->vp.height);
int delta_x = 0;
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 / gl->vp.width;
float inv_win_height = 1.0f / gl->vp.height;
switch (text_align)
{
@ -595,8 +602,6 @@ static void gl3_raster_font_render_line(gl3_t *gl,
break;
}
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
while (msg < msg_end)
{
i = 0;
@ -604,7 +609,7 @@ static void gl3_raster_font_render_line(gl3_t *gl,
{
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 = font->font_driver->get_glyph(
@ -640,13 +645,15 @@ static void gl3_raster_font_render_line(gl3_t *gl,
coords.lut_tex_coord = font_tex_coords;
if (font->block)
video_coord_array_append(&font->block->carr, &coords, coords.vertices);
video_coord_array_append(&font->block->carr,
&coords, coords.vertices);
else
gl3_raster_font_draw_vertices(font, &coords);
gl3_raster_font_draw_vertices(gl, font, &coords);
}
}
static void gl3_raster_font_render_message(
gl3_t *gl,
gl3_raster_t *font, const char *msg, GLfloat scale,
const GLfloat color[4], GLfloat pos_x, GLfloat pos_y,
unsigned text_align)
@ -654,8 +661,14 @@ static void gl3_raster_font_render_message(
float line_height;
struct font_line_metrics *line_metrics = NULL;
int lines = 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 / gl->vp.width;
float inv_win_height = 1.0f / gl->vp.height;
int x = roundf(pos_x * gl->vp.width);
const struct font_glyph* glyph_q = font->font_driver->get_glyph(font->font_data, '?');
font->font_driver->get_line_metrics(font->font_data, &line_metrics);
line_height = line_metrics->height * scale / font->gl->vp.height;
line_height = line_metrics->height * scale / gl->vp.height;
for (;;)
{
@ -663,9 +676,17 @@ static void gl3_raster_font_render_message(
size_t msg_len = delim ? (delim - msg) : strlen(msg);
/* Draw the line */
gl3_raster_font_render_line(font->gl, font,
msg, msg_len, scale, color, pos_x,
pos_y - (float)lines*line_height, text_align);
gl3_raster_font_render_line(gl, font,
glyph_q,
msg, msg_len, scale, color,
pos_x,
pos_y - (float)lines * line_height,
x,
inv_tex_size_x,
inv_tex_size_y,
inv_win_width,
inv_win_height,
text_align);
if (!delim)
break;
@ -676,16 +697,16 @@ static void gl3_raster_font_render_message(
}
static void gl3_raster_font_setup_viewport(
gl3_t *gl,
unsigned width, unsigned height,
gl3_raster_t *font, bool full_screen)
{
gl3_set_viewport(font->gl, width, height, full_screen, false);
gl3_set_viewport(gl, width, height, full_screen, false);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendEquation(GL_FUNC_ADD);
if (font->gl)
glUseProgram(font->gl->pipelines.font);
glUseProgram(gl->pipelines.font);
}
static void gl3_raster_font_render_msg(
@ -698,10 +719,11 @@ static void gl3_raster_font_render_msg(
int drop_x, drop_y;
GLfloat x, y, scale, drop_mod, drop_alpha;
enum text_alignment text_align = TEXT_ALIGN_LEFT;
bool full_screen = false ;
bool full_screen = false;
gl3_raster_t *font = (gl3_raster_t*)data;
unsigned width = font->gl->video_width;
unsigned height = font->gl->video_height;
gl3_t *gl = (gl3_t*)userdata;
unsigned width = gl->video_width;
unsigned height = gl->video_height;
settings_t *settings = config_get_ptr();
float video_msg_pos_x = settings->floats.video_msg_pos_x;
float video_msg_pos_y = settings->floats.video_msg_pos_y;
@ -709,7 +731,7 @@ static void gl3_raster_font_render_msg(
float video_msg_color_g = settings->floats.video_msg_color_g;
float video_msg_color_b = settings->floats.video_msg_color_b;
if (!font || string_is_empty(msg))
if (!font || string_is_empty(msg) || !gl)
return;
if (params)
@ -755,36 +777,33 @@ static void gl3_raster_font_render_msg(
if (font->block)
font->block->fullscreen = full_screen;
else
gl3_raster_font_setup_viewport(width, height, font, full_screen);
gl3_raster_font_setup_viewport(gl, width, height, font, full_screen);
if (font->gl)
if (!string_is_empty(msg)
&& font->font_data && font->font_driver)
{
if (!string_is_empty(msg)
&& font->font_data && font->font_driver)
if (drop_x || drop_y)
{
if (drop_x || drop_y)
{
GLfloat color_dark[4];
GLfloat color_dark[4];
color_dark[0] = color[0] * drop_mod;
color_dark[1] = color[1] * drop_mod;
color_dark[2] = color[2] * drop_mod;
color_dark[3] = color[3] * drop_alpha;
color_dark[0] = color[0] * drop_mod;
color_dark[1] = color[1] * drop_mod;
color_dark[2] = color[2] * drop_mod;
color_dark[3] = color[3] * drop_alpha;
gl3_raster_font_render_message(font, msg, scale, color_dark,
x + scale * drop_x / font->gl->vp.width, y +
scale * drop_y / font->gl->vp.height, text_align);
}
gl3_raster_font_render_message(font, msg, scale, color,
x, y, text_align);
gl3_raster_font_render_message(gl, font, msg, scale, color_dark,
x + scale * drop_x / gl->vp.width,
y + scale * drop_y / gl->vp.height, text_align);
}
if (!font->block)
{
glDisable(GL_BLEND);
gl3_set_viewport(font->gl, width, height, false, true);
}
gl3_raster_font_render_message(gl, font, msg, scale, color,
x, y, text_align);
}
if (!font->block)
{
glDisable(GL_BLEND);
gl3_set_viewport(gl, width, height, false, true);
}
}
@ -802,18 +821,16 @@ static void gl3_raster_font_flush_block(unsigned width, unsigned height,
{
gl3_raster_t *font = (gl3_raster_t*)data;
video_font_raster_block_t *block = font ? font->block : NULL;
gl3_t *gl = font ? font->gl : NULL;
if (!font || !block || !block->carr.coords.vertices)
if (!font || !block || !block->carr.coords.vertices || !gl)
return;
gl3_raster_font_setup_viewport(width, height, font, block->fullscreen);
gl3_raster_font_draw_vertices(font, (video_coords_t*)&block->carr.coords);
gl3_raster_font_setup_viewport(gl, width, height, font, block->fullscreen);
gl3_raster_font_draw_vertices(gl, font, (video_coords_t*)&block->carr.coords);
if (font->gl)
{
glDisable(GL_BLEND);
gl3_set_viewport(font->gl, width, height, block->fullscreen, true);
}
glDisable(GL_BLEND);
gl3_set_viewport(gl, width, height, block->fullscreen, true);
}
static void gl3_raster_font_bind_block(void *data, void *userdata)
@ -1061,12 +1078,18 @@ static void gl3_render_overlay(gl3_t *gl,
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
gl3_bind_scratch_vbo(gl, gl->overlay_vertex_coord, 8 * sizeof(float) * gl->overlays);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), (void *)(uintptr_t)0);
gl3_bind_scratch_vbo(gl, gl->overlay_tex_coord, 8 * sizeof(float) * gl->overlays);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), (void *)(uintptr_t)0);
gl3_bind_scratch_vbo(gl, gl->overlay_color_coord, 16 * sizeof(float) * gl->overlays);
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void *)(uintptr_t)0);
gl3_bind_scratch_vbo(gl, gl->overlay_vertex_coord,
8 * sizeof(float) * gl->overlays);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE,
2 * sizeof(float), (void *)(uintptr_t)0);
gl3_bind_scratch_vbo(gl, gl->overlay_tex_coord,
8 * sizeof(float) * gl->overlays);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE,
2 * sizeof(float), (void *)(uintptr_t)0);
gl3_bind_scratch_vbo(gl, gl->overlay_color_coord,
16 * sizeof(float) * gl->overlays);
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE,
4 * sizeof(float), (void *)(uintptr_t)0);
for (i = 0; i < gl->overlays; i++)
{

View File

@ -488,16 +488,19 @@ static int gx2_font_get_message_width(void* data, const char* msg,
static void gx2_font_render_line(
wiiu_video_t *wiiu,
gx2_font_t* font, const char* msg, size_t msg_len,
gx2_font_t* font,
const struct font_glyph* glyph_q,
const char* msg, size_t msg_len,
float scale, const unsigned int color, float pos_x,
float pos_y,
unsigned width, unsigned height, unsigned text_align)
unsigned width, unsigned height,
int pre_x,
unsigned text_align)
{
int i;
int count;
sprite_vertex_t *v;
const struct font_glyph* glyph_q = NULL;
int x = roundf(pos_x * width);
int x = pre_x;
int y = roundf((1.0 - pos_y) * height);
switch (text_align)
@ -512,7 +515,6 @@ static void gx2_font_render_line(
}
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++)
{
@ -558,8 +560,10 @@ static void gx2_font_render_line(
if (font->atlas->dirty)
{
for (i = 0; (i < font->atlas->height) && (i < font->texture.surface.height); i++)
memcpy(font->texture.surface.image + (i * font->texture.surface.pitch),
font->atlas->buffer + (i * font->atlas->width), font->atlas->width);
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,
@ -575,7 +579,9 @@ static void gx2_font_render_line(
GX2DrawEx(GX2_PRIMITIVE_MODE_POINTS, count, wiiu->vertex_cache.current, 1);
GX2SetVertexUniformBlock(sprite_shader.vs.uniformBlocks[1].offset, sprite_shader.vs.uniformBlocks[1].size, wiiu->ubo_tex);
GX2SetVertexUniformBlock(sprite_shader.vs.uniformBlocks[1].offset,
sprite_shader.vs.uniformBlocks[1].size,
wiiu->ubo_tex);
wiiu->vertex_cache.current = v - wiiu->vertex_cache.v;
}
@ -589,6 +595,8 @@ static void gx2_font_render_message(
float line_height;
struct font_line_metrics *line_metrics = NULL;
int lines = 0;
const struct font_glyph* glyph_q = font->font_driver->get_glyph(font->font_data, '?');
int x = roundf(pos_x * width);
font->font_driver->get_line_metrics(font->font_data, &line_metrics);
line_height = line_metrics->height * scale / wiiu->vp.height;
@ -598,10 +606,19 @@ static void gx2_font_render_message(
size_t msg_len = delim ? (delim - msg) : strlen(msg);
/* Draw the line */
if (wiiu->vertex_cache.current + (msg_len * 4) <= wiiu->vertex_cache.size)
gx2_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))
gx2_font_render_line(wiiu,
font,
glyph_q,
msg, msg_len,
scale, color,
pos_x,
pos_y - (float)lines * line_height,
width,
height,
x,
text_align);
if (!delim)
break;

View File

@ -364,7 +364,7 @@ static void rsx_font_free(void *data,
free(font);
}
static bool rsx_font_upload_atlas(rsx_font_t *font)
static bool rsx_font_upload_atlas(rsx_t *rsx, rsx_font_t *font)
{
u8 *texbuffer = (u8 *)font->texture.data;
const u8 *atlas_data = (u8 *)font->atlas->buffer;
@ -394,14 +394,14 @@ static bool rsx_font_upload_atlas(rsx_font_t *font)
font->texture.min_filter = GCM_TEXTURE_LINEAR;
font->texture.mag_filter = GCM_TEXTURE_LINEAR;
rsxInvalidateTextureCache(font->rsx->context, GCM_INVALIDATE_TEXTURE);
rsxLoadTexture(font->rsx->context, font->tex_unit->index, &font->texture.tex);
rsxTextureControl(font->rsx->context, font->tex_unit->index,
rsxInvalidateTextureCache(rsx->context, GCM_INVALIDATE_TEXTURE);
rsxLoadTexture(rsx->context, font->tex_unit->index, &font->texture.tex);
rsxTextureControl(rsx->context, font->tex_unit->index,
GCM_TRUE, 0 << 8, 12 << 8, GCM_TEXTURE_MAX_ANISO_1);
rsxTextureFilter(font->rsx->context, font->tex_unit->index,
rsxTextureFilter(rsx->context, font->tex_unit->index,
0, font->texture.min_filter,
font->texture.mag_filter, GCM_TEXTURE_CONVOLUTION_QUINCUNX);
rsxTextureWrapMode(font->rsx->context, font->tex_unit->index,
rsxTextureWrapMode(rsx->context, font->tex_unit->index,
font->texture.wrap_s, font->texture.wrap_t,
GCM_TEXTURE_CLAMP_TO_EDGE, 0, GCM_TEXTURE_ZFUNC_LESS, 0);
@ -460,7 +460,7 @@ static void *rsx_font_init(void *data,
if (!font->texture.data)
goto error;
if (!rsx_font_upload_atlas(font))
if (!rsx_font_upload_atlas(font->rsx, font))
goto error;
font->atlas->dirty = false;
@ -506,7 +506,9 @@ static int rsx_font_get_message_width(void *data, const char *msg,
return delta_x * scale;
}
static void rsx_font_draw_vertices(rsx_font_t *font,
static void rsx_font_draw_vertices(
rsx_t *rsx,
rsx_font_t *font,
const video_coords_t *coords)
{
int i, end_vert_idx;
@ -517,20 +519,20 @@ static void rsx_font_draw_vertices(rsx_font_t *font,
if (font->atlas->dirty)
{
rsx_font_upload_atlas(font);
rsx_font_upload_atlas(rsx, font);
font->atlas->dirty = false;
}
end_vert_idx = font->rsx->font_vert_idx + coords->vertices;
end_vert_idx = rsx->font_vert_idx + coords->vertices;
if (end_vert_idx > RSX_MAX_FONT_VERTICES)
{
font->rsx->font_vert_idx = 0;
end_vert_idx = font->rsx->font_vert_idx + coords->vertices;
rsx->font_vert_idx = 0;
end_vert_idx = rsx->font_vert_idx + coords->vertices;
}
vertices = &font->vertices[font->rsx->font_vert_idx];
vertices = &font->vertices[rsx->font_vert_idx];
for (i = font->rsx->font_vert_idx; i < end_vert_idx; i++)
for (i = rsx->font_vert_idx; i < end_vert_idx; i++)
{
vertices[i].x = *vertex++;
vertices[i].y = *vertex++;
@ -542,52 +544,57 @@ static void rsx_font_draw_vertices(rsx_font_t *font,
vertices[i].a = *color++;
}
rsxAddressToOffset(&vertices[font->rsx->font_vert_idx].x, &font->pos_offset);
rsxAddressToOffset(&vertices[font->rsx->font_vert_idx].u, &font->uv_offset);
rsxAddressToOffset(&vertices[font->rsx->font_vert_idx].r, &font->col_offset);
font->rsx->font_vert_idx = end_vert_idx;
rsxAddressToOffset(&vertices[rsx->font_vert_idx].x, &font->pos_offset);
rsxAddressToOffset(&vertices[rsx->font_vert_idx].u, &font->uv_offset);
rsxAddressToOffset(&vertices[rsx->font_vert_idx].r, &font->col_offset);
rsx->font_vert_idx = end_vert_idx;
rsxBindVertexArrayAttrib(font->rsx->context, font->pos_index->index, 0,
rsxBindVertexArrayAttrib(rsx->context, font->pos_index->index, 0,
font->pos_offset, sizeof(rsx_vertex_t), 2,
GCM_VERTEX_DATA_TYPE_F32, GCM_LOCATION_RSX);
rsxBindVertexArrayAttrib(font->rsx->context, font->uv_index->index, 0,
rsxBindVertexArrayAttrib(rsx->context, font->uv_index->index, 0,
font->uv_offset, sizeof(rsx_vertex_t), 2,
GCM_VERTEX_DATA_TYPE_F32, GCM_LOCATION_RSX);
rsxBindVertexArrayAttrib(font->rsx->context, font->col_index->index, 0,
rsxBindVertexArrayAttrib(rsx->context, font->col_index->index, 0,
font->col_offset, sizeof(rsx_vertex_t), 4,
GCM_VERTEX_DATA_TYPE_F32, GCM_LOCATION_RSX);
rsxLoadVertexProgram(font->rsx->context, font->vpo, font->vp_ucode);
rsxSetVertexProgramParameter(font->rsx->context, font->vpo,
font->proj_matrix, (float *)&font->rsx->mvp_no_rot);
rsxLoadFragmentProgramLocation(font->rsx->context, font->fpo,
rsxLoadVertexProgram(rsx->context, font->vpo, font->vp_ucode);
rsxSetVertexProgramParameter(rsx->context, font->vpo,
font->proj_matrix, (float *)&rsx->mvp_no_rot);
rsxLoadFragmentProgramLocation(rsx->context, font->fpo,
font->fp_offset, GCM_LOCATION_RSX);
rsxClearSurface(font->rsx->context, GCM_CLEAR_Z);
rsxDrawVertexArray(font->rsx->context, GCM_TYPE_TRIANGLES, 0, coords->vertices);
rsxClearSurface(rsx->context, GCM_CLEAR_Z);
rsxDrawVertexArray(rsx->context, GCM_TYPE_TRIANGLES, 0, coords->vertices);
}
static void rsx_font_render_line(
rsx_font_t *font, const char *msg, size_t msg_len,
float scale, const float color[4], float pos_x,
float pos_y,unsigned text_align)
static void rsx_font_render_line(rsx_t *rsx,
rsx_font_t *font,
const struct font_glyph* glyph_q,
const char *msg,
size_t msg_len,
float scale,
const float color[4],
float pos_x,
float pos_y,
int pre_x,
float inv_tex_size_x,
float inv_tex_size_y,
float inv_win_width,
float inv_win_height,
unsigned text_align)
{
int 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];
rsx_t *rsx = font->rsx;
const char* msg_end = msg + msg_len;
int x = roundf(pos_x * rsx->vp.width);
int x = pre_x;
int y = roundf(pos_y * rsx->vp.height);
int delta_x = 0;
int delta_y = 0;
float inv_tex_size_x = 1.0f / font->tex_width;
float inv_tex_size_y = 1.0f / font->tex_height;
float inv_win_width = 1.0f / font->rsx->vp.width;
float inv_win_height = 1.0f / font->rsx->vp.height;
switch (text_align)
{
@ -599,8 +606,6 @@ static void rsx_font_render_line(
break;
}
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
while (msg < msg_end)
{
i = 0;
@ -644,22 +649,29 @@ static void rsx_font_render_line(
coords.lut_tex_coord = font_tex_coords;
if (font->block)
video_coord_array_append(&font->block->carr, &coords, coords.vertices);
video_coord_array_append(
&font->block->carr, &coords, coords.vertices);
else
rsx_font_draw_vertices(font, &coords);
rsx_font_draw_vertices(rsx, font, &coords);
}
}
static void rsx_font_render_message(
static void rsx_font_render_message(rsx_t *rsx,
rsx_font_t *font, const char *msg, float scale,
const float color[4], float pos_x, float pos_y,
unsigned text_align)
{
struct font_line_metrics *line_metrics = NULL;
int lines = 0;
float line_height;
struct font_line_metrics *line_metrics = NULL;
const struct font_glyph* glyph_q = font->font_driver->get_glyph(font->font_data, '?');
int lines = 0;
int x = roundf(pos_x * rsx->vp.width);
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 / rsx->vp.width;
float inv_win_height = 1.0f / rsx->vp.height;
font->font_driver->get_line_metrics(font->font_data, &line_metrics);
line_height = line_metrics->height * scale / font->rsx->vp.height;
line_height = line_metrics->height * scale / rsx->vp.height;
for (;;)
{
@ -667,9 +679,15 @@ static void rsx_font_render_message(
size_t msg_len = delim ? (delim - msg) : strlen(msg);
/* Draw the line */
rsx_font_render_line(font,
rsx_font_render_line(rsx, font, glyph_q,
msg, msg_len, scale, color, pos_x,
pos_y - (float)lines*line_height, text_align);
pos_y - (float)lines*line_height,
x,
inv_tex_size_x,
inv_tex_size_y,
inv_win_width,
inv_win_height,
text_align);
if (!delim)
break;
@ -680,22 +698,20 @@ static void rsx_font_render_message(
}
static void rsx_font_setup_viewport(
rsx_t *rsx,
unsigned width, unsigned height,
rsx_font_t *font, bool full_screen)
{
rsx_set_viewport(font->rsx, width, height, full_screen, false);
rsx_set_viewport(rsx, width, height, full_screen, false);
if (font->rsx)
{
rsxSetBlendEnable(font->rsx->context, GCM_TRUE);
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(rsx->context, GCM_TRUE);
rsxSetBlendFunc(rsx->context, GCM_SRC_ALPHA,
GCM_ONE_MINUS_SRC_ALPHA, GCM_SRC_ALPHA, GCM_ONE_MINUS_SRC_ALPHA);
rsxSetBlendEquation(rsx->context, GCM_FUNC_ADD, GCM_FUNC_ADD);
rsxLoadTexture(font->rsx->context, font->tex_unit->index, &font->texture.tex);
rsxTextureControl(font->rsx->context, font->tex_unit->index,
GCM_TRUE, 0 << 8, 12 << 8, GCM_TEXTURE_MAX_ANISO_1);
}
rsxLoadTexture(rsx->context, font->tex_unit->index, &font->texture.tex);
rsxTextureControl(rsx->context, font->tex_unit->index,
GCM_TRUE, 0 << 8, 12 << 8, GCM_TEXTURE_MAX_ANISO_1);
}
static void rsx_font_render_msg(
@ -706,22 +722,25 @@ static void rsx_font_render_msg(
{
float color[4];
int drop_x, drop_y;
unsigned width, height;
float x, y, scale, drop_mod, drop_alpha;
enum text_alignment text_align = TEXT_ALIGN_LEFT;
bool full_screen = false ;
bool full_screen = false;
rsx_font_t *font = (rsx_font_t*)data;
unsigned width = font->rsx->width;
unsigned height = font->rsx->height;
settings_t *settings = config_get_ptr();
float video_msg_pos_x = settings->floats.video_msg_pos_x;
float video_msg_pos_y = settings->floats.video_msg_pos_y;
float video_msg_color_r = settings->floats.video_msg_color_r;
float video_msg_color_g = settings->floats.video_msg_color_g;
float video_msg_color_b = settings->floats.video_msg_color_b;
rsx_t *rsx = (rsx_t*)userdata;
if (!font || string_is_empty(msg))
if (!font || string_is_empty(msg) || !rsx)
return;
width = rsx->width;
height = rsx->height;
if (params)
{
x = params->x;
@ -767,39 +786,37 @@ static void rsx_font_render_msg(
else
rsx_font_setup_viewport(width, height, font, full_screen);
if (font->rsx)
if ( !string_is_empty(msg)
&& font->font_data
&& font->font_driver)
{
if (!string_is_empty(msg)
&& font->font_data && font->font_driver)
if (drop_x || drop_y)
{
if (drop_x || drop_y)
{
float color_dark[4];
float color_dark[4];
color_dark[0] = color[0] * drop_mod;
color_dark[1] = color[1] * drop_mod;
color_dark[2] = color[2] * drop_mod;
color_dark[3] = color[3] * drop_alpha;
color_dark[0] = color[0] * drop_mod;
color_dark[1] = color[1] * drop_mod;
color_dark[2] = color[2] * drop_mod;
color_dark[3] = color[3] * drop_alpha;
rsx_font_render_message(font, msg, scale, color_dark,
x + scale * drop_x / font->rsx->vp.width, y +
scale * drop_y / font->rsx->vp.height, text_align);
}
rsx_font_render_message(font, msg, scale, color,
x, y, text_align);
rsx_font_render_message(rsx, font, msg, scale, color_dark,
x + scale * drop_x / rsx->vp.width, y +
scale * drop_y / rsx->vp.height, text_align);
}
if (!font->block)
{
/* Restore viewport */
rsxTextureControl(font->rsx->context, font->tex_unit->index,
GCM_TRUE, 0 << 8, 12 << 8, GCM_TEXTURE_MAX_ANISO_1);
rsxSetBlendEnable(font->rsx->context, GCM_FALSE);
rsx_set_viewport(font->rsx, width, height, false, true);
}
font->rsx->font_vert_idx = 0;
rsx_font_render_message(rsx, font, msg, scale, color,
x, y, text_align);
}
if (!font->block)
{
/* Restore viewport */
rsxTextureControl(rsx->context, font->tex_unit->index,
GCM_TRUE, 0 << 8, 12 << 8, GCM_TEXTURE_MAX_ANISO_1);
rsxSetBlendEnable(rsx->context, GCM_FALSE);
rsx_set_viewport(rsx, width, height, false, true);
}
rsx->font_vert_idx = 0;
}
static const struct font_glyph *rsx_font_get_glyph(
@ -816,21 +833,19 @@ static void rsx_font_flush_block(unsigned width, unsigned height,
{
rsx_font_t *font = (rsx_font_t*)data;
video_font_raster_block_t *block = font ? font->block : NULL;
rsx_t *rsx = font ? font->rsx : NULL;
if (!font || !block || !block->carr.coords.vertices)
if (!font || !block || !block->carr.coords.vertices || !rsx)
return;
rsx_font_setup_viewport(width, height, font, block->fullscreen);
rsx_font_draw_vertices(font, (video_coords_t*)&block->carr.coords);
rsx_font_setup_viewport(rsx, width, height, font, block->fullscreen);
rsx_font_draw_vertices(rsx, font, (video_coords_t*)&block->carr.coords);
if (font->rsx)
{
/* Restore viewport */
rsxTextureControl(font->rsx->context, font->tex_unit->index,
GCM_TRUE, 0 << 8, 12 << 8, GCM_TEXTURE_MAX_ANISO_1);
rsxSetBlendEnable(font->rsx->context, GCM_FALSE);
rsx_set_viewport(font->rsx, width, height, block->fullscreen, true);
}
/* Restore viewport */
rsxTextureControl(rsx->context, font->tex_unit->index,
GCM_TRUE, 0 << 8, 12 << 8, GCM_TEXTURE_MAX_ANISO_1);
rsxSetBlendEnable(rsx->context, GCM_FALSE);
rsx_set_viewport(rsx, width, height, block->fullscreen, true);
font->rsx->font_vert_idx = 0;
}
@ -1078,7 +1093,7 @@ static const gfx_ctx_driver_t* rsx_get_context(rsx_t* rsx)
bool video_shared_context = settings->bools.video_shared_context;
enum gfx_ctx_api api = GFX_CTX_RSX_API;
rsx->shared_context_use = video_shared_context && hwr->context_type != RETRO_HW_CONTEXT_NONE;
rsx->shared_context_use = (video_shared_context && (hwr->context_type != RETRO_HW_CONTEXT_NONE));
if ((runloop_get_flags() & RUNLOOP_FLAG_CORE_SET_SHARED_CONTEXT)
&& (hwr->context_type != RETRO_HW_CONTEXT_NONE))
@ -2176,11 +2191,15 @@ static bool rsx_frame(void* data, const void* frame,
if (frame && width && height)
{
gcm->tex_index = ((gcm->tex_index + 1) % RSX_MAX_TEXTURES);
rsx_load_texture_data(gcm, &gcm->texture[gcm->tex_index], frame, width, height, pitch, gcm->rgb32, false,
gcm->smooth ? TEXTURE_FILTER_LINEAR : TEXTURE_FILTER_NEAREST);
/* TODO/FIXME - pipeline ID being used here is RSX_SHADER_MENU, shouldn't
* this be RSX_SHADER_STOCK_BLEND instead? */
gcm->tex_index = ((gcm->tex_index + 1) % RSX_MAX_TEXTURES);
rsx_load_texture_data(gcm,
&gcm->texture[gcm->tex_index],
frame, width, height, pitch, gcm->rgb32, false,
gcm->smooth
? TEXTURE_FILTER_LINEAR
: TEXTURE_FILTER_NEAREST);
/* TODO/FIXME - pipeline ID being used here is RSX_SHADER_MENU,
* shouldn't this be RSX_SHADER_STOCK_BLEND instead? */
rsx_set_texture(gcm, &gcm->texture[gcm->tex_index]);
rsx_draw_vertices(gcm);
draw = true;
@ -2192,7 +2211,8 @@ static bool rsx_frame(void* data, const void* frame,
menu_driver_frame(menu_is_alive, video_info);
if (gcm->menu_texture.data)
{
/* TODO/FIXME - pipeline ID being used here is RSX_SHADER_STOCK_BLEND, shouldn't
/* TODO/FIXME - pipeline ID being used here
* is RSX_SHADER_STOCK_BLEND, shouldn't
* this be RSX_SHADER_MENU instead? */
rsx_set_menu_texture(gcm, &gcm->menu_texture);
rsx_draw_menu_vertices(gcm);

View File

@ -304,14 +304,19 @@ static int vita2d_font_get_message_width(void *data, const char *msg,
}
static void vita2d_font_render_line(
vita_font_t *font, const char *msg, size_t msg_len,
vita_video_t *vita,
vita_font_t *font,
const struct font_glyph* glyph_q,
const char *msg, size_t msg_len,
float scale, const unsigned int color, float pos_x,
float pos_y,
unsigned width, unsigned height, unsigned text_align)
unsigned width,
unsigned height,
int pre_x,
unsigned text_align)
{
int i;
const struct font_glyph* glyph_q = NULL;
int x = roundf(pos_x * width);
int x = pre_x;
int y = roundf((1.0f - pos_y) * height);
int delta_x = 0;
int delta_y = 0;
@ -326,8 +331,6 @@ 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 j, k;
@ -380,6 +383,7 @@ static void vita2d_font_render_line(
}
static void vita2d_font_render_message(
vita_video_t *vita,
vita_font_t *font, const char *msg, float scale,
const unsigned int color, float pos_x, float pos_y,
unsigned width, unsigned height, unsigned text_align)
@ -387,8 +391,10 @@ static void vita2d_font_render_message(
float line_height;
struct font_line_metrics *line_metrics = NULL;
int lines = 0;
int x = roundf(pos_x * width);
const struct font_glyph* glyph_q = font->font_driver->get_glyph(font->font_data, '?');
font->font_driver->get_line_metrics(font->font_data, &line_metrics);
line_height = line_metrics->height * scale / font->vita->vp.height;
line_height = line_metrics->height * scale / vita->vp.height;
for (;;)
{
@ -396,9 +402,9 @@ static void vita2d_font_render_message(
size_t msg_len = (delim) ? (delim - msg) : strlen(msg);
/* Draw the line */
vita2d_font_render_line(font, msg, msg_len,
vita2d_font_render_line(vita, font, glyph_q, msg, msg_len,
scale, color, pos_x, pos_y - (float)lines * line_height,
width, height, text_align);
width, height, x, text_align);
if (!delim)
break;
@ -470,7 +476,7 @@ static void vita2d_font_render_msg(
drop_alpha = 1.0f;
}
vita2d_set_viewport_wrapper(font->vita, width, height, full_screen, false);
vita2d_set_viewport_wrapper(vita, width, height, full_screen, false);
if (drop_x || drop_y)
{
@ -480,12 +486,12 @@ static void vita2d_font_render_msg(
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,
vita2d_font_render_message(vita, font, msg, scale, color_dark,
x + scale * drop_x / width, y +
scale * drop_y / height, width, height, text_align);
}
vita2d_font_render_message(font, msg, scale,
vita2d_font_render_message(vita, font, msg, scale,
color, x, y, width, height, text_align);
}

View File

@ -1402,21 +1402,26 @@ static int vulkan_get_message_width(void *data, const char *msg,
}
static void vulkan_font_render_line(vk_t *vk,
vulkan_raster_t *font, const char *msg, size_t msg_len,
float scale, const float color[4], float pos_x,
float pos_y, unsigned text_align)
vulkan_raster_t *font,
const struct font_glyph* glyph_q,
const char *msg, size_t msg_len,
float scale,
const float color[4],
float pos_x,
float pos_y,
int pre_x,
float inv_tex_size_x,
float inv_tex_size_y,
float inv_win_width,
float inv_win_height,
unsigned text_align)
{
struct vk_color vk_color;
const struct font_glyph* glyph_q = NULL;
const char* msg_end = msg + msg_len;
int x = roundf(pos_x * vk->vp.width);
int x = pre_x;
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];
@ -1433,8 +1438,6 @@ static void vulkan_font_render_line(vk_t *vk,
break;
}
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
while (msg < msg_end)
{
const struct font_glyph *glyph;
@ -1475,7 +1478,8 @@ static void vulkan_font_render_line(vk_t *vk,
float _tex_height = height * inv_tex_size_y;
const struct vk_color *_color = &vk_color;
VULKAN_WRITE_QUAD_VBO(pv, _x, _y, _width, _height, _tex_x, _tex_y, _tex_width, _tex_height, _color);
VULKAN_WRITE_QUAD_VBO(pv, _x, _y, _width, _height,
_tex_x, _tex_y, _tex_width, _tex_height, _color);
}
font->vertices += 6;
@ -1485,16 +1489,22 @@ static void vulkan_font_render_line(vk_t *vk,
}
}
static void vulkan_font_render_message(
static void vulkan_font_render_message(vk_t *vk,
vulkan_raster_t *font, const char *msg, float scale,
const float color[4], float pos_x, float pos_y,
unsigned text_align)
{
float line_height;
struct font_line_metrics *line_metrics = NULL;
const struct font_glyph* glyph_q = font->font_driver->get_glyph(font->font_data, '?');
int x = roundf(pos_x * vk->vp.width);
int lines = 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 / vk->vp.width;
float inv_win_height = 1.0f / vk->vp.height;
font->font_driver->get_line_metrics(font->font_data, &line_metrics);
line_height = line_metrics->height * scale / font->vk->vp.height;
line_height = line_metrics->height * scale / vk->vp.height;
for (;;)
{
@ -1502,8 +1512,15 @@ static void vulkan_font_render_message(
size_t msg_len = delim ? (delim - msg) : strlen(msg);
/* Draw the line */
vulkan_font_render_line(font->vk, font, msg, msg_len,
scale, color, pos_x, pos_y - (float)lines * line_height,
vulkan_font_render_line(vk, font, glyph_q, msg, msg_len,
scale, color,
pos_x,
pos_y - (float)lines * line_height,
x,
inv_tex_size_x,
inv_tex_size_y,
inv_win_width,
inv_win_height,
text_align);
if (!delim)
@ -1514,15 +1531,15 @@ static void vulkan_font_render_message(
}
}
static void vulkan_font_flush(vulkan_raster_t *font)
static void vulkan_font_flush(vk_t *vk, vulkan_raster_t *font)
{
struct vk_draw_triangles call;
call.pipeline = font->vk->pipelines.font;
call.pipeline = vk->pipelines.font;
call.texture = &font->texture_optimal;
call.sampler = font->vk->samplers.mipmap_linear;
call.uniform = &font->vk->mvp;
call.uniform_size = sizeof(font->vk->mvp);
call.sampler = vk->samplers.mipmap_linear;
call.uniform = &vk->mvp;
call.uniform_size = sizeof(vk->mvp);
call.vbo = &font->range;
call.vertices = font->vertices;
@ -1537,10 +1554,10 @@ static void vulkan_font_flush(vulkan_raster_t *font)
cmd_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
cmd_info.pNext = NULL;
cmd_info.commandPool = font->vk->staging_pool;
cmd_info.commandPool = vk->staging_pool;
cmd_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
cmd_info.commandBufferCount = 1;
vkAllocateCommandBuffers(font->vk->context->device, &cmd_info, &staging);
vkAllocateCommandBuffers(vk->context->device, &cmd_info, &staging);
begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
begin_info.pNext = NULL;
@ -1548,18 +1565,18 @@ static void vulkan_font_flush(vulkan_raster_t *font)
begin_info.pInheritanceInfo = NULL;
vkBeginCommandBuffer(staging, &begin_info);
VULKAN_SYNC_TEXTURE_TO_GPU_COND_OBJ(font->vk, font->texture);
VULKAN_SYNC_TEXTURE_TO_GPU_COND_OBJ(vk, font->texture);
dynamic_tex = &font->texture_optimal;
staging_tex = &font->texture;
vulkan_copy_staging_to_dynamic(font->vk, staging,
vulkan_copy_staging_to_dynamic(vk, staging,
dynamic_tex, staging_tex);
vkEndCommandBuffer(staging);
#ifdef HAVE_THREADS
slock_lock(font->vk->context->queue_lock);
slock_lock(vk->context->queue_lock);
#endif
submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
@ -1571,22 +1588,22 @@ static void vulkan_font_flush(vulkan_raster_t *font)
submit_info.pCommandBuffers = &staging;
submit_info.signalSemaphoreCount = 0;
submit_info.pSignalSemaphores = NULL;
vkQueueSubmit(font->vk->context->queue,
vkQueueSubmit(vk->context->queue,
1, &submit_info, VK_NULL_HANDLE);
vkQueueWaitIdle(font->vk->context->queue);
vkQueueWaitIdle(vk->context->queue);
#ifdef HAVE_THREADS
slock_unlock(font->vk->context->queue_lock);
slock_unlock(vk->context->queue_lock);
#endif
vkFreeCommandBuffers(font->vk->context->device,
font->vk->staging_pool, 1, &staging);
vkFreeCommandBuffers(vk->context->device,
vk->staging_pool, 1, &staging);
font->needs_update = false;
}
vulkan_draw_triangles(font->vk, &call);
vulkan_draw_triangles(vk, &call);
}
static void vulkan_font_render_msg(
@ -1602,7 +1619,6 @@ static void vulkan_font_render_msg(
unsigned width, height;
enum text_alignment text_align;
float x, y, scale, drop_mod, drop_alpha;
vk_t *vk = NULL;
vulkan_raster_t *font = (vulkan_raster_t*)data;
settings_t *settings = config_get_ptr();
float video_msg_pos_x = settings->floats.video_msg_pos_x;
@ -1610,12 +1626,11 @@ static void vulkan_font_render_msg(
float video_msg_color_r = settings->floats.video_msg_color_r;
float video_msg_color_g = settings->floats.video_msg_color_g;
float video_msg_color_b = settings->floats.video_msg_color_b;
vk_t *vk = (vk_t*)userdata;
if (!font || !msg || !*msg || !font->vk)
if (!font || !msg || !*msg || !vk)
return;
vk = font->vk;
width = vk->video_width;
height = vk->video_height;
@ -1658,13 +1673,13 @@ static void vulkan_font_render_msg(
color[3] = 1.0f;
}
vulkan_set_viewport(font->vk, width, height, full_screen, false);
vulkan_set_viewport(vk, width, height, full_screen, false);
max_glyphs = strlen(msg);
if (drop_x || drop_y)
max_glyphs *= 2;
if (!vulkan_buffer_chain_alloc(font->vk->context, &font->vk->chain->vbo,
if (!vulkan_buffer_chain_alloc(vk->context, &vk->chain->vbo,
6 * sizeof(struct vk_vertex) * max_glyphs, &font->range))
return;
@ -1679,14 +1694,14 @@ static void vulkan_font_render_msg(
color_dark[2] = color[2] * drop_mod;
color_dark[3] = color[3] * drop_alpha;
vulkan_font_render_message(font, msg, scale, color_dark,
vulkan_font_render_message(vk, font, msg, scale, color_dark,
x + scale * drop_x / vk->vp.width, y +
scale * drop_y / vk->vp.height, text_align);
}
vulkan_font_render_message(font, msg, scale,
vulkan_font_render_message(vk, font, msg, scale,
color, x, y, text_align);
vulkan_font_flush(font);
vulkan_font_flush(vk, font);
}
static const struct font_glyph *vulkan_font_get_glyph(