Re: [AD] Line clipping fix

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


On Thu, 2004-01-15 at 15:14, Doug Eleveld wrote:
> Hi Everyone,
> 
> I have gotten line drawing to clip properly while
> keeping track of the bresenham state.  It should be
> faster than 4.1.11 for clipped lines and should be
> almost as fast as the pixel incorrect version in
> 4.1.12.  I dont know if there are standardized speed
> or regression tests that need to be run.
> 

I think not there are.. it might be some hidden feature of the test
program, but I think there's only the interactive tests..

> I've also made a test program to show the problems
> with 4.1.12.
> 
> I dont know anything about gettign this code into
> allegro.  I assume that someone can (test and) apply
> this patch?
> 

and in a private mail:
> I am just running some speed test now.  Under DOS 640x480x16 I get 
> unclipped lines per sec
> 
> Mine     125805
> 4.1.12   138889
> 4.1.11   145346

I just ran test as well and get (X11):

yours  4015
CVS    4214

Which is similiar to your result (10%/5% slower). But when drawing to
memory bitmaps, like in the attached program, I get:

yours  66000
CVS    105000

So it's like 40% slower. CVS is the same as 4.1.12, and 4.1.11 and CVS
seem to be about equally fast to me.

As I already said once - maybe you can try modifying it, so in case
there is no clipping, do_line is used, like in the 4.1.11/12 case? So
there should be no performance differences in the unclipped case - and
only in the clipped case the clipped bresenham would be used. I guess
for this to work, and also draw the same lines when clipped and not,
you'd have to use all 8 possible bresenham directions again, which would
make the code complicated :P

-- 
Elias Pschernig <elias@xxxxxxxxxx>
#include <allegro.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>

volatile int t = 0;
void
ticker (void)
{
   t++;
}

int
main (int argc, char **argv)
{
   allegro_init ();
   set_gfx_mode (GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
   install_keyboard ();
   install_timer ();
   install_int_ex (ticker, BPS_TO_TIMER (100));

   BITMAP *bmp = create_bitmap (SCREEN_W, SCREEN_H);

   int c = makecol (0, 0, 0);
   int n = 0;
   int p = 0;

   int clip = 0;
   if (argc > 1 && !ustrcmp (argv[1], "-clip"))
      clip = 1;

   srand (0);//time (NULL));

   int start = t;
   do
   {
      if (clip)
      {
         int x = rand () % SCREEN_W;
         int y = rand () % SCREEN_H;
         int x_ = rand () % SCREEN_W;
         int y_ = rand () % SCREEN_H;
         set_clip_rect (bmp, x, y, x_, y_);
      }
      int x = rand () % SCREEN_W;
      int y = rand () % SCREEN_H;
      int x_ = rand () % SCREEN_W;
      int y_ = rand () % SCREEN_H;
      line (bmp, x, y, x_, y_, c);
      n++;
      p += MAX (ABS (1 + x_ - x), ABS (1 + y_ - y));
   }
   while (t - start < 3000);
   int end = t;

   double T = (double)(end - start) / 100.0;
   double N = n;
   double P = p;
   printf ("lines:  %.1f / sec\n", N / T);
   printf ("pixels: %.1f / sec\n", P / T);

   return 0;
}
END_OF_MAIN ()


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