<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>[A5] Bitmap locking</title>
		<link>http://www.allegro.cc/forums/view/607254</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sun, 08 May 2011 12:20:45 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hey folks,</p><p>I have these questions about Allegro 5&#39;s <tt>al_lock_bitmap</tt> and <tt>al_unlock_bitmap</tt>, which I couldn&#39;t answer by reading the manual and wiki.</p><p>1. Does locking in a readable mode simply mean to copy a bitmap into RAM, or is there more to it? (Unlocking will do different things, based on whether the lock was read-only.) If so, does locking/unlocking a memory bitmap do anything at all?</p><p>2. Assume I have a video bitmap, onto which I wish to blit several other video bitmaps. I won&#39;t use any drawing primitives here. Which of these bitmaps should I lock for best performance?</p><p>3. If I lock the same bitmap several times (might happen write-only or readwrite), is that hazardous or taxing on performance? What will happen if I unlock it too many times? <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /></p><p>These questions arise as I&#39;m porting my game from A4 to A5. I was only using memory bitmaps in A4, which likely hasn&#39;t ever been a great idea, and I wish to do a cleaner job in A5.</p><p>-- Simon
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SimonN)</author>
		<pubDate>Sat, 07 May 2011 19:46:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>1. Yes. Locking a memory bitmap does nothing.</p><p>2. You should lock none of them.</p><p>3. You cannot lock a locked bitmap again if that&#39;s what you meant. And both locking (for reading) and un-locking (for writing) will be extremely slow.</p><p>Basically, locking is required to copy data from memory to a video bitmap, so is used internally by e.g. al_load_bitmap (with OpenGL, it will translate to e.g. glTexImage2d). Other than that you should mostly avoid it. Taking a screenshot would require locking the screen (translates to e.g. glReadPixels with OpenGL). Also for things like streaming a video you may have to lock a bitmap for writing.</p><p>But in any other cases where you think you need locking it&#39;s likely much faster to not use it. Especially for per-pixel manipulations you should use shaders.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Sat, 07 May 2011 20:54:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks, this has helped to think about its benefits and pitfalls. Yes, for #3, I meant locking an already locked bitmap.</p><p>I&#39;ll continue to play around, and think about shader usage where appropriate.</p><p>-- Simon
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SimonN)</author>
		<pubDate>Sun, 08 May 2011 12:20:45 +0000</pubDate>
	</item>
</rss>
