Pages: 1 2
Author Topic: Custom: Curve drawing functions (Bezier and Spline)  (110,275 Views)
Offline (Unknown gender) TheExDeus

Developer
Joined: Apr 2008
Posts: 1,860
View profile
Reply #15 Posted on: December 04, 2010, 07:53:33 PM
As far as I know* vectors are better for inserting at the end and iterating trough.** Lists are better for inserting and deleting in the middle (or anywhere). So in my case I think vectors could be better.

*And I know little, as 2 days ago I didn't know that in C++ vectors were arrays.
** http://www.gamedev.net/community/forums/topic.asp?topic_id=211458
Offline (Unknown gender) luiscubal

Member
Joined: Jun 2009
Posts: 452
View profile
Reply #16 Posted on: December 04, 2010, 08:23:49 PM
I was addressing Josh's concern of O(N) push complexity.
Offline (Unknown gender) TheExDeus

Developer
Joined: Apr 2008
Posts: 1,860
View profile
Reply #17 Posted on: December 04, 2010, 09:26:43 PM
Ou, ok. Thought that suggestion was pointed at me.

I released the current source. Added new functions and changed the _begin() spline functions to use stacks and vectors. The speed seems identical, but the memory usage could be down. Also now it allows nesting.
I added anti-aliasing function, which makes the splines look a lot better. Thou I have a decision on how to implement it. What I did for now is make curves totally independent from the rest of the system. So you can change color, alpha, aa, drawing mode etc. totally independent from other functions. And I am not sure if that is the best idea. For example, I could have aa code like this:
Code (C++) Select
void draw_set_antialiasing(bool enable, int qual)
{
    if (enable==1){
        glEnable(GL_LINE_SMOOTH);
        glHint(GL_LINE_SMOOTH_HINT, qual);
    }else{
        glDisable(GL_LINE_SMOOTH);
    }
}
But that will enable aa for every primitive (circles etc.). I ended up doing this:
Code (C++) Select
pr_curve_aa = enable;
pr_curve_aa_qual = qual;
With having this in every drawing function (which of course can slow down the function):
Code (C++) Select
    if (pr_curve_aa==1){
        glEnable(GL_LINE_SMOOTH);
        glHint(GL_LINE_SMOOTH_HINT, pr_curve_aa_qual);
    }else{
        glDisable(GL_LINE_SMOOTH);
    }
Of course it is needed only once per function call, and compared to all the trig going on just to draw thous splines and curves, I think this doesn't impact the speed at all. It just seems wrong..
And testing speed is extremely hard because FPS jumps like crazy. I think that number is updated several times too much. Maybe it should be updated once per second or once per half a second. Maybe its normal like this, but I never seen it jump like that in GM.
Offline (Unknown gender) RetroX

Master of all things Linux
Contributor
Joined: Apr 2008
Posts: 1,055
View profile
Reply #18 Posted on: December 05, 2010, 01:36:18 AM
Why not let the GPU handle it and use transformation matrices?  Or do they not work that way?  I haven't gone too much into GL, so, I don't know how it's done.
Offline (Unknown gender) Josh @ Dreamland

Prince of all Goldfish
Developer
Joined: Feb 2008
Posts: 2,950
View profile
Reply #19 Posted on: December 05, 2010, 02:18:06 AM
HaRRi, I think if you're going to offer an AA function, it may as well be for all primitives. Let the user make the call to it before and after spline drawing, if they like.

Luis, using a list would increase RAM. It would save push_back for the duration of one frame, then one subtract each frame, but at the cost of another add-dereference from there on. It doesn't really seem worth it...
Offline (Unknown gender) luiscubal

Member
Joined: Jun 2009
Posts: 452
View profile
Reply #20 Posted on: December 05, 2010, 03:03:17 AM
There's also the option of using bezier_reserve() to set vector capacity if the extra performance is that much needed.
That said, it's probably not worth it.
Pages: 1 2