OpenGL: draw text with fewer draw calls

Was one draw call per glyph,  now one per line.

Still room for improvement here.
This commit is contained in:
Mike Erwin 2016-10-14 14:40:53 -04:00
parent dd350c0b37
commit 34dc660a76
2 changed files with 23 additions and 12 deletions

View File

@ -58,6 +58,8 @@
#include "BIF_gl.h"
#include "BLF_api.h"
#include "GPU_immediate.h"
#include "blf_internal_types.h"
#include "blf_internal.h"
@ -187,6 +189,17 @@ static void blf_font_draw_ex(
blf_font_ensure_ascii_table(font);
immBeginAtMost(GL_QUADS, (unsigned)len * 40);
/* (5 shadow + 5 blur) * 4 verts per quad
* TODO: determine exact count of quads, somthing like this: */
#if 0
unsigned quad_ct = 1 + (unsigned)font->blur;
if (font->flags & BLF_SHADOW)
quad_ct += (unsigned)font->shadow;
immBegin(GL_QUADS, (unsigned)len * quad_ct * 4);
#endif
while ((i < len) && str[i]) {
BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
@ -204,6 +217,8 @@ static void blf_font_draw_ex(
g_prev = g;
}
immEnd();
if (r_info) {
r_info->lines = 1;
r_info->width = pen_x;
@ -229,6 +244,8 @@ static void blf_font_draw_ascii_ex(
blf_font_ensure_ascii_table(font);
immBeginAtMost(GL_QUADS, (unsigned)len * 40);
while ((c = *(str++)) && len--) {
BLI_assert(c < 128);
if ((g = glyph_ascii_table[c]) == NULL)
@ -243,6 +260,8 @@ static void blf_font_draw_ascii_ex(
g_prev = g;
}
immEnd();
if (r_info) {
r_info->lines = 1;
r_info->width = pen_x;
@ -265,6 +284,8 @@ int blf_font_draw_mono(FontBLF *font, const char *str, size_t len, int cwidth)
blf_font_ensure_ascii_table(font);
immBeginAtMost(GL_QUADS, (unsigned)len * 40);
while ((i < len) && str[i]) {
BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
@ -284,6 +305,8 @@ int blf_font_draw_mono(FontBLF *font, const char *str, size_t len, int cwidth)
pen_x += cwidth * col;
}
immEnd();
return columns;
}

View File

@ -469,16 +469,6 @@ void blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
glBindTexture(GL_TEXTURE_2D, (font->tex_bind_state = g->tex));
}
#if 0 /* determine exact count of quads */
unsigned quad_ct = 1 + (unsigned)font->blur;
if (font->flags & BLF_SHADOW)
quad_ct += (unsigned)font->shadow;
immBegin(GL_QUADS, quad_ct * 4);
#else
immBeginAtMost(GL_QUADS, 40); /* (5 shadow + 5 blur) * 4 verts per quad */
#endif
/* TODO: blur & shadow in shader, single quad per glyph */
if (font->flags & BLF_SHADOW) {
@ -511,6 +501,4 @@ void blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
immAttrib4fv(BLF_COLOR_ID, font->orig_col);
blf_texture_draw(g->uv, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
}
immEnd();
}