Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [A5] al_draw_scaled_bitmap vs al_draw_scaled_rotated_bitmap

This thread is locked; no one can reply to it. rss feed Print
[A5] al_draw_scaled_bitmap vs al_draw_scaled_rotated_bitmap
pkrcel
Member #14,001
February 2012

There are fundamental differences in the two functions:

al_draw_scaled_bitmap
al_draw_scaled_rotated_bitmap

major one I can think about is that the first lets you draw a portion of the source bitmap, while the latter only draws always the whole source bitmap.

Aside from that, I find the calling convention of al_draw_scaled_rotated_bitmap more comfortable for SCALING only.

I would like to ask if calling the latter with rotation = 0 is roughly equivalent to calling the first one or there are significative perfomance differences (for a large number of calls, likely in every game).

Many thanks for any advice. :P

EDIT: forgot to mention the different way the two handle coordinates of the destination, but my main concern is performance...so that's not really a point.

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

Kris Asick
Member #1,424
July 2001

Performance-wise, the two functions are extremely similar, though adding rotation will slow things down by a few microseconds since it has to apply matrix rotations on top of the translations and scaling both functions need to do.

The difference is so incredibly small though you're better off using whichever one you're most comfortable with. Heck, I'm using al_draw_tinted_scaled_rotated_bitmap() for most of my calls and even when there's a couple thousand sprites/particles on screen I still get 60 FPS on my mid-range hardware... on top of some rather GPU intensive fragment shaders I've got going! ;)

--- Kris Asick (Gemini)
--- http://www.pixelships.com

SiegeLord
Member #7,827
October 2006
avatar

All al_draw_*_bitmap functions call the same underlying function with different parameters. Aside from the insignificant static function call overhead, there should be absolutely no performance difference between all of these functions.

"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

Thanks to both of you.

My concern was exactly that...what if I use al_draw_scaled_tinted_rotated_whatever_bitmap for ANY call (be it a sprite/particle/scenery) even thou I do no really need tinting/scaling/whatever?

Great to know, thanks a lot. ;D

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

Kris Asick
Member #1,424
July 2001

SiegeLord said:

All al_draw_*_bitmap functions call the same underlying function with different parameters. Aside from the insignificant static function call overhead, there should be absolutely no performance difference between all of these functions.

...wait... so you mean rotation and scaling matricies are applied even if not needed?

--- Kris Asick (Gemini)
--- http://www.pixelships.com

Arthur Kalliokoski
Second in Command
February 2005
avatar

...wait... so you mean rotation and scaling matricies are applied even if not needed?

I think it's like you're drawing 2D bitmaps via a 3D library, so the rotation and scaling are necessary anyway. OpenGL for instance has some 2D functions, but the docs state that the other parameters are filled in for you.

They all watch too much MSNBC... they get ideas.

pkrcel
Member #14,001
February 2012

I think it's because by an Hardware point of view, you end up always applying a transformation....IIRC it's the way HW is optimized for that.

(still, it's been TOO long since I dabbled in HW design matters for this to count anything ;D ).

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

Peter Wang
Member #23
April 2000

That might have been the original idea but we actually do a lot of matrix fiddling in software, often unnecessarily. _draw_tinted_rotated_scaled_bitmap_region is rather gross.

Elias
Member #358
May 2000

We also apparently do things now like query OpenGL for the current texture binding, in my memory there were drivers which had to talk to the GPU for that (making it extremely slow).

We really need something similar to the unit tests which does benchmarking of various functions. Right now it's hard to say what needs optimizing (that last thread comparing al_draw_bitmap to direct OpenGL calls indicated a speed difference between 0% and 20%, so either no need to do anything or quite some overhead). Also hard to see performance regressions without (at least somewhat) automated testing.

I already have something like that on my TODO, just reminding myself. I'm thinking about a set of .c files where each defines a function drawing something. And then a monolithic test program like the one in A4 which can call them all and output to some format which we could collect somewhere along with information about CPU and GPU (and Allegro version).

--
"Either help out or stop whining" - Evert

Go to: