draw_line vs. draw_quad for drawing filled quads

Posted By: Clemens

draw_line vs. draw_quad for drawing filled quads - 09/14/11 15:29

Just a short question with rather low priority:

It's easy to develope a function for drawing filled quads with draw_line (-> drawing many lines in a row).
Is there any good reason if this way is more useful for the programer (bmaps are not needed) not to go this way, but using instead draw_quad?
Posted By: Myrkling

Re: draw_line vs. draw_quad for drawing filled quads - 09/14/11 16:40

Drawing quads with draw_quad is probably quite a bit faster than using draw_line for the same purpose.
draw_quad also makes rotating and scaling quads easier.
Posted By: Clemens

Re: draw_line vs. draw_quad for drawing filled quads - 09/14/11 20:03

You think it's faster?

However, I had to realize that it's even simpler and more user friendly to write this function with draw_quad... wink

But if you would like continue to philosophize (like: what's faster?), feel free... I'm in 8)
Posted By: Superku

Re: draw_line vs. draw_quad for drawing filled quads - 09/14/11 20:13

Why should it be faster to draw multiple lines instead of one single quad of the same size?!
Posted By: Myrkling

Re: draw_line vs. draw_quad for drawing filled quads - 09/14/11 22:38

I can't tell you why exactly, for I don't know the implementation details of these functions.

However, you can run this little test to see the speed difference (it's pretty obvious in this case):
Code:
#include <acknex.h>

void main()
{
    wait(1);
        
    while (1)
    {
        int i;
        var draw_line_time, draw_quad_time;
        
        timer();
        
        draw_line(NULLVECTOR, NULL, 100);
    
        for (i = 0; i < screen_size.y; i++)
        {
            draw_line(vector(0, i, 0), COLOR_WHITE, 100);
            draw_line(vector(screen_size.x, i, 0), COLOR_WHITE, 100);
        }
        
        draw_line_time = timer();
        
        draw_quad(NULL, NULLVECTOR, NULL, screen_size, NULL, COLOR_WHITE, 100, 0);
        
        draw_quad_time = timer();
        
        DEBUG_VAR(draw_line_time, 10);
        DEBUG_VAR(draw_quad_time, 30);
        
        wait (1);
    }
}


Posted By: MrGuest

Re: draw_line vs. draw_quad for drawing filled quads - 09/15/11 15:16

trying
Code:
#include <acknex.h>


void main()
{
	wait(1);
	
	int i;
	var draw_line_time1, draw_line_time2, draw_quad_time1, draw_quad_time2;
	while (1)
	{
		
		timer();
		
		//test1
		draw_line(NULLVECTOR, NULL, 100);
		
		for (i = 0; i < screen_size.y; i++)
		{
			draw_line(vector(0, i, 0), COLOR_WHITE, 100);
			draw_line(vector(screen_size.x, i, 0), COLOR_WHITE, 100);
		}
		
		draw_line_time1 = timer();
		
		//test2
		draw_quad(NULL, NULLVECTOR, NULL, screen_size, NULL, COLOR_WHITE, 100, 0);
		
		draw_quad_time1 = timer();
		
		//test3
		draw_quad(NULL, NULLVECTOR, NULL, screen_size, NULL, COLOR_WHITE, 100, 0);
		
		draw_quad_time2 = timer();
		
		//test4
		draw_line(NULLVECTOR, NULL, 100);
		
		for (i = 0; i < screen_size.y; i++)
		{
			draw_line(vector(0, i, 0), COLOR_WHITE, 100);
			draw_line(vector(screen_size.x, i, 0), COLOR_WHITE, 100);
		}
		
		draw_line_time2 = timer();
		
		DEBUG_VAR(draw_line_time1, 10);
		DEBUG_VAR(draw_quad_time1, 30);
		DEBUG_VAR(draw_line_time2, 50);
		DEBUG_VAR(draw_quad_time2, 70);
		
		wait (1);
	}
}

will give you an unexplainable result. changing the order you draw shows draw_line as being quicker
Posted By: Myrkling

Re: draw_line vs. draw_quad for drawing filled quads - 09/15/11 20:41

I can't confirm this.

For me draw_line is slower in both cases (measured time: approx. 7300µs each).
Noticeable is though, that the second draw_quad is faster than the first (first: ~20µs, second: ~10µs).

Maybe you've mistaken draw_line_time2 for draw_quad_time2?
Posted By: MrGuest

Re: draw_line vs. draw_quad for drawing filled quads - 09/15/11 23:52

sorry, probably wasn't clear enough (or at all really), draw_quad is always quicker

performing a draw_line then draw_quad for some reason is quicker than draw_quad then draw_line (obviously there's no reason to just draw the same thing twice).

drawing 2 quad's the second is usually 1/10 of the speed of the first call

drawing 2 draw_lines the first is 100+ times SLOWER than draw_quad, the second call is then 10 times the speed of the first
Posted By: Myrkling

Re: draw_line vs. draw_quad for drawing filled quads - 09/17/11 18:22

Ahh, I see. I misunderstood you on that one.

Maybe there needs something to be initialized or reset when draw_line/draw_quad is called for the first time in a frame. This could explain why subsequent calls of these functions are faster.
© 2024 lite-C Forums