<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Speeding up drawing from a tile atlas.</title>
		<link>http://www.allegro.cc/forums/view/612620</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 22 May 2013 15:35:07 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Uusually when I have a question I can find an answer in the docs or on the forums because someone asked it before me, but now I&#39;m kind of stumped. I&#39;ve been browsing the forums looking for solutions for a while, and I&#39;m nearly positive the error is in my code and not the system because a few months I implemented something similar that had no performance issues at all using the same version of allegro (5.0.8).</p><p>I&#39;m drawing to the screen for a tile atlas, organized into an array of sub-bitmaps. It is extremely slow. Like, 15/16fps slow on windows and 26fps slow on Arch. This is on a machine that can run Battlefield 3 on Ultra at 60fps just to put in perspective exactly how wrong I went somewhere in my code.</p><p>I draw to the screen with this block
</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><a href="http://www.allegro.cc/manual/al_hold_bitmap_drawing"><span class="a">al_hold_bitmap_drawing</span></a><span class="k2">(</span><span class="k1">true</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  2</span><span class="k1">for</span> <span class="k2">(</span><span class="k1">int</span> i <span class="k3">=</span> x<span class="k2">;</span> i <span class="k3">&lt;</span> x <span class="k3">+</span> tiwi<span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span>
<span class="number">  3</span>        <span class="k1">for</span> <span class="k2">(</span><span class="k1">int</span> j <span class="k3">=</span> y<span class="k2">;</span> j <span class="k3">&lt;</span> y <span class="k3">+</span> tihi<span class="k2">;</span> j<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number">  4</span>                fg <span class="k3">=</span> ch-&gt;fore<span class="k2">[</span>i<span class="k2">]</span><span class="k2">[</span>j<span class="k2">]</span><span class="k2">;</span>
<span class="number">  5</span>                bg <span class="k3">=</span> ch-&gt;back<span class="k2">[</span>i<span class="k2">]</span><span class="k2">[</span>j<span class="k2">]</span><span class="k2">;</span>
<span class="number">  6</span>                block_draw<span class="k2">(</span>fg, bg, <span class="k2">(</span>i <span class="k3">-</span> x<span class="k2">)</span> <span class="k3">*</span> scale,
<span class="number">  7</span>                           <span class="k2">(</span>j <span class="k3">-</span> y<span class="k2">)</span> <span class="k3">*</span> scale, scale<span class="k2">)</span><span class="k2">;</span>
<span class="number">  8</span>        <span class="k2">}</span>
<span class="number">  9</span><a href="http://www.allegro.cc/manual/al_hold_bitmap_drawing"><span class="a">al_hold_bitmap_drawing</span></a><span class="k2">(</span><span class="k1">false</span><span class="k2">)</span><span class="k2">;</span>
</div></div><p>

x and y indicate position on the map, and tihi abbreviates &quot;tiles high&quot; (screen size) and tiwi abbreviates &quot;tiles wide&quot;. fg and bg are numbers, an id for what tile to draw, and then scale is the size to draw them at.</p><p>The function that calls is below.
</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> block_draw <span class="k2">(</span>block fg, block bg, <span class="k1">int</span> x, <span class="k1">int</span> y, <span class="k1">int</span> scale<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="k2">(</span>profiles<span class="k2">[</span>fg.id<span class="k2">]</span>.opacity <span class="k3">&lt;</span> BLOCK_OPAQUE<span class="k2">)</span> <span class="k3">&amp;</span><span class="k3">&amp;</span> bg.id<span class="k2">)</span> <span class="k2">{</span>
<span class="number">  4</span>                <a href="http://www.allegro.cc/manual/al_draw_scaled_bitmap"><span class="a">al_draw_scaled_bitmap</span></a><span class="k2">(</span>backs<span class="k2">[</span>bg.id<span class="k2">]</span>, <span class="n">0</span>, <span class="n">0</span>, BLOCK_SIZE,
<span class="number">  5</span>                                      BLOCK_SIZE, x, y, scale, scale, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  6</span>                <span class="k1">if</span> <span class="k2">(</span>fg.id<span class="k2">)</span>
<span class="number">  7</span>                        <a href="http://www.allegro.cc/manual/al_draw_tinted_scaled_bitmap"><span class="a">al_draw_tinted_scaled_bitmap</span></a><span class="k2">(</span>sprites<span class="k2">[</span>fg.id<span class="k2">]</span>,
<span class="number">  8</span>                                <a href="http://www.allegro.cc/manual/al_map_rgba_f"><span class="a">al_map_rgba_f</span></a><span class="k2">(</span><span class="n">1</span>, <span class="n">1</span>, <span class="n">1</span>, profiles<span class="k2">[</span>fg.id<span class="k2">]</span>.opacity<span class="k2">)</span>,
<span class="number">  9</span>                                <span class="n">0</span>, <span class="n">0</span>, BLOCK_SIZE, BLOCK_SIZE, x, y, scale,
<span class="number"> 10</span>                                scale, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 11</span>        <span class="k2">}</span> <span class="k1">else</span>
<span class="number"> 12</span>                <a href="http://www.allegro.cc/manual/al_draw_scaled_bitmap"><span class="a">al_draw_scaled_bitmap</span></a><span class="k2">(</span>sprites<span class="k2">[</span>fg.id<span class="k2">]</span>, <span class="n">0</span>, <span class="n">0</span>, BLOCK_SIZE,
<span class="number"> 13</span>                                      BLOCK_SIZE, x, y, scale, scale, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 14</span><span class="k2">}</span>
</div></div><p>

Currently all the blocks I&#39;ve been testing with go straight to the &quot;else&quot; clause in block_draw.</p><p>As for modes, I took some suggestions I found on the forums and implemented flags that should help.
</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> init <span class="k2">(</span><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><a href="http://www.allegro.cc/manual/al_init"><span class="a">al_init</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span>
<span class="number">  4</span>                <span class="k1">return</span> <span class="n">1</span><span class="k2">;</span>
<span class="number">  5</span>
<span class="number">  6</span>        <a href="http://www.allegro.cc/manual/al_init_image_addon"><span class="a">al_init_image_addon</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  7</span>        <a href="http://www.allegro.cc/manual/al_install_keyboard"><span class="a">al_install_keyboard</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  8</span>        <a href="http://www.allegro.cc/manual/al_init_font_addon"><span class="a">al_init_font_addon</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  9</span>        <a href="http://www.allegro.cc/manual/al_init_ttf_addon"><span class="a">al_init_ttf_addon</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 10</span>        <a href="http://www.allegro.cc/manual/al_set_new_display_flags"><span class="a">al_set_new_display_flags</span></a><span class="k2">(</span>ALLEGRO_OPENGL<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 11</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"> 12</span>
<span class="number"> 13</span>        <span class="k1">if</span> <span class="k2">(</span>enet_initialize<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span>
<span class="number"> 14</span>                <span class="k1">return</span> <span class="n">2</span><span class="k2">;</span>
<span class="number"> 15</span>
<span class="number"> 16</span>        <a href="http://www.delorie.com/djgpp/doc/libc/libc_52.html" target="_blank">atexit</a><span class="k2">(</span>enet_deinitialize<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 17</span>
<span class="number"> 18</span>        <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 19</span><span class="k2">}</span>
</div></div><p>

Without the ALLEGRO_OPENGL flag I was getting about a frame a minute, so that&#39;s really helpful.</p><p>The bitmaps called in block_draw are loaded with this.
</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">static</span> <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>sheet<span class="k2">;</span>
<span class="number">  2</span><span class="k1">static</span> <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>sprites<span class="k2">[</span>BLOCK_COUNT<span class="k2">]</span><span class="k2">;</span>
<span class="number">  3</span><span class="k1">static</span> <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>backs<span class="k2">[</span>BLOCK_COUNT<span class="k2">]</span><span class="k2">;</span>
<span class="number">  4</span>
<span class="number">  5</span>...
<span class="number">  6</span>
<span class="number">  7</span><span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span><span class="k2">(</span>sheet <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>name<span class="k2">)</span><span class="k2">)</span><span class="k2">)</span>
<span class="number">  8</span>        <span class="k1">return</span> <span class="n">1</span><span class="k2">;</span>
<span class="number">  9</span>
<span class="number"> 10</span><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>temp <span class="k3">=</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="number"> 11</span><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>map <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>BLOCK_COUNT <span class="k3">*</span> BLOCK_SIZE,
<span class="number"> 12</span>                                       BLOCK_SIZE <span class="k3">*</span> <span class="n">2</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</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>map<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 14</span><a href="http://www.allegro.cc/manual/al_draw_bitmap"><span class="a">al_draw_bitmap</span></a><span class="k2">(</span>sheet, <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"> 15</span><a href="http://www.allegro.cc/manual/al_draw_tinted_bitmap"><span class="a">al_draw_tinted_bitmap</span></a><span class="k2">(</span>sheet, <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">100</span>, <span class="n">100</span>, <span class="n">100</span><span class="k2">)</span>, <span class="n">0</span>, BLOCK_SIZE, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 16</span>
<span class="number"> 17</span><span class="k1">if</span> <span class="k2">(</span>temp<span class="k2">)</span>
<span class="number"> 18</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>temp<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 19</span>
<span class="number"> 20</span><a href="http://www.allegro.cc/manual/al_destroy_bitmap"><span class="a">al_destroy_bitmap</span></a><span class="k2">(</span>sheet<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 21</span>sheet <span class="k3">=</span> map<span class="k2">;</span>
<span class="number"> 22</span>
<span class="number"> 23</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_569.html" target="_blank">memset</a><span class="k2">(</span>sprites, <span class="n">0</span>, <span class="k1">sizeof</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span><span class="k2">)</span> <span class="k3">*</span> BLOCK_COUNT<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 24</span><span class="k1">for</span> <span class="k2">(</span><span class="k1">int</span> i <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> i <span class="k3">&lt;</span> BLOCK_COUNT<span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span>
<span class="number"> 25</span>        sprites<span class="k2">[</span>i<span class="k2">]</span> <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_sub_bitmap"><span class="a">al_create_sub_bitmap</span></a><span class="k2">(</span>sheet, i <span class="k3">*</span> BLOCK_SIZE, <span class="n">0</span>,
<span class="number"> 26</span>                                          BLOCK_SIZE, BLOCK_SIZE<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 27</span>
<span class="number"> 28</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_569.html" target="_blank">memset</a><span class="k2">(</span>backs, <span class="n">0</span>, <span class="k1">sizeof</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span><span class="k2">)</span> <span class="k3">*</span> BLOCK_COUNT<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 29</span><span class="k1">for</span> <span class="k2">(</span><span class="k1">int</span> i <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> i <span class="k3">&lt;</span> BLOCK_COUNT<span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span>
<span class="number"> 30</span>        backs<span class="k2">[</span>i<span class="k2">]</span> <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_sub_bitmap"><span class="a">al_create_sub_bitmap</span></a><span class="k2">(</span>sheet, i <span class="k3">*</span> BLOCK_SIZE,
<span class="number"> 31</span>                                        BLOCK_SIZE,
<span class="number"> 32</span>                                        BLOCK_SIZE, BLOCK_SIZE<span class="k2">)</span><span class="k2">;</span>
</div></div><p>

I am going to continue testing things I&#39;m reading in docs/forums, and I will post back on the thread if I find anything in case other people have this problem in the future.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Dakota West)</author>
		<pubDate>Mon, 20 May 2013 01:11:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Do you have the same performance problem if you use <span class="source-code"><a href="http://www.allegro.cc/manual/al_draw_bitmap_region"><span class="a">al_draw_bitmap_region</span></a></span> on the atlas instead of creating sub bitmaps? (You can use <span class="source-code"><a href="http://www.allegro.cc/manual/al_scale_transform"><span class="a">al_scale_transform</span></a></span>/<span class="source-code"><a href="http://www.allegro.cc/manual/al_use_transform"><span class="a">al_use_transform</span></a></span> if it&#39;s crucial you have some non-one scale.)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Jeff Bernard)</author>
		<pubDate>Mon, 20 May 2013 01:29:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>No, using the draw region doesn&#39;t change performance in any measurable way. I will test the transformation method. Since all the tiles drawn in a given frame would be scaled to the same way, I figure I set it for the target bitmap and then unset it once everything is drawn?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Dakota West)</author>
		<pubDate>Mon, 20 May 2013 01:32:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I find this suspicious:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">void</span> block_draw <span class="k2">(</span>block fg, block bg, <span class="k1">int</span> x, <span class="k1">int</span> y, <span class="k1">int</span> scale<span class="k2">)</span><span class="k2">{</span>
</pre></div></div><p>

It seems you are passing the block objects by value instead of reference or as a pointer, meaning you are making copies of the block objects. If you do this hundreds of times per iteration, it could cause your program to slow down (and even malfunction)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ph03nix)</author>
		<pubDate>Mon, 20 May 2013 02:26:13 +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/612620/983104#target">ph03nix</a> said:</div><div class="quote"><p>
It seems you are passing the block objects by value instead of reference or as a pointer, meaning you are making copies of the block objects. If you do this hundreds of times per iteration, it could cause your program to slow down (and even malfunction)
</p></div></div><p>

The block struct currently only has one field, which is an unsigned 8bit integer, so I&#39;m not sure that&#39;s the issue, but I&#39;m running a test now.</p><p>Damn, no difference.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Dakota West)</author>
		<pubDate>Mon, 20 May 2013 02:35:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Quite the mystery then, because I see nothing wrong with the code. Does it still run slowly if you draw everything but the tiles? (assuming you draw other things as well)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ph03nix)</author>
		<pubDate>Mon, 20 May 2013 02:55:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><s>To me it seems like biggest reason for this thing to work slow.</s> Use pointers anyway.</p><p>Also, make sure you don&#39;t call your render functions too much. <s>Do not assume that you can simply render entire scene at once just because it will get clipped to display area.</s> That was already there, haven&#39;t noticed, sorry. Anyway, even something as simple as rendering 64x64 bitmaps grid @60 fps causes big time performance problems.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Raidho36)</author>
		<pubDate>Mon, 20 May 2013 02:57:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The bitmaps are 64x64 pixels naturally, but I want their render size to be adjustable. Is it still hard to render them even when resized because their natural resolution is 64x64? For context, it renders 30 tiles across, and 10 tiles down (although I hoped that when I figured this out, I could render a bigger space).</p><p>I will experiment with smaller textures.</p><p>And ph03nix no, I am only drawing the tiles. It&#39;s only a map viewer.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Dakota West)</author>
		<pubDate>Mon, 20 May 2013 03:47:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Rendering 300 64x64 bitmaps should not slow down to 15 fps from 60, or be slow at all. Perhaps you are somehow converting the bitmaps to memory bitmaps. Try calling al_get_bitmap_flags on your tiles to see if they are memory bitmaps
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ph03nix)</author>
		<pubDate>Mon, 20 May 2013 03:54:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>@ph03nix You got it. They are somehow becoming memory bitmaps. I don&#39;t know how though. I will update soon.</p><p>Update: The tile atlas was loaded after setting the new bitmap flags to ALLEGRO_VIDEO_BITMAP, but before creating the display. I missed something really obvious; sorry for wasting your time guys. I can now display them at their natural size, in an array of 100x200 no problem, as well as export to a 500x500 tile image in under a second.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Dakota West)</author>
		<pubDate>Mon, 20 May 2013 04:04:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I meant <i>a grid of bitmaps</i> sized 64x64, of arbitrary bitmaps, that is rendering over 4000 bitmaps at once. Even such relatively small tile grid turns out to be a huge deal. That was real surprise to me, since my computer ran modern games at &quot;ultra&quot; just fine, I was really expected it to much the whole thing like it&#39;s nothing. And that&#39;s with very plain loop, all there was is incrementing values and drawing &quot;as is&quot;, with no computations going along. Now that I think of it, I probably had memory bitmaps, too. Still, if you have a lot of small tiles you&#39;re more likely to be drawing too many of them, in terms of computations per tile. For that part I really suggest you to use transformations, as you do a lot of computing within the loop only to do what transformaton does. Even if your video card render it faster than you can supply it, that&#39;ll still save you some processing.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Raidho36)</author>
		<pubDate>Mon, 20 May 2013 09:26:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Drawing any kind of tilemap will be <i>nothing</i> for modern hardware and allegro5. if it is slow, you&#39;ve done something wrong.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Mon, 20 May 2013 11:00:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Modern hardware relies on preload to run fast, because transferring data via outdated PCI-E interface takes way longer than processing it internally. Thus, transferring data is the bottleneck, and Allegro doesn&#39;t handle it well as of 5.0.8 branch. Maybe I was missing something, but last time I checked, instead of using VBO preloading and rendering by demand, Allegro was passing vertex data to the video card via legacy functions, and it was doing it for every single bitmap blitting operation. ---- It was also handling transformation matrices by itself rather than making the video card do it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Raidho36)</author>
		<pubDate>Mon, 20 May 2013 14:13:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It handles it fine. All bitmaps are loaded into video memory as textures, so that doesn&#39;t need to be transferred when drawing, and if you set up deferred/held drawing, the geometry is batched up and sent in as big of a batch as possible to cut down on gpu driver calls, and transfers to the gpu. IIRC it uses vertex arrays to transfer it over, and not &quot;legacy functions&quot; (I assume you mean glBegin/glVertex/glEnd). held drawing is known to help performance <i>significantly</i>.</p><p>Using a VBO for regular allegro drawing routines isn&#39;t likely to work very well. VBO integration is something very specific to the app&#39;s own data and structure. I tried coming up with something that would defer <i>all</i> allegro drawing, including blits and primitives. It still wouldn&#39;t use a VBO, but even with that, it was incredibly hard, or just down right impossible to do right.</p><p>I think SiegeLord implemented deferred drawing for the primitives addon, and it didn&#39;t help performance at all.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Mon, 20 May 2013 16:10:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It&#39;s a fact that Allegro&#39;s drawing model is suboptimal for GPUs, even with deferred drawing tricks... a more suitable API would be more complicated and probably would be even less well received than the current API <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />. It would require persistent objects (e.g. a persistent bitmap, rectangle etc.) and a scene graph, going completely against the A4 immediate drawing model that A5 essentially replicated.</p><p>The manual transformation bit is largely a red herring, incidentally. I&#39;ve implemented a &quot;fast&quot; drawing <a href="https://github.com/SiegeLord/FastDraw">library</a> that avoids the unnecessary (for tilemaps) transformation pre-application and it wasn&#39;t magically faster... the vagaries of the GPU/driver performance drowned out any gain of that optimization. E.g. on my old GPU it had no effect (or even a paradoxical slowdown), while on my new GPU it&#39;s twice as fast.</p><p>Anyway, Allegro 5.1 has some preliminary support for VBOs in the primitives addon, so in principle somebody who wants to squeeze more performance out of their GPU could use that.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Mon, 20 May 2013 16:30:17 +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/612620/983147#target">SiegeLord</a> said:</div><div class="quote"><p>It&#39;s a fact that Allegro&#39;s drawing model is suboptimal for GPUs, even with deferred drawing tricks... </p></div></div><p>Sure, but its still going to be more than fast enough for a lot of people&#39;s uses.</p><p>Speaking of scene graph type things, I started a 2d canvas lib. Probably going to be a lot faster than using a crap load of allegro primitive calls. But I never bothered to test it <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /> and I haven&#39;t worked on it in a while.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Anyway, Allegro 5.1 has some preliminary support for VBOs in the primitives addon, so in principle somebody who wants to squeeze more performance out of their GPU could use that.</p></div></div><p>How would a VBO help over a vertex array when you have to fire all of the data at the gpu every time?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Mon, 20 May 2013 16:35:52 +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/612620/983148#target">Thomas Fjellstrom</a> said:</div><div class="quote"><p> How would a VBO help over a vertex array when you have to fire all of the data at the gpu every time?</p></div></div><p>I don&#39;t know the mechanism, but it does help on some GPUs. E.g. on mine it&#39;s 35% faster to use the VBO even if you&#39;re re-sending the entire thing every frame (as reported by ex_vertex_buffer).</p><p>GPUs are magic.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Mon, 20 May 2013 16:54:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Or they just &quot;forget&quot; to optimize the vertex array stuff the same way. Driver derps.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Mon, 20 May 2013 17:11:26 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thomas, I would rather suggest uploading vertex data on bitmap loading, and then calling render of certain VBO vertex associated with certain bitmap, since batching or not, Allegro gathers vertex list and then passes it to video card, that&#39;s legacy. Instead, gathering should only involve setting up array of preloaded bitmap-associated vertex indices to render within a texture used. <s>I&#39;d implemented an array that would hold booleans for rendering of all bitmaps loaded, so whole gathering is narrowed down to marking certain indices to be rendered and figuring contiguous sectors to render more vertices at once.</s> Of course that won&#39;t do since there&#39;s more than single render of certain bitmap is possible. I didn&#39;t thought it through. So on the second thought I&#39;d implement a bunch of functions along main rendering functions specifically to handle VBO drawing, with persistent data, etc. So rather than telling video card &quot;render this long-<span class="cuss"><span>ass</span></span> freshly gathered vertex list with this texture&quot; it should tell a video card &quot;have this long-<span class="cuss"><span>ass</span></span> vertex list generated on bitmap load and remember it, because I&#39;ll be asking you to render vertices X through Y with texture Z&quot;. Calling VBO render function is way faster than transferring a bunch of triangles in terms of data transmission. Texture preloading was considered an industry standard about two decades ago, so that doesn&#39;t really count. Still, I haven&#39;t looked at the code too properly, so if it&#39;s already does precisely that, then I&#39;m sorry for putting it like this.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/612620/983144#target">Thomas Fjellstrom</a> said:</div><div class="quote"><p> it was incredibly hard, or just down right impossible to do right
</p></div></div><p>What can <i>possibly</i> be hard with a) uploading vertices to the video card and b) calling VBO render function later on?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Raidho36)</author>
		<pubDate>Tue, 21 May 2013 00:23:29 +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/612620/983164#target">Raidho36</a> said:</div><div class="quote"><p>Thomas, I would rather suggest uploading vertex data on bitmap loading</p></div></div><p>I&#39;m not sure how that helps? You don&#39;t even know where you&#39;re going to be drawing it at that point, or how many times.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>What can possibly be hard with a) uploading vertices to the video card and b) calling VBO render function later on?</p></div></div><p>Lets say you have 1000 objects, that have to be rendered in a certain order, how are you going to tell the gpu to render things in the right order? We&#39;re talking 2d here, but where objects have a proper zindex.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Tue, 21 May 2013 01:04:10 +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/612620/983166#target">Thomas Fjellstrom</a> said:</div><div class="quote"><p> I&#39;m not sure how that helps? You don&#39;t even know where you&#39;re going to be drawing it at that point, or how many times.
</p></div></div><p>Neither do 3d games know at what position and how many times will they draw their 3d models, but that doesn&#39;t stop anyone from using VBO. You must be don&#39;t getting the principle and idea of VBO if you have <i>this kind</i> of questions raised by it. Anyway, as for using VBO specifically for 2d bitmaps, here&#39;s my idea of it: when you load a bitmap (or create sub-bitmap) you upload to video card it&#39;s 4 vertices positions against it&#39;s origin (normally center) and with texture coordinates also specified, which would be 0 and 1 for &quot;full&quot; bitmap and somewhere between those for sub-bitmap. And there you go - you&#39;re all set to render your preloaded bitmaps with VBO. Simply call the render function to render vertices 1-4 if you want to render your bitmap 1, 5-8 for bitmap 2, etc. The right texture should be enabled, of course. So existing function that gathers as many bitmaps with same texture in a row as possible would be handy. Yet again, it may be faster to brute-force render it with setting up new texture every time it needs to be changed rather than computing queues like that, so it should be an option enabled with a flag. Or preferably, Allegro should estimate by itself whether or not target machine needs software queue or it can do it hardware just fine.
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> Lets say you have 1000 objects, that have to be rendered in a certain order, how are you going to tell the gpu to render things in the right order?
</p></div></div><p>First obvious thought: orthographic and depth buffer. Thoughtful idea: like normal, with depth buffer disabled, but rather than passing new vertices over and over, simply ask video card to render already uploaded vertices.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Raidho36)</author>
		<pubDate>Tue, 21 May 2013 10:03:04 +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/612620/983199#target">Raidho36</a> said:</div><div class="quote"><p>You must be don&#39;t getting the principle and idea of VBO if you have this kind of questions raised by it.</p></div></div><p> Or you completely missed my point. You upload vertex data for N bitmaps. Doesn&#39;t really do much when you&#39;re drawing N*500. The real gain comes when you can put all of your geometry in the VBO.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>First obvious thought: orthographic and depth buffer. Thoughtful idea: like normal, with depth buffer disabled, but rather than passing new vertices over and over, simply ask video card to render already uploaded vertices.</p></div></div><p>Please go implement that and let me know how it goes. Start with the Allegro 5 primitive apis (the bitmap drawing, and primitive shape drawing apis), and make sure everything is drawing in the correct order based on the order of the calls, making sure to take into account blending.</p><p>And please note, people are going to be calling these functions every frame.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Tue, 21 May 2013 10:22:26 +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/612620/983200#target">Thomas Fjellstrom</a> said:</div><div class="quote"><p> Doesn&#39;t really do much when you&#39;re drawing N*500. 
