- Online Community Forums » Programming Questions » Locking bitmap is slower than not (?)

This thread is locked; no one can reply to it. rss feed Print
Locking bitmap is slower than not (?)
Member #15,215
July 2013

Im trying to draw text and primitives to the screen.

This is my current drawing function:

1 2ALLEGRO_VERTEX *vertices; 3 4// ... calculate triangle points and save them to "vertices"; 5 6al_clear_to_color(BACKGROUND_COLOR); 7 8al_lock_bitmap(al_get_target_bitmap(), ALLEGRO_PIXEL_FORMAT_ANY, 0); // The current target bitmap is the display back buffer 9 10al_draw_prim(vertices, null, null, 0, size, ALLEGRO_PRIM_TRIANGLE_LIST); // Draw triangles 11al_draw_filled_rectangle(600, 0, 660, 660, al_map_rgb(255,255,255)); // Draw a rectangle 12 13al_unlock_bitmap(al_get_target_bitmap()); 14 15al_draw_text(myfont, BLACK, 10, 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.

Edgar Reynaldo
Major Reynaldo
May 2007

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.

Member #12,636
March 2011

What you might be confusing locking the bitmap with is holding the bitmap drawing as per 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.

Gideon Weems
Member #3,925
October 2003

Here is a link for the discussion catcher (one of the cooleset, most under-rated features of these forums): al_hold_bitmap_drawing

Member #9,729
April 2008

Yep. I only lock bitmaps when I specifically use al_get_pixel or al_put_pixel :)

<--- The ghost with the most!
[Website] [Youtube]

Go to: