Skip to content

Commit d0de0af

Browse files
committed
(D3D10/Vulkan) font_render_message function - when drop shadows
are enabled for the message to be rendered, glyph_q lookup would be queried twice. Redesign it so that the glyph_q lookup gets hoisted outside of this function and passed as an argument instead. Saves us one call
1 parent 29c4551 commit d0de0af

2 files changed

Lines changed: 22 additions & 12 deletions

File tree

gfx/drivers/d3d10.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,7 @@ static void d3d10_font_render_line(
10641064
static void d3d10_font_render_message(
10651065
d3d10_video_t *d3d10,
10661066
d3d10_font_t* font,
1067+
const struct font_glyph* glyph_q,
10671068
const char* msg,
10681069
float scale,
10691070
const unsigned int color,
@@ -1076,8 +1077,6 @@ static void d3d10_font_render_message(
10761077
float line_height;
10771078
struct font_line_metrics *line_metrics = NULL;
10781079
int lines = 0;
1079-
const struct font_glyph* glyph_q =
1080-
font->font_driver->get_glyph(font->font_data, '?');
10811080
int x = roundf(pos_x * width);
10821081
font->font_driver->get_line_metrics(font->font_data, &line_metrics);
10831082
line_height = line_metrics->height * scale / height;
@@ -1110,6 +1109,7 @@ static void d3d10_font_render_msg(
11101109
{
11111110
int drop_x, drop_y;
11121111
enum text_alignment text_align;
1112+
const struct font_glyph* glyph_q;
11131113
unsigned color, r, g, b, alpha;
11141114
float x, y, scale, drop_mod, drop_alpha;
11151115
d3d10_font_t *font = (d3d10_font_t*)data;
@@ -1165,6 +1165,9 @@ static void d3d10_font_render_msg(
11651165
drop_alpha = 1.0f;
11661166
}
11671167

1168+
glyph_q = (font->font_driver)
1169+
? font->font_driver->get_glyph(font->font_data, '?') : NULL;
1170+
11681171
if (drop_x || drop_y)
11691172
{
11701173
unsigned r_dark = r * drop_mod;
@@ -1174,15 +1177,14 @@ static void d3d10_font_render_msg(
11741177
unsigned color_dark = DXGI_COLOR_RGBA(r_dark, g_dark, b_dark, alpha_dark);
11751178

11761179
d3d10_font_render_message(d3d10,
1177-
font, msg, scale, color_dark,
1180+
font, glyph_q, msg, scale, color_dark,
11781181
x + scale * drop_x / width,
11791182
y + scale * drop_y / height,
11801183
width, height, text_align);
11811184
}
11821185

1183-
d3d10_font_render_message(d3d10, font, msg, scale,
1184-
color, x, y,
1185-
width, height, text_align);
1186+
d3d10_font_render_message(d3d10, font, glyph_q,
1187+
msg, scale, color, x, y, width, height, text_align);
11861188
}
11871189

11881190
static const struct font_glyph* d3d10_font_get_glyph(void *data,

gfx/drivers/vulkan.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2194,14 +2194,19 @@ static void vulkan_font_render_line(vk_t *vk,
21942194
}
21952195
}
21962196

2197-
static void vulkan_font_render_message(vk_t *vk,
2198-
vulkan_raster_t *font, const char *msg, float scale,
2199-
const float color[4], float pos_x, float pos_y,
2197+
static void vulkan_font_render_message(
2198+
vk_t *vk,
2199+
vulkan_raster_t *font,
2200+
const struct font_glyph* glyph_q,
2201+
const char *msg,
2202+
float scale,
2203+
const float color[4],
2204+
float pos_x,
2205+
float pos_y,
22002206
unsigned text_align)
22012207
{
22022208
float line_height;
22032209
struct font_line_metrics *line_metrics = NULL;
2204-
const struct font_glyph* glyph_q = font->font_driver->get_glyph(font->font_data, '?');
22052210
int x = roundf(pos_x * vk->vp.width);
22062211
int lines = 0;
22072212
float inv_tex_size_x = 1.0f / font->texture.width;
@@ -2356,6 +2361,7 @@ static void vulkan_font_render_msg(
23562361
size_t max_glyphs;
23572362
unsigned width, height;
23582363
enum text_alignment text_align;
2364+
const struct font_glyph* glyph_q;
23592365
float x, y, scale, drop_mod, drop_alpha;
23602366
vulkan_raster_t *font = (vulkan_raster_t*)data;
23612367
settings_t *settings = config_get_ptr();
@@ -2423,6 +2429,8 @@ static void vulkan_font_render_msg(
24232429

24242430
font->vertices = 0;
24252431
font->pv = (struct vk_vertex*)font->range.data;
2432+
glyph_q = (font->font_driver)
2433+
? font->font_driver->get_glyph(font->font_data, '?') : NULL;
24262434

24272435
if (drop_x || drop_y)
24282436
{
@@ -2432,12 +2440,12 @@ static void vulkan_font_render_msg(
24322440
color_dark[2] = color[2] * drop_mod;
24332441
color_dark[3] = color[3] * drop_alpha;
24342442

2435-
vulkan_font_render_message(vk, font, msg, scale, color_dark,
2443+
vulkan_font_render_message(vk, font, glyph_q, msg, scale, color_dark,
24362444
x + scale * drop_x / vk->vp.width, y +
24372445
scale * drop_y / vk->vp.height, text_align);
24382446
}
24392447

2440-
vulkan_font_render_message(vk, font, msg, scale,
2448+
vulkan_font_render_message(vk, font, glyph_q, msg, scale,
24412449
color, x, y, text_align);
24422450
vulkan_font_flush(vk, font);
24432451
}

0 commit comments

Comments
 (0)