</p></div></div><p>Implying that building an array of N * 500 * 4 vertices every frame and passing it to video card would be anywhat more effecient. Even if not rendered faster, it saves CPU time. Yes, uploading entire drawable thing would be better, but that&#39;s not quite possible, and not used in practice: even 3d games with large open spaces split up their maps into small chunks and render them as needed rather than render entire thing at once, so your argument (rendering the whole thing as a single mesh) is not really valid anyway.
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> Please go implement that and let me know how it goes. 
</p></div></div><p>Let me check my list. Data structures, UTF-32 internal strings (what kind of moron came up with idea to store unicode strings internally as UTF-8?), network... now I just list in the &quot;VBO&quot; and that&#39;ll be it for now. Also sounded to me like an excuse not to do it.</p><p>----</p><p>Note that the whole point of using VBO is to cut down data transmission rate and CPU computation overhead (also saves a tiny bit of RAM) so that video card doesn&#39;t wait while you prepare your data, as this allows model rendering be as simple as calling a single function that unfolds into small bunch (possibly just one) of low-level calls to video card.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Raidho36)</author>
		<pubDate>Tue, 21 May 2013 11:39:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Nobody needs excuses not to do something for Allegro... Its all voluntary. Just like you could stop talking so much and actually get to coding some of the features you think are lacking. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Vanneto)</author>
		<pubDate>Tue, 21 May 2013 14:45:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>A5 is still a 2D library. Why do we need Allegro to be a 3D library? Isn&#39;t that what Ogre is for? And as for passing vertexes, you can do that yourself with OpenGL. Allegro doesn&#39;t prevent you from doing anything as far as I know. I don&#39;t see what the complaints are all about. If you have such great ideas to optimize the allegro library, by all means do so, but stop expecting everyone else to implement your ideas as if they didn&#39;t have anything else to do with their time. Stop blabbing, and start coding.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Tue, 21 May 2013 18:53:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Y&#39;all really should stop replying to Raidho36.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Tue, 21 May 2013 19:45: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/612620/983217#target">Edgar Reynaldo</a> said:</div><div class="quote"><p> A5 is still a 2D library. Why do we need Allegro to be a 3D library? Isn&#39;t that what Ogre is for?</p></div></div><p>A5 works just fine.<br /><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=iWcN851NzTg" target="_blank"><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/object/5/8/587fdadd7c7c190678f9d5431ab003dc.jpg" border="0" alt="video" title="Click to play video" /></a></div></div>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Tue, 21 May 2013 23:37:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Theres no reason we should put artificial limitations in place. If its easy to allow people to make 3D stuff with allegro, we should do it.</p><p>Of course allegro will never have its own full 3D engine api, but it shouldn&#39;t get in your way when you&#39;re trying to make one.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Tue, 21 May 2013 23:46:57 +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/612620/983206#target">Vanneto</a> said:</div><div class="quote"><p> Just like you could stop talking so much and actually get to coding some of the features you think are lacking. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div></div><p>That ain&#39;t my style, I&#39;ll just complain that those are missing rather than make them cease missing. <img src="http://www.allegro.cc/forums/smileys/cheesy.gif" alt=";D" border="0" />
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/612620/983217#target">Edgar Reynaldo</a> said:</div><div class="quote"><p> A5 is still a 2D library. Why do we need Allegro to be a 3D library? 
</p></div></div><p>True. Yet doesn&#39;t mean you shouldn&#39;t employ 3d-originated technques, provided modern video card have little to no support for 2d acceleration (nowdays the whole thing is done via 3d). Also, Allegro&#39;s sound doesn&#39;t have 3d-originated features such as doppler effect (despite using OpenAL), which is obviously a <i>lacking</i> of features. ---- Though it does have &quot;speed&quot; modifier that&#39;s kinda makes up for doppler stuff, if you can calculate it right. Also panning have to be done manually. But, I mean, OpenAL have those built-in, why make users implement it on their own on top of Allegro&#39;s wrappers.
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> Isn&#39;t that what Ogre is for? 
</p></div></div><p>IIRC Ogre is written in C++, which I don&#39;t stand as a library writing language. For any language but assembly it should be written in C unless it targets that particular language of choosing. 
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> I don&#39;t see what the complaints are all about.
</p></div></div><p>The library isn&#39;t optimal enough and doesn&#39;t provides certain features it could&#39;ve had provided easily, that&#39;s what. Just because it&#39;s &quot;good enough&quot; as is doesn&#39;t mean you shouldn&#39;t put further effort to make it better, particularry by coming up with reasons why not. Come to think of it, as opposed to vaguely (mostly zero) productive discussions, that would be even counter-productive. I perfectly realize that fixing bugs is higher priority though, just conduct some discussion. Like, never said you should go do it, it&#39;s not my fault you turned it <i>that way</i>.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/612620/983229#target">Thomas Fjellstrom</a> said:</div><div class="quote"><p> Of course allegro will never have its own full 3D engine api, but it shouldn&#39;t get in your way when you&#39;re trying to make one
</p></div></div><p>What about OpenAL part? I haven&#39;t looked at it that closely.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Raidho36)</author>
		<pubDate>Wed, 22 May 2013 02:21:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>OpenAL isn&#39;t related to 3D video at all.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/612620/983245#target">Raidho36</a> said:</div><div class="quote"><p>Just because it&#39;s &quot;good enough&quot; as is doesn&#39;t mean you shouldn&#39;t put further effort to make it better, particularry by coming up with reasons why not.</p></div></div><p>People do what they are interested in, in their own free time. If someone wants something specific, they should just do it, instead of winging about it not having been done for them.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Wed, 22 May 2013 02:27:50 +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/612620/983248#target">Thomas Fjellstrom</a> said:</div><div class="quote"><p> OpenAL isn&#39;t related to 3D video at all.
