Locking bitmap is slower than not (?)
Im trying to draw text and primitives to the screen.
This is my current drawing function:
4// ... calculate triangle points and save them to "vertices";
, ALLEGRO_PIXEL_FORMAT_ANY, 0); // The current target bitmap is the display back buffer
vertices, null, null, 0
, size, ALLEGRO_PRIM_TRIANGLE_LIST); // Draw triangles
,255)); // Draw a rectangle
myfont, BLACK, 10
, ALLEGRO_ALIGN_LEFT, "TESTING");
When I draw around 180 000 triangles, Im getting 25FPS while locking the bitmap. But if I comment both the lock and unlock functions, Im getting ~60FPS !
I must be doing something terrible wrong with my drawing process (?). What's the correct order to draw and lock the bitmap ?.
Furthermore, why cant I clear the display with al_clear_to_color or write text to it when it is locked ?
Thanks a lot.
Short answer is, you don't need to lock the bitmap except for direct memory access, and you shouldn't.
Note: While a bitmap is locked, you can not use any drawing operations on it (with the sole exception of al_put_pixel and al_put_blended_pixel).
Basically, Allegro will lock the bitmap when it needs to, so you don't have to worry about it yourself, unless you're doing a lot of direct memory access.
What you might be confusing locking the bitmap with is holding the bitmap drawing as per https://www.allegro.cc/manual/5/al_hold_bitmap_drawing. Locking is indeed only for direct access and hence, slows down drawing, but holding bitmap drawing can enhance performance if done right. Another way is to use possibly improve performance is the primitives functions.
Here is a link for the discussion catcher (one of the cooleset, most under-rated features of these forums): al_hold_bitmap_drawing
Thread #616537. Printed from Allegro.cc
Yep. I only lock bitmaps when I specifically use al_get_pixel or al_put_pixel