[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22273] branches/blender2.5/blender/source /blender: Remove bitmap mode from blenfont, only draw with textures.

Diego Borghetti bdiego at gmail.com
Thu Aug 6 22:06:02 CEST 2009


Revision: 22273
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22273
Author:   bdiego
Date:     2009-08-06 22:06:02 +0200 (Thu, 06 Aug 2009)

Log Message:
-----------
Remove bitmap mode from blenfont, only draw with textures.

As Joe point on a previous mail, glBitmap don't work nice
on all cards and also some of the things that we can do
with texture are hard (or need that blender check the font mode)
to implement.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/blenfont/BLF_api.h
    branches/blender2.5/blender/source/blender/blenfont/intern/blf.c
    branches/blender2.5/blender/source/blender/blenfont/intern/blf_font.c
    branches/blender2.5/blender/source/blender/blenfont/intern/blf_glyph.c
    branches/blender2.5/blender/source/blender/blenfont/intern/blf_internal_types.h
    branches/blender2.5/blender/source/blender/editors/interface/interface_style.c

Modified: branches/blender2.5/blender/source/blender/blenfont/BLF_api.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenfont/BLF_api.h	2009-08-06 18:31:25 UTC (rev 22272)
+++ branches/blender2.5/blender/source/blender/blenfont/BLF_api.h	2009-08-06 20:06:02 UTC (rev 22273)
@@ -140,17 +140,10 @@
 /* Free the data return by BLF_dir_get. */
 void BLF_dir_free(char **dirs, int count);
 
-/* Set the current draw mode. */
-void BLF_mode(int mode);
-
 /* font->flags. */
 #define BLF_ROTATION (1<<0)
 #define BLF_CLIPPING (1<<1)
 #define BLF_SHADOW (1<<2)
 #define BLF_KERNING_DEFAULT (1<<3)
 
-/* font->mode. */
-#define BLF_MODE_TEXTURE 0
-#define BLF_MODE_BITMAP 1
-
 #endif /* BLF_API_H */

Modified: branches/blender2.5/blender/source/blender/blenfont/intern/blf.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenfont/intern/blf.c	2009-08-06 18:31:25 UTC (rev 22272)
+++ branches/blender2.5/blender/source/blender/blenfont/intern/blf.c	2009-08-06 20:06:02 UTC (rev 22273)
@@ -333,7 +333,6 @@
 	}
 }
 
-
 void BLF_draw(char *str)
 {
 	FontBLF *font;
@@ -342,40 +341,24 @@
 	 * The pixmap alignment hack is handle
 	 * in BLF_position (old ui_rasterpos_safe).
 	 */
-
 	font= global_font[global_font_cur];
 	if (font) {
-		if (font->mode == BLF_MODE_BITMAP) {
-			glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
-			glPushAttrib(GL_ENABLE_BIT);
-			glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
-			glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
-			glDisable(GL_BLEND);
-			glRasterPos3f(font->pos[0], font->pos[1], font->pos[2]);
+		glEnable(GL_BLEND);
+		glEnable(GL_TEXTURE_2D);
+		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
-			blf_font_draw(font, str);
+		glPushMatrix();
+		glTranslatef(font->pos[0], font->pos[1], font->pos[2]);
+		glScalef(font->aspect, font->aspect, 1.0);
 
-			glPopAttrib();
-			glPopClientAttrib();
-		}
-		else {
-			glEnable(GL_BLEND);
-			glEnable(GL_TEXTURE_2D);
-			glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+		if (font->flags & BLF_ROTATION)
+			glRotatef(font->angle, 0.0f, 0.0f, 1.0f);
 
-			glPushMatrix();
-			glTranslatef(font->pos[0], font->pos[1], font->pos[2]);
-			glScalef(font->aspect, font->aspect, 1.0);
+		blf_font_draw(font, str);
 
-			if (font->flags & BLF_ROTATION)
-				glRotatef(font->angle, 0.0f, 0.0f, 1.0f);
-
-			blf_font_draw(font, str);
-
-			glPopMatrix();
-			glDisable(GL_BLEND);
-			glDisable(GL_TEXTURE_2D);
-		}
+		glPopMatrix();
+		glDisable(GL_BLEND);
+		glDisable(GL_TEXTURE_2D);
 	}
 }
 
