Commit: 0b5ebb3265b155658d441135e152f32ba11c001d
Author: Clément Foucault
Date:   Sun Apr 8 01:14:43 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB0b5ebb3265b155658d441135e152f32ba11c001d

BLF: Fix problem with bound texture.

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.

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

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

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

diff --git a/source/blender/blenfont/intern/blf_font.c 
b/source/blender/blenfont/intern/blf_font.c
index cc7eb336b21..301f06e22b5 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -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 */
diff --git a/source/blender/blenfont/intern/blf_glyph.c 
b/source/blender/blenfont/intern/blf_glyph.c
index ad7e482f8e0..21c11d96b07 100644
--- a/source/blender/blenfont/intern/blf_glyph.c
+++ b/source/blender/blenfont/intern/blf_glyph.c
@@ -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,
diff --git a/source/blender/blenfont/intern/blf_internal_types.h 
b/source/blender/blenfont/intern/blf_internal_types.h
index af2dc8a66e9..1d70980d33d 100644
--- a/source/blender/blenfont/intern/blf_internal_types.h
+++ b/source/blender/blenfont/intern/blf_internal_types.h
@@ -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;

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

Reply via email to