Page 1 of 1

Optimizing Line Rendering In Vesa

Posted: Thu Jun 28, 2007 8:11 am
by Lprogster
Well, as the title says, I wanna optimize my Vesa lin ( ) function. I have optimized it prettuy well (I think) so far - can anyone see anything I could improve?

Code: Select all

...
The code is so inelegant now... Before I optimized it - it was nice and clean looking!

Thank you,
Lster

Posted: Thu Jun 28, 2007 4:28 pm
by exkor
You may wanna consider special cases: horizontal, vertical and if they are aligned on 1,2,4,8 bait boundaries.
look assembly listing of your code (especially if its gcc) and fix it yourself
http://www.osdev.org/phpBB2/viewtopic.php?t=14138
as of your algorithm I dont know

Posted: Thu Jun 28, 2007 7:51 pm
by Kevin McGuire
I have not tested this.. I could be wrong as it might not draw a nice line.. but I think this works?

Code: Select all

void ldraw(int x1, int y1, int x2, int y2)
{
	int dx = (x2 - x1);
	int dy = (y2 - y1);
	if(dx > dy)
	{
		a1 = x1;
		a2 = x2;
		b2 = y1;
		bs = dy/dx;
	}else{
		a1 = y1;
		a2 = y2;
		b2 = x1;
		bs = dx/dy;
	}
	for(; a1 < a2; ++a1, b2 += bs)
	{
		plotpixel(a1, b2);
	}
	return;
}

Posted: Fri Jun 29, 2007 2:12 am
by Lprogster
Thanks for the code, Kevin. Having a look...

Thanks for the link exkor, but I've already seen that...

Posted: Fri Jun 29, 2007 3:50 am
by Assembler
Hi,
I think you are using Bresenham which is AFAIK the fastest line drawing algorithm.

Bresenham uses a decision parameter P(k), for slope m < 1, it only inc Y or leave Y according to the decision parameter P(k), while X is always incremented. For m > 1 reverse the role of X & Y.

http://en.wikipedia.org/wiki/Bresenham_line_algorithm

Posted: Fri Jun 29, 2007 8:20 am
by Lprogster
Yes, I am using Bresenham's algorithm. Can anyone tell me if it is a good implementation of that? I want it as fast as possible! Muahhah!

Thanks,
Lster