[AD] character clipping proposal

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Hi everyone,

I noticed that text output in Allegro doesn't consider clipping conditions and renders each character of the string even when it can be easily determined that characters will be fully clipped.

Here is a patch on 4.2.2 that incorporates character based clipping to mono_render and color_render. The unclipped rendering speed is not slowed down by any detectable amount but the clipped drawing speed is quite a bit faster. It's hard to say exactly how much faster since test.exe chooses different clipping conditions all the time and profiling doesnt(?) check drawing with clipping.

The patch is very simple and should be easily translatable to WIP versions. I cant test them because the WIP versions dont compile for me.

best regards,

Doug eleveld

diff -wur allegro/src/font.c deleveld_charclip_patch/src/font.c
--- allegro/src/font.c	2006-12-11 19:14:36 +0000
+++ deleveld_charclip_patch/src/font.c	2008-05-14 16:32:50 +0000
@@ -540,10 +540,18 @@
     int ch = 0;
     AL_CONST char* p = text;
 
+    if (bmp->clip) {
+        if (x >= bmp->cr || y >= bmp->cb || y + text_height(f) <= bmp->ct)
+            return;
+    }
+
     acquire_bitmap(bmp);
 
     while( (ch = ugetxc(&p)) ) {
         x += f->vtable->render_char(f, ch, fg, bg, bmp, x, y);
+
+        if (bmp->clip && x >= bmp->cr)
+             break;
     }
 
     release_bitmap(bmp);
@@ -995,6 +1003,11 @@
     AL_CONST char* p = text;
     int ch = 0;
 
+    if (bmp->clip) {
+        if (x >= bmp->cr || y >= bmp->cb || y + text_height(f) <= bmp->ct)
+            return;
+    }
+
     acquire_bitmap(bmp);
 
     if(fg < 0 && bg >= 0) {
@@ -1004,6 +1017,9 @@
 
     while( (ch = ugetxc(&p)) ) {
         x += f->vtable->render_char(f, ch, fg, bg, bmp, x, y);
+
+        if (bmp->clip && x >= bmp->cr)
+            break;
     }
 
     release_bitmap(bmp);


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/