<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Locking bitmap is slower than not (?)</title>
		<link>http://www.allegro.cc/forums/view/616537</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 18 Oct 2016 11:53:03 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Im trying to draw text and primitives to the screen.</p><p>This is my current drawing function:</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span>
<span class="number">  2</span><a href="http://www.allegro.cc/manual/ALLEGRO_VERTEX"><span class="a">ALLEGRO_VERTEX</span></a> <span class="k3">*</span>vertices<span class="k2">;</span>
<span class="number">  3</span>
<span class="number">  4</span><span class="c">// ... calculate triangle points and save them to "vertices";</span>
<span class="number">  5</span>
<span class="number">  6</span><a href="http://www.allegro.cc/manual/al_clear_to_color"><span class="a">al_clear_to_color</span></a><span class="k2">(</span>BACKGROUND_COLOR<span class="k2">)</span><span class="k2">;</span>
<span class="number">  7</span>
<span class="number">  8</span><a href="http://www.allegro.cc/manual/al_lock_bitmap"><span class="a">al_lock_bitmap</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_get_target_bitmap"><span class="a">al_get_target_bitmap</span></a><span class="k2">(</span><span class="k2">)</span>, ALLEGRO_PIXEL_FORMAT_ANY, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span> <span class="c">// The current target bitmap is the display back buffer</span>
<span class="number">  9</span>
<span class="number"> 10</span><a href="http://www.allegro.cc/manual/al_draw_prim"><span class="a">al_draw_prim</span></a><span class="k2">(</span>vertices, null, null, <span class="n">0</span>, size, ALLEGRO_PRIM_TRIANGLE_LIST<span class="k2">)</span><span class="k2">;</span> <span class="c">// Draw triangles</span>
<span class="number"> 11</span><a href="http://www.allegro.cc/manual/al_draw_filled_rectangle"><span class="a">al_draw_filled_rectangle</span></a><span class="k2">(</span><span class="n">600</span>, <span class="n">0</span>, <span class="n">660</span>, <span class="n">660</span>, <a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a><span class="k2">(</span><span class="n">255</span>,<span class="n">255</span>,<span class="n">255</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span> <span class="c">// Draw a rectangle</span>
<span class="number"> 12</span>
<span class="number"> 13</span><a href="http://www.allegro.cc/manual/al_unlock_bitmap"><span class="a">al_unlock_bitmap</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_get_target_bitmap"><span class="a">al_get_target_bitmap</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 14</span>
<span class="number"> 15</span><a href="http://www.allegro.cc/manual/al_draw_text"><span class="a">al_draw_text</span></a><span class="k2">(</span>myfont, BLACK, <span class="n">10</span>, <span class="n">10</span>, ALLEGRO_ALIGN_LEFT, <span class="s">"TESTING"</span><span class="k2">)</span><span class="k2">;</span>
</div></div><p>

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 !</p><p>I must be doing something terrible wrong with my drawing process (?). What&#39;s the correct order to draw and lock the bitmap ?.</p><p>Furthermore, why cant I clear the display with al_clear_to_color or write text to it when it is locked ?</p><p>Thanks a lot.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Ediolot)</author>
		<pubDate>Sun, 16 Oct 2016 22:35:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Short answer is, you don&#39;t need to lock the bitmap except for direct memory access, and you shouldn&#39;t.</p><div class="quote_container"><div class="title"><a href="http://liballeg.org/a5docs/trunk/graphics.html#al_lock_bitmap">The Manual : Graphics</a> said:</div><div class="quote"><p>
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).
</p></div></div><p>

Basically, Allegro will lock the bitmap when it needs to, so you don&#39;t have to worry about it yourself, unless you&#39;re doing a lot of direct memory access.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Mon, 17 Oct 2016 00:29:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What you might be confusing locking the bitmap with is <i>holding</i> the bitmap drawing as per <a href="https://www.allegro.cc/manual/5/al_hold_bitmap_drawing">https://www.allegro.cc/manual/5/al_hold_bitmap_drawing</a>. 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.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (beoran)</author>
		<pubDate>Mon, 17 Oct 2016 01:20:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Here is a link for the discussion catcher (one of the cooleset, most under-rated features of these forums):  <span class="source-code"><a href="http://www.allegro.cc/manual/al_hold_bitmap_drawing"><span class="a">al_hold_bitmap_drawing</span></a></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Gideon Weems)</author>
		<pubDate>Mon, 17 Oct 2016 15:46:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yep. I only lock bitmaps when I specifically use al_get_pixel or al_put_pixel <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Felix-The-Ghost)</author>
		<pubDate>Tue, 18 Oct 2016 11:53:03 +0000</pubDate>
	</item>
</rss>