@@ -506,15 +489,6 @@
 	}
 }
 
-void BLF_mode(int mode)
-{
-	FontBLF *font;
-
-	font= global_font[global_font_cur];
-	if (font)
-		font->mode= mode;
-}
-
 void BLF_shadow(int level, float r, float g, float b, float a)
 {
 	FontBLF *font;

Modified: branches/blender2.5/blender/source/blender/blenfont/intern/blf_font.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenfont/intern/blf_font.c	2009-08-06 18:31:25 UTC (rev 22272)
+++ branches/blender2.5/blender/source/blender/blenfont/intern/blf_font.c	2009-08-06 20:06:02 UTC (rev 22273)
@@ -128,17 +128,6 @@
 		if (!g)
 			continue;
 
-		/*
-		 * This happen if we change the mode of the
-		 * font, we don't drop the glyph cache, so it's
-		 * possible that some glyph don't have the
-		 * bitmap or texture information.
-		 */
-		if (font->mode == BLF_MODE_BITMAP && (!g->bitmap_data))
-			g= blf_glyph_add(font, glyph_index, c);
-		else if (font->mode == BLF_MODE_TEXTURE && (!g->tex_data))
-			g= blf_glyph_add(font, glyph_index, c);
-
 		if (has_kerning && g_prev) {
 			delta.x= 0;
 			delta.y= 0;
@@ -200,17 +189,6 @@
 		if (!g)
 			continue;
 
-		/*
-		 * This happen if we change the mode of the
-		 * font, we don't drop the glyph cache, so it's
-		 * possible that some glyph don't have the
-		 * bitmap or texture information.
-		 */
-		if (font->mode == BLF_MODE_BITMAP && (!g->bitmap_data))
-			g= blf_glyph_add(font, glyph_index, c);
-		else if (font->mode == BLF_MODE_TEXTURE && (!g->tex_data))
-			g= blf_glyph_add(font, glyph_index, c);
-
 		if (has_kerning && g_prev) {
 			delta.x= 0;
 			delta.y= 0;
@@ -316,7 +294,6 @@
 
 void blf_font_fill(FontBLF *font)
 {
-	font->mode= BLF_MODE_TEXTURE;
 	font->aspect= 1.0f;
 	font->pos[0]= 0.0f;
 	font->pos[1]= 0.0f;

Modified: branches/blender2.5/blender/source/blender/blenfont/intern/blf_glyph.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenfont/intern/blf_glyph.c	2009-08-06 18:31:25 UTC (rev 22272)
+++ branches/blender2.5/blender/source/blender/blenfont/intern/blf_glyph.c	2009-08-06 20:06:02 UTC (rev 22273)
@@ -189,12 +189,11 @@
 	return(NULL);
 }
 
-GlyphBLF *blf_glyph_texture_add(FontBLF *font, FT_UInt index, unsigned int c)
+GlyphBLF *blf_glyph_add(FontBLF *font, FT_UInt index, unsigned int c)
 {
 	FT_GlyphSlot slot;
 	GlyphCacheBLF *gc;
 	GlyphBLF *g;
-	GlyphTextureBLF *gt;
 	FT_Error err;
 	FT_Bitmap bitmap;
 	FT_BBox bbox;
@@ -202,13 +201,7 @@
 	int do_new;
 
 	g= blf_glyph_search(font->glyph_cache, c);
-
-	/* The glyph can be add on Bitmap mode, so we have the
-	 * glyph, but not the texture data.
-	 */
-	if (g && g->tex_data)
-		return(g);
-	else if (g)
+	if (g)
 		do_new= 0;
 	else
 		do_new= 1;
@@ -228,14 +221,10 @@
 		g= (GlyphBLF *)MEM_mallocN(sizeof(GlyphBLF), "blf_glyph_add");
 		g->next= NULL;
 		g->prev= NULL;
-		g->tex_data= NULL;
-		g->bitmap_data= NULL;
 		g->c= c;
 	}
 
-	gt= (GlyphTextureBLF *)MEM_mallocN(sizeof(GlyphTextureBLF), "blf_glyph_texture_add");
 	gc= font->glyph_cache;
-
 	if (gc->cur_tex == -1) {
 		blf_glyph_cache_texture(font, gc);
 		gc->x_offs= gc->pad;
@@ -253,27 +242,27 @@
 	}
 
 	bitmap= slot->bitmap;
-	gt->tex= gc->textures[gc->cur_tex];
+	g->tex= gc->textures[gc->cur_tex];
 
-	gt->xoff= gc->x_offs;
-	gt->yoff= gc->y_offs;
-	gt->width= bitmap.width;
-	gt->height= bitmap.rows;
+	g->xoff= gc->x_offs;
+	g->yoff= gc->y_offs;
+	g->width= bitmap.width;
+	g->height= bitmap.rows;
 
-	if (gt->width && gt->height) {
+	if (g->width && g->height) {
 		glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
 		glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
 		glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
 		glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
 
-		glBindTexture(GL_TEXTURE_2D, gt->tex);
-		glTexSubImage2D(GL_TEXTURE_2D, 0, gt->xoff, gt->yoff, gt->width, gt->height, GL_ALPHA, GL_UNSIGNED_BYTE, bitmap.buffer);
+		glBindTexture(GL_TEXTURE_2D, g->tex);
+		glTexSubImage2D(GL_TEXTURE_2D, 0, g->xoff, g->yoff, g->width, g->height, GL_ALPHA, GL_UNSIGNED_BYTE, bitmap.buffer);
 		glPopClientAttrib();
 	}
 
 	g->advance= ((float)slot->advance.x) / 64.0f;
-	gt->pos_x= slot->bitmap_left;
-	gt->pos_y= slot->bitmap_top;
+	g->pos_x= slot->bitmap_left;
+	g->pos_y= slot->bitmap_top;
 
 	FT_Outline_Get_CBox(&(slot->outline), &bbox);
 	g->box.xmin= ((float)bbox.xMin) / 64.0f;
@@ -281,10 +270,10 @@
 	g->box.ymin= ((float)bbox.yMin) / 64.0f;
 	g->box.ymax= ((float)bbox.yMax) / 64.0f;
 
-	gt->uv[0][0]= ((float)gt->xoff) / ((float)gc->p2_width);
-	gt->uv[0][1]= ((float)gt->yoff) / ((float)gc->p2_height);
-	gt->uv[1][0]= ((float)(gt->xoff + gt->width)) / ((float)gc->p2_width);
-	gt->uv[1][1]= ((float)(gt->yoff + gt->height)) / ((float)gc->p2_height);
+	g->uv[0][0]= ((float)g->xoff) / ((float)gc->p2_width);
+	g->uv[0][1]= ((float)g->yoff) / ((float)gc->p2_height);
+	g->uv[1][0]= ((float)(g->xoff + g->width)) / ((float)gc->p2_width);
+	g->uv[1][1]= ((float)(g->yoff + g->height)) / ((float)gc->p2_height);
 
 	/* update the x offset for the next glyph. */
 	gc->x_offs += (int)(g->box.xmax - g->box.xmin + gc->pad);
@@ -295,126 +284,11 @@
 		gc->rem_glyphs--;
 	}
 
-	/* and attach the texture information. */
-	g->tex_data= gt;
-
 	return(g);
 }
 
-GlyphBLF *blf_glyph_bitmap_add(FontBLF *font, FT_UInt index, unsigned int c)
-{
-	FT_GlyphSlot slot;
-	GlyphCacheBLF *gc;
-	GlyphBLF *g;
-	GlyphBitmapBLF *gt;
-	FT_Error err;
-	FT_Bitmap bitmap;
-	FT_BBox bbox;
-	unsigned char *dest, *src;
-	unsigned int key, y;
-	unsigned int src_width, src_height, src_pitch;
-	int do_new;
-
-	g= blf_glyph_search(font->glyph_cache, c);
-
-	/*
-	 * The glyph can be add on Texture mode, so we have the
-	 * glyph, but not the bitmap data.
-	 */
-	if (g && g->bitmap_data)
-		return(g);
-	else if (g)
-		do_new= 0;
-	else
-		do_new= 1;
-
-	err= FT_Load_Glyph(font->face, index, FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP);
-	if (err)
-		return(NULL);
-
-	/* get the glyph. */
-	slot= font->face->glyph;
-
-	err= FT_Render_Glyph(slot, FT_RENDER_MODE_MONO);
-	if (err || slot->format != FT_GLYPH_FORMAT_BITMAP)
-		return(NULL);
-
-	if (do_new) {
-		g= (GlyphBLF *)MEM_mallocN(sizeof(GlyphBLF), "blf_glyph_add");
-		g->next= NULL;
-		g->prev= NULL;
-		g->tex_data= NULL;
-		g->bitmap_data= NULL;
-		g->c= c;
-	}
-
-	gt= (GlyphBitmapBLF *)MEM_mallocN(sizeof(GlyphBitmapBLF), "blf_glyph_bitmap_add");
-	gc= font->glyph_cache;
-
-	bitmap= slot->bitmap;
-
-	src_width= bitmap.width;
-	src_height= bitmap.rows;
-	src_pitch= bitmap.pitch;
-
-	gt->width= src_width;
-	gt->height= src_height;
-	gt->pitch= src_pitch;
-	gt->image= NULL;
-
-	if (gt->width && gt->height) {
-		gt->image= (unsigned char *)malloc(gt->pitch * gt->height);
-
-		dest= gt->image + ((gt->height - 1) * gt->pitch);
-		src= bitmap.buffer;
-
-		for (y= 0; y < src_height; ++y) {
-			memcpy((void *)dest, (void *)src, src_pitch);
-			dest -= gt->pitch;
-			src += src_pitch;
-		}
-	}
-
-	g->advance= ((float)slot->advance.x) / 64.0f;
-	gt->pos_x= slot->bitmap_left;
-	gt->pos_y= ((int)src_height) - slot->bitmap_top;
-
-	FT_Outline_Get_CBox(&(slot->outline), &bbox);
-	g->box.xmin= ((float)bbox.xMin) / 64.0f;
-	g->box.xmax= ((float)bbox.xMax) / 64.0f;
-	g->box.ymin= ((float)bbox.yMin) / 64.0f;
-	g->box.ymax= ((float)bbox.yMax) / 64.0f;
-
-	if (do_new) {
-		key= blf_hash(g->c);
-		BLI_addhead(&(gc->bucket[key]), g);
-		gc->rem_glyphs--;
-	}
-
-	/* and attach the bitmap information. */
-	g->bitmap_data= gt;
-
-	return(g);
-}
-
-GlyphBLF *blf_glyph_add(FontBLF *font, FT_UInt index, unsigned int c)
-{
-	if (font->mode == BLF_MODE_BITMAP)
-		return(blf_glyph_bitmap_add(font, index, c));
-	return(blf_glyph_texture_add(font, index, c));
-}
-
 void blf_glyph_free(GlyphBLF *g)
 {
-	if (g->tex_data)
-		MEM_freeN(g->tex_data);
-
-	if (g->bitmap_data) {
-		if (g->bitmap_data->image)
-			free((void *)g->bitmap_data->image);
-		MEM_freeN(g->bitmap_data);
-	}
-
 	/* don't need free the texture, the GlyphCache already

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list