[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53533] trunk/blender/source/blender/ blenfont/intern/blf_glyph.c: fix for bug rendering text at small sizes, padding was incorrectly being applied to the characters y offset causing out of bounds pixels to be requested from glTexSubImage2D ().

Campbell Barton ideasman42 at gmail.com
Thu Jan 3 16:15:54 CET 2013


Revision: 53533
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53533
Author:   campbellbarton
Date:     2013-01-03 15:15:51 +0000 (Thu, 03 Jan 2013)
Log Message:
-----------
fix for bug rendering text at small sizes, padding was incorrectly being applied to the characters y offset causing out of bounds pixels to be requested from glTexSubImage2D().
also clamp width, height of the character bitmap to the bitmap bounds since this can still happen for very small text (2-3 pixels high).

Modified Paths:
--------------
    trunk/blender/source/blender/blenfont/intern/blf_glyph.c

Modified: trunk/blender/source/blender/blenfont/intern/blf_glyph.c
===================================================================
--- trunk/blender/source/blender/blenfont/intern/blf_glyph.c	2013-01-03 13:37:17 UTC (rev 53532)
+++ trunk/blender/source/blender/blenfont/intern/blf_glyph.c	2013-01-03 15:15:51 UTC (rev 53533)
@@ -383,7 +383,7 @@
 		if (gc->cur_tex == -1) {
 			blf_glyph_cache_texture(font, gc);
 			gc->x_offs = gc->pad;
-			gc->y_offs = gc->pad;
+			gc->y_offs = 0;
 		}
 
 		if (gc->x_offs > (gc->p2_width - gc->max_glyph_width)) {
@@ -391,7 +391,7 @@
 			gc->y_offs += gc->max_glyph_height;
 
 			if (gc->y_offs > (gc->p2_height - gc->max_glyph_height)) {
-				gc->y_offs = gc->pad;
+				gc->y_offs = 0;
 				blf_glyph_cache_texture(font, gc);
 			}
 		}
@@ -400,6 +400,19 @@
 		g->xoff = gc->x_offs;
 		g->yoff = gc->y_offs;
 
+		/* prevent glTexSubImage2D from failing if the character
+		 * asks for pixels out of bounds, this tends only to happen
+		 * with very small sizes (5px high or less) */
+		if (UNLIKELY((g->xoff + g->width)  > gc->p2_width)) {
+			g->width  -= (g->xoff + g->width)  - gc->p2_width;
+			BLI_assert(g->width > 0);
+		}
+		if (UNLIKELY((g->yoff + g->height) > gc->p2_height)) {
+			g->height -= (g->yoff + g->height) - gc->p2_height;
+			BLI_assert(g->height > 0);
+		}
+
+
 		glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
 		glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
 		glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
@@ -407,6 +420,7 @@
 
 		glBindTexture(GL_TEXTURE_2D, g->tex);
 		glTexSubImage2D(GL_TEXTURE_2D, 0, g->xoff, g->yoff, g->width, g->height, GL_ALPHA, GL_UNSIGNED_BYTE, g->bitmap);
+		BLI_assert(glGetError() == GL_NO_ERROR);
 		glPopClientAttrib();
 
 		g->uv[0][0] = ((float)g->xoff) / ((float)gc->p2_width);




More information about the Bf-blender-cvs mailing list