[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43202] trunk/blender/source/blender/ blenfont/intern: Move glTexEnvi to draw__start/draw__end.

Diego Borghetti bdiego at gmail.com
Fri Jan 6 17:40:57 CET 2012


Revision: 43202
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43202
Author:   bdiego
Date:     2012-01-06 16:40:57 +0000 (Fri, 06 Jan 2012)
Log Message:
-----------
Move glTexEnvi to draw__start/draw__end.

As Campbell point, this is to avoid call glGet/glTexEnvi
on each character.

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

Modified: trunk/blender/source/blender/blenfont/intern/blf.c
===================================================================
--- trunk/blender/source/blender/blenfont/intern/blf.c	2012-01-06 16:37:07 UTC (rev 43201)
+++ trunk/blender/source/blender/blenfont/intern/blf.c	2012-01-06 16:40:57 UTC (rev 43202)
@@ -479,7 +479,7 @@
 	}
 }
 
-static void blf_draw__start(FontBLF *font, GLint *mode)
+static void blf_draw__start(FontBLF *font, GLint *mode, GLint *param)
 {
 	/*
 	 * The pixmap alignment hack is handle
@@ -516,10 +516,19 @@
 
 	/* always bind the texture for the first glyph */
 	font->tex_bind_state= -1;
+
+	/* Save the current parameter to restore it later. */
+	glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, param);
+	if (*param != GL_MODULATE)
+		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 }
 
-static void blf_draw__end(GLint mode)
+static void blf_draw__end(GLint mode, GLint param)
 {
+	/* and restore the original value. */
+	if (param != GL_MODULATE)
+		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, param);
+
 	glMatrixMode(GL_TEXTURE);
 	glPopMatrix();
 
@@ -536,24 +545,24 @@
 void BLF_draw(int fontid, const char *str, size_t len)
 {
 	FontBLF *font= BLF_get(fontid);
-	GLint mode;
+	GLint mode, param;
 
 	if (font && font->glyph_cache) {
-		blf_draw__start(font, &mode);
+		blf_draw__start(font, &mode, &param);
 		blf_font_draw(font, str, len);
-		blf_draw__end(mode);
+		blf_draw__end(mode, param);
 	}
 }
 
 void BLF_draw_ascii(int fontid, const char *str, size_t len)
 {
 	FontBLF *font= BLF_get(fontid);
-	GLint mode;
+	GLint mode, param;
 
 	if (font && font->glyph_cache) {
-		blf_draw__start(font, &mode);
+		blf_draw__start(font, &mode, &param);
 		blf_font_draw_ascii(font, str, len);
-		blf_draw__end(mode);
+		blf_draw__end(mode, param);
 	}
 }
 

Modified: trunk/blender/source/blender/blenfont/intern/blf_glyph.c
===================================================================
--- trunk/blender/source/blender/blenfont/intern/blf_glyph.c	2012-01-06 16:37:07 UTC (rev 43201)
+++ trunk/blender/source/blender/blenfont/intern/blf_glyph.c	2012-01-06 16:40:57 UTC (rev 43202)
@@ -368,7 +368,6 @@
 	float dx, dx1;
 	float y1, y2;
 	float xo, yo;
-	GLint param;
 
 	if ((!g->width) || (!g->height))
 		return 1;
@@ -450,11 +449,6 @@
 		glBindTexture(GL_TEXTURE_2D, (font->tex_bind_state= g->tex));
 	}
 
-	/* Save the current parameter to restore it later. */
-	glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &param);
-	if (param != GL_MODULATE)
-		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-
 	if (font->flags & BLF_SHADOW) {
 
 		switch(font->shadow) {
@@ -493,9 +487,5 @@
 			break;
 	}
 
-	/* and restore the original value. */
-	if (param != GL_MODULATE)
-		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, param);
-
 	return 1;
 }



More information about the Bf-blender-cvs mailing list