From 50fb37ca2d378b595ef0ca4213dc3a85f09e4491 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Tue, 19 Sep 2006 08:18:32 +0000 Subject: [PATCH] * Optimised memory usage in the GL driver and added a few comments. --- caca/driver_gl.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/caca/driver_gl.c b/caca/driver_gl.c index 474ca6a..231c50e 100644 --- a/caca/driver_gl.c +++ b/caca/driver_gl.c @@ -495,12 +495,13 @@ static void gl_compute_font(caca_display_t *dp) uint32_t *image; int i, b, w, h, x, y; + /* Count how many glyphs this font has */ dp->drv.p->blocks = cucul_get_font_blocks(dp->drv.p->f); for(b = 0, i = 0; dp->drv.p->blocks[i + 1]; i += 2) b += dp->drv.p->blocks[i + 1] - dp->drv.p->blocks[i]; - dp->drv.p->txid = malloc(b * sizeof(int)); + /* Allocate a libcucul canvas and print all the glyphs on it */ cv = cucul_create_canvas(1, b); cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK); @@ -514,12 +515,16 @@ static void gl_compute_font(caca_display_t *dp) b += n; } + /* Draw the cucul canvas onto an image buffer */ image = malloc(b * dp->drv.p->font_height * dp->drv.p->font_width * sizeof(uint32_t)); cucul_render_canvas(cv, dp->drv.p->f, image, dp->drv.p->font_width, b * dp->drv.p->font_height, 4 * dp->drv.p->font_width); cucul_free_canvas(cv); + /* Convert all glyphs in the image buffer to GL textures */ + dp->drv.p->txid = malloc(b * sizeof(int)); + w = dp->drv.p->font_width <= 16 ? dp->drv.p->font_width : 16; h = dp->drv.p->font_height <= 16 ? dp->drv.p->font_height : 16;