</p></div></div><p>Because it&#39;s related to 3d audio? Seriously though, I see zero reasons for Allegro&#39;s sound to limit users&#39; interaction with OpenAL to very basic features. Not like it&#39;s deliberately blocked by it, but unlike OpenGL part, it makes it either Audio addon or bare OpenAL, as far as I see.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> People do what they are interested in, in their own free time
</p></div></div><p>Yeah, I know, see above. I sincerely would go patch something up if it wasn&#39;t for need to install <span class="cuss"><span><span class="cuss"><span>shit</span></span></span></span>loads of libraries and programs and have to spend hours trying to get it to work if I happen to be unlucky with system setup just to build liballeg from sources (because, you know, things aren&#39;t done easy with Windows), and then spend days to figure right way to integrate new sources into library, so right now I&#39;m just doing my own stuff, like mirror interreflections for 3d laser game, (for some reason perspective gets screwed up <i>for certain models</i> after a bunch of iterations although matrices seems to be OK).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Raidho36)</author>
		<pubDate>Wed, 22 May 2013 02:39:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>There was going to be a much fancier audio api, but it never got finished.</p><p>I&#39;m not really sure how the OpenAL api works, so I don&#39;t know if it limits you from using it if you also use Allegro.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Wed, 22 May 2013 03:20:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>As I said, unlike OpenGL part, it doesn&#39;t supply you with functions that let you use Allegro&#39;s internal sound-related structures with bare OpenAL.Like, OpenGL part could return you a valid OpenGL texture from Allegro bitmap, but Audio addon doesn&#39;t have any of such.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Raidho36)</author>
		<pubDate>Wed, 22 May 2013 13:18:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It&#39;s not needed with audio, you can just completely bypass Allegro&#39;s audio. (With OpenGL some connection was required because OpenGL can&#39;t create the window.)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Wed, 22 May 2013 15:35:07 +0000</pubDate>
	</item>
</rss>
