<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Is there a fast way to copy memory to bitmap?</title>
		<link>http://www.allegro.cc/forums/view/616107</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 08 Mar 2016 22:39:18 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>This relates to the map in the game. The map consists of 32X32 segments, each of them are updated and stored in an 32X32 array of four bytes (rgba).</p><p>When any of the segment is changed or created, it needs to create it&#39;s video sprite and setup it&#39;s contents based on the array of data, so it can be actually drawn when the map is displayed. This tasks is quite slow, and the best improvement I have done (long time ago), was to find biggest set of squares and draw to the bitmap these instead of drawing pixel by pixel.</p><p>I&#39;m looking for a way, to directly copy the raw sprite data to the allegro structures, so they are updated in one operation, which would most probably fasten the process a lot.</p><p>Thank you for any advice.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kovarex)</author>
		<pubDate>Tue, 08 Mar 2016 16:03:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Don&#39;t know exactly what you&#39;re looking for, but I think bitmap locking and accessing data via ALLEGRO_LOCKED_REGION is the fastest way. Be sure to pass ALLEGRO_LOCK_WRITEONLY to al_lock_bitmap, so as to avoid reading texture data.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Polybios)</author>
		<pubDate>Tue, 08 Mar 2016 21:09:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The slow part is not copying from your structure to the Allegro structure, it is fetching the video bitmap from the graphics card and putting it into main memory for manipulation, then sending back your changes to the graphics card. This was not a problem in the old days of software rendering, but it is in hardware rendering.</p><p>If it is possible, you will see significant speed increase from using a fragment shader to manipulate the bitmap. This avoids the travel cost.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jmasterx)</author>
		<pubDate>Tue, 08 Mar 2016 21:55:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Assuming he&#39;s talking about Factorio:</p><p>You have this game world, split into large chunks:</p><p><span class="remote-thumbnail"><span class="json">{"name":"fr-minecraft_map_5YPD_file.jpg","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/1\/017db0d9af7e93645c1d2743b49661c6.jpg","w":900,"h":506,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/1\/017db0d9af7e93645c1d2743b49661c6"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/0/1/017db0d9af7e93645c1d2743b49661c6-240.jpg" alt="fr-minecraft_map_5YPD_file.jpg" width="240" height="134" /></span></p><p>You press the map button and it looks like this:</p><p><span class="remote-thumbnail"><span class="json">{"name":"hcwwTzG.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/a\/bab9b49124b578073072e690d51f79e0.png","w":1600,"h":860,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/a\/bab9b49124b578073072e690d51f79e0"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/b/a/bab9b49124b578073072e690d51f79e0-240.jpg" alt="hcwwTzG.png" width="240" height="129" /></span></p><p>Note the square edges. Those are chunks.</p><p>But without seeing the rendering pipeline, I agree with the two answers provided. It&#39;s most likely an issue copying to system RAM. You should definitely try to avoid system bitmaps for live updates at all cost. Shaders are insanely fast.</p><p>You&#39;d want to look into tutorials regarding &quot;Shader Rendering to Texture&quot;.</p><p>Someone built &quot;the <a href="https://codea.io/talk/discussion/2252/game-of-life-shader">Game of Life</a>&quot; into a texture (using every pixel!) and rendered it to a torus.</p><p><div class="media-player youtube"><div style="margin: 1em 2em; background: url(/images/movie.png); width: 180px; height: 100px; text-align: center;"><a href="http://www.allegro.cc//www.youtube.com/watch?v=tZTIiKcqdtI" target="_blank"><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/object/0/d/0d39307fb67a1ca382c1126efd523d1d.jpg" border="0" alt="video" title="Click to play video" /></a></div></div></p><p>And that&#39;s about as per-pixel as you can get.</p><p>One more possibility. Thinking about this from the time axis. Assuming you&#39;re talking about that map and scanning every piece on a chunk. How much of that map needs to be updated in real-time? Can a particular chuck update be &quot;deferred&quot; across multiple frames? I can&#39;t remember, does the map show live movement of &quot;alien attacks&quot;? If not, a &quot;chunk parse&quot; could certainly cross a few frames and still &quot;appear&quot; instant to a user if that one piece is dragging the FPS down.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Chris Katko)</author>
		<pubDate>Tue, 08 Mar 2016 22:39:18 +0000</pubDate>
	</item>
</rss>
