BLF: Fix problem with bound texture.
authorClément Foucault <foucault.clem@gmail.com>
Sat, 7 Apr 2018 23:14:43 +0000 (01:14 +0200)
committerClément Foucault <foucault.clem@gmail.com>
Sat, 7 Apr 2018 23:14:43 +0000 (01:14 +0200)
Previous code was assuming that the glyph texture would remain bound to
GL_TEXTURE0 until the cache would be drawn. This is not always the case,
so better save the texture and rebind it before drawing.

source/blender/blenfont/intern/blf_font.c
source/blender/blenfont/intern/blf_glyph.c
source/blender/blenfont/intern/blf_internal_types.h

index cc7eb336b21a8af18f39375837529aeebf6078a2..301f06e22b5b755a0107094cc5185943f38a1819 100644 (file)
@@ -189,9 +189,9 @@ void blf_batch_draw(void)
        /* We need to flush widget base first to ensure correct ordering. */
        UI_widgetbase_draw_cache_flush();
 
-       BLI_assert(g_batch.font->tex_bind_state != 0); /* must still be valid */
+       BLI_assert(g_batch.tex_bind_state != 0); /* must still be valid */
        glActiveTexture(GL_TEXTURE0);
-       glBindTexture(GL_TEXTURE_2D, g_batch.font->tex_bind_state);
+       glBindTexture(GL_TEXTURE_2D, g_batch.tex_bind_state);
 
        GWN_vertbuf_vertex_count_set(g_batch.verts, g_batch.glyph_len);
        GWN_vertbuf_use(g_batch.verts); /* send data */
index ad7e482f8e09acafc2cd913e3ab64393a9653c6c..21c11d96b07329d1c61b4dd720a6babac1b3a63a 100644 (file)
@@ -520,6 +520,8 @@ void blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
                glBindTexture(GL_TEXTURE_2D, (font->tex_bind_state = g->tex));
        }
 
+       g_batch.tex_bind_state = g->tex;
+
        if (font->flags & BLF_SHADOW) {
                rctf rect_ofs;
                blf_glyph_calc_rect(&rect_ofs, g,
index af2dc8a66e9232a2ac38b7844853b56ea6c90d6f..1d70980d33d5eeda2c9b688aa70c8676ce291e27 100644 (file)
@@ -45,6 +45,7 @@ typedef struct BatchBLF{
        float ofs[2];    /* copy of font->pos */
        float mat[4][4]; /* previous call modelmatrix. */
        bool enabled, active, simple_shader;
+       unsigned int tex_bind_state;
 } BatchBLF;
 
 extern BatchBLF g_batch;