Optimizing Line Rendering In Vesa

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Lprogster
Member
Member
Posts: 174
Joined: Tue Nov 14, 2006 11:59 am

Optimizing Line Rendering In Vesa

Post 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
Last edited by Lprogster on Mon Jul 02, 2007 10:10 am, edited 1 time in total.
exkor
Member
Member
Posts: 111
Joined: Wed May 23, 2007 9:38 pm

Post 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
User avatar
Kevin McGuire
Member
Member
Posts: 843
Joined: Tue Nov 09, 2004 12:00 am
Location: United States
Contact:

Post 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;
}
Lprogster
Member
Member
Posts: 174
Joined: Tue Nov 14, 2006 11:59 am

Post by Lprogster »

Thanks for the code, Kevin. Having a look...

Thanks for the link exkor, but I've already seen that...
Last edited by Lprogster on Tue Oct 23, 2007 10:59 am, edited 1 time in total.
User avatar
Assembler
Member
Member
Posts: 30
Joined: Fri Oct 27, 2006 5:26 am
Contact:

Post 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
Attachments
b.zip
I'll remove the attachment when my quota is full :)
(43.91 KiB) Downloaded 47 times
Systems and Computer Engineering Researcher
"Do you pine for the nice days of Minix-1.1, when men were men and wrote their own device drivers?" -- Linus Torvalds
http://sce.carleton.ca/~maslan
Lprogster
Member
Member
Posts: 174
Joined: Tue Nov 14, 2006 11:59 am

Post 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
Post Reply