<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>al_draw_bitmap faster on backbuffer than on another bitmap?</title>
		<link>http://www.allegro.cc/forums/view/608893</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Fri, 25 Nov 2011 21:48:07 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>First of all, hello everyone.<br />I have recently began building a simple tile engine with learning purposes, and have implemented a simple layered-tile-map drawing function (Code below), which had a rather large flaw: It built the map on each frame instead of drawing the tile layers on a persisting Bitmap which could then be used for updates.</p><p>When I tried to implement this (I.E. Using a bitmap to store the generated map image and then draw this on the backbuffer on all successive updates), I noticed things worked great as long as I stuck with really small maps, but when I tried larger maps (50x50) everything went to hell. The initial building of the map into the buffer bitmap took around 4 minutes, whereas drawing it on each frame into the backbuffer as done previously took a few seconds (Which was the reason why I tried to improve its performance by only drawing it once).</p><p>Is it possible that drawing on an ALLEGRO_BITMAP is a LOT slower than drawing on the backbuffer?<br />If so, any suggestions on how I can improve my 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="k1">void</span> CTileMap::paint<span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_DISPLAY"><span class="a">ALLEGRO_DISPLAY</span></a> <span class="k3">*</span>display<span class="k2">)</span>
<span class="number">  2</span><span class="k2">{</span>
<span class="number">  3</span>  <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span>m_bmpMapBuffer<span class="k2">)</span> <span class="k2">{</span>
<span class="number">  4</span>    TileCoord tc<span class="k2">;</span>
<span class="number">  5</span>    TileGrid <span class="k3">*</span>tgTiles <span class="k3">=</span> NULL<span class="k2">;</span>
<span class="number">  6</span>    CLayer <span class="k3">*</span>lyrCurrentLayer <span class="k3">=</span> NULL<span class="k2">;</span>
<span class="number">  7</span>    CTileset <span class="k3">*</span>tlsCurrentTileset <span class="k3">=</span> NULL<span class="k2">;</span>
<span class="number">  8</span>    CTilesetImg <span class="k3">*</span>tliPalette <span class="k3">=</span> NULL<span class="k2">;</span>
<span class="number">  9</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>bmpMesh <span class="k3">=</span> NULL<span class="k2">;</span>
<span class="number"> 10</span>    <span class="k1">int</span> nTileIndex<span class="k2">;</span>
<span class="number"> 11</span>  <span class="c">//      int nTranspColor;</span>
<span class="number"> 12</span>
<span class="number"> 13</span>    m_bmpMapBuffer <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_bitmap"><span class="a">al_create_bitmap</span></a><span class="k2">(</span>m_nWidth <span class="k3">*</span> m_nTileWidth, m_nHeight <span class="k3">*</span> m_nTileHeight<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 14</span>    <span class="c">//al_set_target_bitmap(al_get_backbuffer(display));</span>
<span class="number"> 15</span>    <a href="http://www.allegro.cc/manual/al_set_target_bitmap"><span class="a">al_set_target_bitmap</span></a><span class="k2">(</span>m_bmpMapBuffer<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 16</span>
<span class="number"> 17</span>    <span class="c">// Iterate through the layers from bottom to top painting each one</span>
<span class="number"> 18</span>    <span class="k1">for</span> <span class="k2">(</span>LayerVector::iterator itLayer <span class="k3">=</span> m_vLayers.begin<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> itLayer <span class="k3">!</span><span class="k3">=</span> m_vLayers.end<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> <span class="k3">+</span><span class="k3">+</span>itLayer<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 19</span>      lyrCurrentLayer <span class="k3">=</span> <span class="k2">(</span><span class="k3">*</span>itLayer<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 20</span>
<span class="number"> 21</span>      tgTiles <span class="k3">=</span> lyrCurrentLayer-&gt;getTileGrid<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 22</span>
<span class="number"> 23</span>      <span class="c">// Iterate through the rows of the current layer</span>
<span class="number"> 24</span>      <span class="k1">for</span> <span class="k2">(</span><span class="k1">int</span> x <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> x <span class="k3">&lt;</span> lyrCurrentLayer-&gt;getWidth<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> x<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span>
<span class="number"> 25</span>      <span class="k2">{</span>
<span class="number"> 26</span>        tc.x <span class="k3">=</span> x<span class="k2">;</span>
<span class="number"> 27</span>
<span class="number"> 28</span>        <span class="c">// Iterate through the columns of the current row of the layer</span>
<span class="number"> 29</span>        <span class="k1">for</span> <span class="k2">(</span><span class="k1">int</span> y <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> y <span class="k3">&lt;</span> lyrCurrentLayer-&gt;getHeight<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> y<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span>
<span class="number"> 30</span>        <span class="k2">{</span>
<span class="number"> 31</span>          tc.y <span class="k3">=</span> y<span class="k2">;</span>
<span class="number"> 32</span>
<span class="number"> 33</span>          <span class="c">// If the coordinate has no Tile element, skip to the next</span>
<span class="number"> 34</span>          <span class="k1">if</span> <span class="k2">(</span>tgTiles-&gt;find<span class="k2">(</span>tc<span class="k2">)</span> <span class="k3">=</span><span class="k3">=</span> tgTiles-&gt;end<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 35</span>            <span class="k1">continue</span><span class="k2">;</span>
<span class="number"> 36</span>          <span class="k2">}</span>
<span class="number"> 37</span>
<span class="number"> 38</span>          nTileIndex <span class="k3">=</span> tgTiles-&gt;at<span class="k2">(</span>tc<span class="k2">)</span><span class="k3">-</span><span class="k3">&gt;</span>getTileIndex<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 39</span>
<span class="number"> 40</span>          <span class="c">// Iterate backwards through the available tilesets for the map in order to find the one corresponding to the current GId</span>
<span class="number"> 41</span>          <span class="k1">for</span> <span class="k2">(</span>TilesetVector::reverse_iterator itTileset <span class="k3">=</span> m_vTilesets.rbegin<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> itTileset <span class="k3">!</span><span class="k3">=</span> m_vTilesets.rend<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> <span class="k3">+</span><span class="k3">+</span>itTileset<span class="k2">)</span>
<span class="number"> 42</span>          <span class="k2">{</span>
<span class="number"> 43</span>            tlsCurrentTileset <span class="k3">=</span> <span class="k2">(</span><span class="k3">*</span>itTileset<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 44</span>
<span class="number"> 45</span>            <span class="c">// If the GId is within the current tileset, draw it</span>
<span class="number"> 46</span>            <span class="k1">if</span> <span class="k2">(</span>nTileIndex <span class="k3">&gt;</span><span class="k3">=</span> tlsCurrentTileset-&gt;getFirstGId<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 47</span>              tliPalette <span class="k3">=</span> tlsCurrentTileset-&gt;getTilePalette<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 48</span>
<span class="number"> 49</span>              bmpMesh <span class="k3">=</span> tliPalette-&gt;getImage<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 50</span>              
<span class="number"> 51</span>
<span class="number"> 52</span>              <a href="http://www.allegro.cc/manual/al_draw_bitmap_region"><span class="a">al_draw_bitmap_region</span></a><span class="k2">(</span>bmpMesh,
<span class="number"> 53</span>                      tlsCurrentTileset-&gt;getTileX<span class="k2">(</span>nTileIndex<span class="k2">)</span>,
<span class="number"> 54</span>                      tlsCurrentTileset-&gt;getTileY<span class="k2">(</span>nTileIndex<span class="k2">)</span>,
<span class="number"> 55</span>                      tlsCurrentTileset-&gt;getTileW<span class="k2">(</span><span class="k2">)</span>,
<span class="number"> 56</span>                      tlsCurrentTileset-&gt;getTileH<span class="k2">(</span><span class="k2">)</span>,
<span class="number"> 57</span>                      <span class="k2">(</span>m_nTileWidth <span class="k3">*</span> x<span class="k2">)</span>, <span class="k2">(</span>m_nTileHeight <span class="k3">*</span> y<span class="k2">)</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 58</span>
<span class="number"> 59</span>              <span class="c">// End the loop in order to avoid the tile from being overwritten by an empty image</span>
<span class="number"> 60</span>              <span class="k1">break</span><span class="k2">;</span>
<span class="number"> 61</span>            <span class="k2">}</span>
<span class="number"> 62</span>          <span class="k2">}</span>
<span class="number"> 63</span>        <span class="k2">}</span>
<span class="number"> 64</span>      <span class="k2">}</span>
<span class="number"> 65</span>    <span class="k2">}</span>
<span class="number"> 66</span>  <span class="k2">}</span>
<span class="number"> 67</span>  <a href="http://www.allegro.cc/manual/al_set_target_bitmap"><span class="a">al_set_target_bitmap</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_get_backbuffer"><span class="a">al_get_backbuffer</span></a><span class="k2">(</span>display<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 68</span>  <a href="http://www.allegro.cc/manual/al_draw_bitmap"><span class="a">al_draw_bitmap</span></a><span class="k2">(</span>m_bmpMapBuffer, <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 69</span><span class="k2">}</span>
</div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Dash125)</author>
		<pubDate>Thu, 24 Nov 2011 02:56:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608893/938311#target">Dash125</a> said:</div><div class="quote"><p>
When I tried to implement this (I.E. Using a bitmap to store the generated map image and then draw this on the backbuffer on all successive updates), I noticed things worked great as long as I stuck with really small maps, but when I tried larger maps (50x50) everything went to hell. The initial building of the map into the buffer bitmap took around 4 minutes, whereas drawing it on each frame into the backbuffer as done previously took a few seconds (Which was the reason why I tried to improve its performance by only drawing it once).
</p></div></div><p>
If your buffer bitmap was 50x50 tiles, then it could easily have exceeded the size limit of video bitmaps on your hardware and become a memory bitmap. If it was, and you then tried to draw your video bitmap tiles onto a memory bitmap it would have been horrendously slow due to reading from video memory and writing back to regular memory.</p><p>I think your best bet is to a single tile sheet in video memory and create your tiles as sub bitmaps of this sheet. Then when you draw your tile map use <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> before and after you draw all of your sub bitmap tiles.</p><p>The main problem is probably due to memory bitmaps being in use somewhere.</p><p><b>Edit</b></p><p>After looking at your code, you are creating a bitmap (likely a memory bitmap) on every drawing frame and then drawing that to your backbuffer. You don&#39;t want to create and redraw the background buffer on every frame. That defeats the purpose of pre drawing it. You&#39;re better off drawing directly to the backbuffer every frame, using sub bitmaps instead of drawing regions, and drawing all the sub bitmaps that share a common parent at the same time if you can.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Thu, 24 Nov 2011 03:01:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608893/938312#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>After looking at your code, you are creating a bitmap (likely a memory bitmap) on every drawing frame and then drawing that to your backbuffer. You don&#39;t want to create and redraw the background buffer on every frame. That defeats the purpose of pre drawing it. You&#39;re better off drawing directly to the backbuffer every frame, using sub bitmaps instead of drawing regions, and drawing all the sub bitmaps that share a common parent at the same time if you can.</p></div></div><p>
Actually, I&#39;m only drawing the memory bitmap only once: <i>m_bmpMapBuffer</i> is a class member, and is initialized as NULL when the object is created, and will be created only once (Hence the null check at the beginning of the function), and will remain alive as long as the object lives.</p><div class="quote_container"><div class="title">Edgar Reynaldo said:</div><div class="quote"><p>If your buffer bitmap was 50x50 tiles, then it could easily have exceeded the size limit of video bitmaps on your hardware and become a memory bitmap. If it was, and you then tried to draw your video bitmap tiles onto a memory bitmap it would have been horrendously slow due to reading from video memory and writing back to regular memory.</p><p>I think your best bet is to a single tile sheet in video memory and create your tiles as sub bitmaps of this sheet. Then when you draw your tile map use al_hold_bitmap_drawing before and after you draw all of your sub bitmap tiles.</p><p>The main problem is probably due to memory bitmaps being in use somewhere.</p></div></div><p>
A few questions on this, since I&#39;m quite a newbie on both Allegro and game development from scratch:<br />- How can I can tell if a bitmap I declared lives in video memory or regular memory? (I thought that was automatically handled by Allegro).<br />- The buffer bitmap being created on my method is 800x800px (16x16 px per tile), but according to al_get_display_option(display, ALLEGRO_MAX_BITMAP_SIZE), the maximum size for bitmaps is 4096. How is this possible?</p><p>Just in case, I will briefly describe the map circuit, since maybe my error is deeper than just the drawing code <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>- The map is parsed and all pertinent objects are generated and initialized.<br />- The tile sheet is loaded as an ALLEGRO_BITMAP.<br />- When the paint method is called, I check if the buffer bitmap has been created.<br />- If the buffer bitmap has not been created, I get the tile bitmap from the tilesheet and draw it onto the buffer bitmap (previously it was done on the backbuffer directly) for each tile of each layer.<br />- Once I&#39;m sure the buffer bitmap exists, I draw it onto the backbuffer.</p><p>(I know you can deduce most of this from my code, but I guess it can&#39;t harm to add all the information I have)</p><p><b>edit: I just added the al_hold_bitmap_drawing to the method, and after some reading, set all bitmaps to be video bitmaps by default, and found no changes whatsoever</b>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Dash125)</author>
		<pubDate>Thu, 24 Nov 2011 06:27:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><b><i>Major Edit</i></b>
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608893/938335#target">Dash125</a> said:</div><div class="quote"><p>
Actually, I&#39;m only drawing the memory bitmap only once: m_bmpMapBuffer is a class member, and is initialized as NULL when the object is created, and will be created only once (Hence the null check at the beginning of the function), and will remain alive as long as the object lives.
</p></div></div><p>
I totally missed the <span class="source-code"><span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span>m_bmpMapBuffer<span class="k2">)</span> <span class="k2">{</span></span> line. <img src="http://www.allegro.cc/forums/smileys/embarassed.gif" alt=":-[" /><img src="http://www.allegro.cc/forums/smileys/embarassed.gif" alt=":-[" /><img src="http://www.allegro.cc/forums/smileys/embarassed.gif" alt=":-[" /></p><p><s>Well, it doesn&#39;t look like you are buffering properly at all. Your paint method does this :</s>
</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>paint<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number">  2</span>   create_buffer<span class="k2">(</span><span class="k2">)</span>
<span class="number">  3</span>   set_target<span class="k2">(</span>buffer<span class="k2">)</span>
<span class="number">  4</span>   <span class="k1">for</span> each layer
<span class="number">  5</span>      <span class="k1">for</span> each column x
<span class="number">  6</span>         <span class="k1">for</span> each row y
<span class="number">  7</span>            <span class="k1">if</span> <span class="k2">(</span>Tiles-&gt;find<span class="k2">(</span>Tile<span class="k2">(</span>x,y<span class="k2">)</span><span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span><span class="k1">goto</span> next y<span class="k2">}</span>
<span class="number">  8</span>            reverse <span class="k1">for</span> each tileset tls
<span class="number">  9</span>               <span class="k1">if</span> <span class="k2">(</span>tls.contains<span class="k2">(</span>tileindex<span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 10</span>                  draw_bitmap_region<span class="k2">(</span>tileset-&gt;get_palette<span class="k2">(</span><span class="k2">)</span><span class="k3">-</span><span class="k3">&gt;</span>get_image<span class="k2">(</span><span class="k2">)</span>,....<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 11</span>                  <span class="k1">break</span> <span class="k1">for</span> each tileset
<span class="number"> 12</span>               <span class="k2">}</span>
<span class="number"> 13</span>            end <span class="k1">for</span>
<span class="number"> 14</span>         end <span class="k1">for</span>
<span class="number"> 15</span>      end <span class="k1">for</span>
<span class="number"> 16</span>   end <span class="k1">for</span>
<span class="number"> 17</span>   set_target<span class="k2">(</span>allegro_backbuffer<span class="k2">)</span>
<span class="number"> 18</span>   draw<span class="k2">(</span>buffer<span class="k2">)</span>
<span class="number"> 19</span><span class="k2">}</span>
</div></div><p>
<s>If you are calling that every time you need to draw your tilemap, then your buffer is completely wasted and unnecessary and you should have drawn to allegro&#39;s backbuffer instead. Your paint method also leaks your buffer bitmap every time you call it.</s></p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
- How can I can tell if a bitmap I declared lives in video memory or regular memory? (I thought that was automatically handled by Allegro).
</p></div></div><p>
Use <span class="source-code"><a href="http://www.allegro.cc/manual/al_get_bitmap_flags"><span class="a">al_get_bitmap_flags</span></a></span> to check what properties the bitmap has. Use <span class="source-code"><a href="http://www.allegro.cc/manual/al_set_new_bitmap_flags"><span class="a">al_set_new_bitmap_flags</span></a></span> to tell allegro what kind of bitmap to create when you create or clone a new bitmap. I don&#39;t know what the default kind of bitmap is anymore, but I thought it would be a &#39;fail if unsuccessful video bitmap&#39;.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
- The buffer bitmap being created on my method is 800x800px (16x16 px per tile), but according to al_get_display_option(display, ALLEGRO_MAX_BITMAP_SIZE), the maximum size for bitmaps is 4096. How is this possible?
</p></div></div><p>
As long as <span class="source-code"><a href="http://www.allegro.cc/manual/al_get_new_bitmap_flags"><span class="a">al_get_new_bitmap_flags</span></a><span class="k2">(</span><span class="k2">)</span> <span class="k3">&amp;</span> ALLEGRO_VIDEO_BITMAP</span> is true, it should be making a video bitmap for you, especially if it is only 800x800.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
- When the paint method is called, I check if the buffer bitmap has been created.<br />- If the buffer bitmap has not been created, I get the tile bitmap from the tilesheet and draw it onto the buffer bitmap (previously it was done on the backbuffer directly) for each tile of each layer.<br />- Once I&#39;m sure the buffer bitmap exists, I draw it onto the backbuffer.
</p></div></div><p>
<s>That&#39;s not what the code you showed me does, unless you really only call paint once, and you have some other method that draws the buffer to the allegro back buffer. (In which case, why have paint draw onto the backbuffer, and not just call &lt;code&gt;paint();displaybuffer();&lt;/code&gt;).</s></p><p>Ideally, I would do something like this (<b>Edit</b> - he already is) :
</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="k1">class</span> TileMap <span class="k2">{</span>
<span class="number">  2</span><span class="k1">public</span> <span class="k2">:</span>
<span class="number">  3</span>   <span class="k1">void</span> Display<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number">  4</span>      <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span>buffer_drawn<span class="k2">)</span> <span class="k2">{</span>DrawBuffer<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span><span class="k2">}</span>
<span class="number">  5</span>      <a href="http://www.allegro.cc/manual/al_set_target_bitmap"><span class="a">al_set_target_bitmap</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_get_backbuffer"><span class="a">al_get_backbuffer</span></a><span class="k2">(</span>display<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  6</span>      <a href="http://www.allegro.cc/manual/al_draw_bitmap"><span class="a">al_draw_bitmap</span></a><span class="k2">(</span>buffer , <span class="k3">-</span>camerax , <span class="k3">-</span>cameray , <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  7</span>   <span class="k2">}</span>
<span class="number">  8</span>   <span class="k1">void</span> DrawBuffer<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number">  9</span>      <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span>buffer<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 10</span>         buffer <span class="k3">=</span> MakeBuffer<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 11</span>      <span class="k2">}</span>
<span class="number"> 12</span>      <span class="c">// draw tile map onto buffer</span>
<span class="number"> 13</span>      buffer_drawn <span class="k3">=</span> <span class="k1">true</span><span class="k2">;</span>
<span class="number"> 14</span>   <span class="k2">}</span>
<span class="number"> 15</span><span class="k2">}</span><span class="k2">;</span>
</div></div><p>

I am still not sure what you did to make it take 4 minutes, or even several seconds to draw unless memory bitmaps were involved somehow.</p><p><b>Edit</b>
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
edit: I just added the al_hold_bitmap_drawing to the method, and after some reading, set all bitmaps to be video bitmaps by default, and found no changes whatsoever
</p></div></div><p>
If the tile bitmaps don&#39;t share a common parent (like a sub bitmap would, like I recommended earlier), then <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> probably won&#39;t do much for you.</p><p>What graphics card are you using?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Thu, 24 Nov 2011 09:16:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I found the four minute problem: I had a batch of test map files which I had built using Tiled (The editor I chose for this project), and at some point must have renamed one that should never have made on this test in the first place (It was 50x50, but had an extremely large amount of layers). I replaced it by the one that should have been on the test (four 50x50 layers), and re-tested. The whole thing took around 1:12 minutes to draw the map buffer. (Sorry about the mix-up!)</p><p>Since the tile sheet is on a single bitmap, and the map buffer is built by painting bits of the tile sheet onto it, I added the al_hold_bitmap_drawing before starting the loop and after finishing it. (Is this what you mean by parent bitmap?)</p><p><s>I also set the bitmaps to be video by default, and the result was the same...</s></p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608893/938343#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>As long as al_get_new_bitmap_flags() &amp; ALLEGRO_VIDEO_BITMAP is true, it should be making a video bitmap for you, especially if it is only 800x800.</p></div></div><p>
<s>I&#39;ve just checked this, and found (to my horror) that they are all memory bitmaps! It seems my al_set_new_bitmap_flags line is being completely ignored, which causing the whole problem...</s></p><p><s><b>EDIT:</b>
I&#39;ve just tried creating the bitmap on the main() which is where I create the display, and the result is a video bitmap!
How is it possible that the Bitmaps created within the classes of my project are not respecting the video bitmap setting, whereas the ones being created on the main method are respecting it?

Here&#39;s a pseudocode-ish example of what I mean to clarify:</s>
</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="k1">int</span> main<span class="k2">(</span><span class="k1">int</span> argc, <span class="k1">char</span> <span class="k3">*</span><span class="k3">*</span>argv<span class="k2">)</span>
<span class="number">  2</span><span class="k2">{</span>
<span class="number">  3</span>  <span class="c">// Initialize allegro and do stuff</span>
<span class="number">  4</span>  <span class="c">// ...</span>
<span class="number">  5</span>  <span class="c">// Create display</span>
<span class="number">  6</span>  <span class="c">// ...</span>
<span class="number">  7</span>  <a href="http://www.allegro.cc/manual/al_set_target_backbuffer"><span class="a">al_set_target_backbuffer</span></a><span class="k2">(</span>display<span class="k2">)</span><span class="k2">;</span>
<span class="number">  8</span>  <a href="http://www.allegro.cc/manual/al_set_new_bitmap_flags"><span class="a">al_set_new_bitmap_flags</span></a><span class="k2">(</span>ALLEGRO_VIDEO_BITMAP<span class="k2">)</span><span class="k2">;</span>
<span class="number">  9</span>
<span class="number"> 10</span>  <span class="c">// Load a bitmap</span>
<span class="number"> 11</span>  <span class="c">// This is created as a VIDEO BITMAP</span>
<span class="number"> 12</span>  <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>bitmap <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_bitmap"><span class="a">al_load_bitmap</span></a><span class="k2">(</span><span class="s">"tilesetTest.png"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</span>
<span class="number"> 14</span>  <span class="c">// Create an object with a bitmap attribute</span>
<span class="number"> 15</span>  MyClass mc<span class="k2">;</span>
<span class="number"> 16</span>
<span class="number"> 17</span>  <span class="c">// Create the same bitmap as before inside the init() method</span>
<span class="number"> 18</span>  <span class="c">// This is created as a MEMORY BITMAP</span>
<span class="number"> 19</span>  mc.init<span class="k2">(</span><span class="s">"tilesetTest.png"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 20</span><span class="k2">}</span>
<span class="number"> 21</span>
<span class="number"> 22</span><span class="k1">class</span> MyClass <span class="k2">{</span>
<span class="number"> 23</span>public:
<span class="number"> 24</span>  MyClass<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span> bmp <span class="k3">=</span> NULL<span class="k2">;</span> <span class="k2">}</span>
<span class="number"> 25</span>  ~MyClass<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span> <span class="k1">if</span> <span class="k2">(</span>bmp<span class="k2">)</span> <span class="k2">{</span> <a href="http://www.allegro.cc/manual/al_destroy_bitmap"><span class="a">al_destroy_bitmap</span></a><span class="k2">(</span>bmp<span class="k2">)</span><span class="k2">;</span> <span class="k2">}</span> <span class="k2">}</span>
<span class="number"> 26</span>
<span class="number"> 27</span>  <span class="k1">void</span> init<span class="k2">(</span><span class="k1">char</span> <span class="k3">*</span>bitmapPath<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 28</span>    bmp <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_bitmap"><span class="a">al_load_bitmap</span></a><span class="k2">(</span>bitmapPath<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 29</span>  <span class="k2">}</span>
<span class="number"> 30</span>
<span class="number"> 31</span>  <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span> getBmp<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span> <span class="k1">return</span> bmp<span class="k2">;</span> <span class="k2">}</span>
<span class="number"> 32</span>
<span class="number"> 33</span>private:
<span class="number"> 34</span>  <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>bmp<span class="k2">;</span>
<span class="number"> 35</span><span class="k2">}</span>
</div></div><p>

<s>I&#39;m quite lost here... Shouldn&#39;t both bitmaps be created using the same settings? ???</s></p><p><b>LAST EDIT</b></p><p>The only thing I&#39;m still not sure of is this:</p><p>If I use the tile sheet bitmap to draw the tiles onto the map buffer, is it right to use al_hold_bitmap_drawing?</p><p>Read my next post! <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Dash125)</author>
		<pubDate>Thu, 24 Nov 2011 20:26:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608893/938392#target">Dash125</a> said:</div><div class="quote"><p>
Since the tile sheet is on a single bitmap, and the map buffer is built by painting bits of the tile sheet onto it, I added the al_hold_bitmap_drawing before starting the loop and after finishing it. (Is this what you mean by parent bitmap?)
</p></div></div><p>
I&#39;m not sure if al_draw_bitmap_region benefits from al_hold_bitmap_drawing the way a sub bitmap would. You&#39;d have to ask the developers. I would think that it does, but I don&#39;t know. I don&#39;t think al_hold_bitmap_drawing would do anything for drawing memory bitmaps though, and that may be why you didn&#39;t see any difference.</p><div class="quote_container"><div class="title">Dash125 said:</div><div class="quote"><p>
I&#39;ve just tried creating the bitmap on the main() which is where I create the display, and the result is a video bitmap!<br />How is it possible that the Bitmaps created within the classes of my project are not respecting the video bitmap setting, whereas the ones being created on the main method are respecting it?
</p></div></div><p>
Are you calling your init method before the display has been created? You can&#39;t make a video bitmap without having a display to attach it to. There was some mention of auto converting memory bitmaps with the ALLEGRO_VIDEO_BITMAP flag to video bitmaps upon creating a display, but I don&#39;t know if that is the default or if it is in the current version of Allegro yet.</p><p>Are you making your objects in a different thread? You can&#39;t make video bitmaps in a secondary thread unless it also creates another display.</p><div class="quote_container"><div class="title">Dash125 said:</div><div class="quote"><p>
I&#39;m quite lost here... Shouldn&#39;t both bitmaps be created using the same settings? 
</p></div></div><p>
Assuming you create them in the same thread as your display, you create them after your display, and you either don&#39;t call al_set_new_bitmap_flags, or you call it with ALLEGRO_VIDEO_BITMAP, then yes they should be. Make sure they are with <span class="source-code"><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_get_bitmap_flags"><span class="a">al_get_bitmap_flags</span></a><span class="k2">(</span>bitmap<span class="k2">)</span> <span class="k3">&amp;</span> ALLEGRO_VIDEO_BITMAP<span class="k2">)</span></span></p><p>Which version of A5 are you using?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Fri, 25 Nov 2011 02:00:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It turns out I wrote the conditional to check the bitmap flags wrong ( <img src="http://www.allegro.cc/forums/smileys/embarassed.gif" alt=":-[" /> <img src="http://www.allegro.cc/forums/smileys/embarassed.gif" alt=":-[" /> <img src="http://www.allegro.cc/forums/smileys/embarassed.gif" alt=":-[" /> ).</p><p>So, to bottom line it:</p><p>I used al_set_new_bitmap_flags to use all bitmaps as video bitmaps, and re-tested on release mode (I&#39;m using Visual Studio 2010) and everything worked like a charm. I even tested a 14 layers of 50x50 map, and took less than half a second to load and draw!
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608893/938426#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>Which version of A5 are you using?</p></div></div><p>
I&#39;m currently using Allegro 5.0.4 and 5.0.5</p><p>Also, I&#39;d like to thank you for both answering and following up on this, since it has helped me understand a lot better how Allegro works and is supposed to be used! <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Dash125)</author>
		<pubDate>Fri, 25 Nov 2011 21:48:07 +0000</pubDate>
	</item>
</rss>
