Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Erwin <significant.bit@gmail.com>2016-10-16 03:04:25 +0300
committerMike Erwin <significant.bit@gmail.com>2016-10-16 03:04:25 +0300
commita4fe823416f3907f56fb997fe1f244f9bbafc9e7 (patch)
treec40f77ff1ad95718f7e18be24a588c2b7699464d /source/blender/blenfont/intern/blf_font.c
parenta8dc3f4596ef5aed70ceeaa7e3029cb782a0f0ef (diff)
BLF/OpenGL: accurate vertex count for drawing
We still need to BeginAtMost instead of simple Begin, since some glyphs could be clipped & not drawn.
Diffstat (limited to 'source/blender/blenfont/intern/blf_font.c')
-rw-r--r--source/blender/blenfont/intern/blf_font.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index cac3b86b249..71350a0f8dc 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -177,16 +177,18 @@ static void blf_font_ensure_ascii_table(FontBLF *font)
static unsigned verts_needed(const FontBLF *font, const char *str, size_t len)
{
unsigned length = (unsigned)((len == INT_MAX) ? strlen(str) : len);
- return length * 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, length * quad_ct * 4);
-#endif
+ unsigned quad_ct = 1;
+
+ if (font->flags & BLF_SHADOW) {
+ if (font->shadow == 0)
+ quad_ct += 1;
+ if (font->shadow <= 4)
+ quad_ct += 9; /* 3x3 kernel */
+ else
+ quad_ct += 25; /* 5x5 kernel */
+ }
+
+ return length * quad_ct * 4;
}
static void blf_font_draw_ex(
@@ -205,6 +207,7 @@ static void blf_font_draw_ex(
blf_font_ensure_ascii_table(font);
immBeginAtMost(GL_QUADS, verts_needed(font, str, len));
+ /* at most because some glyphs might be clipped & not drawn */
while ((i < len) && str[i]) {
BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);