Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » Primitive equivalent to al_hold_bitmap_drawing?

This thread is locked; no one can reply to it. rss feed Print
Primitive equivalent to al_hold_bitmap_drawing?
EWClay
Member #14,750
December 2012

I find the primitive drawing functions to be very slow compared to the low level drawing routines, al_draw_prim and so on.

It's a shame because some of those functions are quite useful; I don't want to write my own ellipse drawing code for example.

If I can emulate these functions 10x faster using al_draw_prim and buffering, shouldn't there be a way to do that internally? I'm thinking of something along the lines of al_hold_bitmap_drawing.

Any thoughts?

SiegeLord
Member #7,827
October 2006
avatar

I tried implementing this once, and there was no performance difference. al_hold_bitmap_drawing model doesn't really work for primitives anyway, as they, somewhat unlike bitmaps, occasionally take quite a bit of CPU work to generate in the first place... and the fact that the al_hold_bitmap_drawing model requires you to regenerate the vertex data every frame makes the idea somewhat moot. A real solution would involve the ability to "record" a sequence of drawing calls that can be replayed later.

That said, I, personally, am no longer interested in this kind of performance optimizations. Half the time they do nothing on my computer, half the time they help performance only on my computer. al_hold_bitmap_drawing, for example, pretty much did nothing on my old GPU. I'd suggest optimizing on a different level.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

EWClay
Member #14,750
December 2012

So it seems the functions that are hardest to implement are the least likely to benefit from the optimisation, without adding the ability to record.

I'm a little surprised that the approach was not a win for more simple shapes. On my system, which is a fairly typical PC, I can absolutely go 10x faster using al-draw_prim for lines and polygons.

pkrcel
Member #14,001
February 2012

Out of pure theoretical interest, care to elaborate?

I guess you ara passing the vertex data that you have pre-calculated to al draw prim right?

Wouldn't this be quite similar to what al_draw_ellipse does? Where exactly ther esi the performance hit?

It is unlikely that Google shares your distaste for capitalism. - Derezo
If one had the eternity of time, one would do things later. - Johan Halmén

EWClay
Member #14,750
December 2012

The difference is that I only call al_draw_prim once, after buffering possibly hundreds of primitives. The primitive drawing functions will kick off a batch every time.

For example, I draw a polygon over every tile in my game for fog-of-war. Without buffering, this would destroy my frame rate.

I also render circles for debug purposes, but they are not so straightforward to optimise.

Thomas Fjellstrom
Member #476
June 2000
avatar

I think in this case, you just load everything up into a VBO and fire it off with a glDrawArrays or whatever the function is.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

SiegeLord
Member #7,827
October 2006
avatar

I still have the primitive holding code somewhere... if you want, I can update it to work with 5.1 and you could see if it does anything.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

pkrcel
Member #14,001
February 2012

EWClay said:

The difference is that I only call al_draw_prim once, after buffering possibly hundreds of primitives. The primitive drawing functions will kick off a batch every time.

Ah yesss, I get it...pretty straightforward indeed

I know this may sound stupid, and I am partially hijacking the thread but I would like to understand a little bit more of the inner workings of the addon, so...for the circles, can't you use the al_calculate_arc with 0 to 360 as theta and delta? you could then append the calculated buffer into your vertex buffer and call al_draw_prim?

It is unlikely that Google shares your distaste for capitalism. - Derezo
If one had the eternity of time, one would do things later. - Johan Halmén

EWClay
Member #14,750
December 2012

Hadn't noticed al_calculate_arc. The ability to set the number of vertices is a bonus.

@SiegeLord: Can't hurt to try it, it the code exists. I can compare with my own simple version.

SiegeLord
Member #7,827
October 2006
avatar

Ok, here it is. This patch adds the following functions:

void al_hold_primitive_drawing(bool hold);
bool al_is_primitive_drawing_held(void);

Which function about the same as the bitmap equivalents. The deferred drawing is only implemented for al_draw_filled_triangle and al_draw_filled_ellipse.

It's up to you to come up with a benchmark where this sort of nonsense helps ;).

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Go to: