Commit: a4fe823416f3907f56fb997fe1f244f9bbafc9e7
Author: Mike Erwin
Date:   Sat Oct 15 20:04:25 2016 -0400
Branches: blender2.8
https://developer.blender.org/rBa4fe823416f3907f56fb997fe1f244f9bbafc9e7

BLF/OpenGL: accurate vertex count for drawing

We still need to BeginAtMost instead of simple Begin, since some glyphs could 
be clipped & not drawn.

===================================================================

M       source/blender/blenfont/intern/blf_font.c
M       source/blender/blenfont/intern/blf_glyph.c

===================================================================

diff --git a/source/blender/blenfont/intern/blf_font.c 
b/source/blender/blenfont/intern/blf_font.c
index cac3b86..71350a0 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);
diff --git a/source/blender/blenfont/intern/blf_glyph.c 
b/source/blender/blenfont/intern/blf_glyph.c
index a74210c..746aa72 100644
--- a/source/blender/blenfont/intern/blf_glyph.c
+++ b/source/blender/blenfont/intern/blf_glyph.c
@@ -477,16 +477,15 @@ void blf_glyph_render(FontBLF *font, GlyphBLF *g, float 
x, float y)
                                    x + (float)font->shadow_x,
                                    y + (float)font->shadow_y);
 
-               switch (font->shadow) {
-                       case 3:
-                               blf_texture3_draw(font->shadow_col, g->uv, 
rect_ofs.xmin, rect_ofs.ymin, rect_ofs.xmax, rect_ofs.ymax);
-                               break;
-                       case 5:
-                               blf_texture5_draw(font->shadow_col, g->uv, 
rect_ofs.xmin, rect_ofs.ymin, rect_ofs.xmax, rect_ofs.ymax);
-                               break;
-                       default:
-                               immAttrib4fv(BLF_COLOR_ID, font->shadow_col);
-                               blf_texture_draw(g->uv, rect_ofs.xmin, 
rect_ofs.ymin, rect_ofs.xmax, rect_ofs.ymax);
+               if (font->shadow == 0) {
+                       immAttrib4fv(BLF_COLOR_ID, font->shadow_col);
+                       blf_texture_draw(g->uv, rect_ofs.xmin, rect_ofs.ymin, 
rect_ofs.xmax, rect_ofs.ymax);
+               }
+               else if (font->shadow <= 4) {
+                       blf_texture3_draw(font->shadow_col, g->uv, 
rect_ofs.xmin, rect_ofs.ymin, rect_ofs.xmax, rect_ofs.ymax);
+               }
+               else {
+                       blf_texture5_draw(font->shadow_col, g->uv, 
rect_ofs.xmin, rect_ofs.ymin, rect_ofs.xmax, rect_ofs.ymax);
                }
        }

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to