<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Slow blitting in windowed mode?</title>
		<link>http://www.allegro.cc/forums/view/586505</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 18 Jul 2006 13:24:38 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi, I&#39;ve got the following code:</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td><span class="k1">int</span> main<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">2</td><td>    <a href="http://www.allegro.cc/manual/allegro_init" target="_blank"><span class="a">allegro_init</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">3</td><td>    <a href="http://www.allegro.cc/manual/install_keyboard" target="_blank"><span class="a">install_keyboard</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">4</td><td>    <a href="http://www.allegro.cc/manual/install_timer" target="_blank"><span class="a">install_timer</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">5</td><td>    <a href="http://www.allegro.cc/manual/install_mouse" target="_blank"><span class="a">install_mouse</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">6</td><td>    </td></tr><tr><td class="number">7</td><td>    <a href="http://www.allegro.cc/manual/set_color_depth" target="_blank"><span class="a">set_color_depth</span></a><span class="k2">(</span><span class="n">32</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">8</td><td>    <a href="http://www.allegro.cc/manual/set_gfx_mode" target="_blank"><span class="a">set_gfx_mode</span></a><span class="k2">(</span>GFX_AUTODETECT_WINDOWED, <span class="n">640</span>, <span class="n">480</span>, <span class="n">0</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">9</td><td>        </td></tr><tr><td class="number">10</td><td>    <a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>page1 <span class="k3">=</span> <a href="http://www.allegro.cc/manual/create_video_bitmap" target="_blank"><span class="a">create_video_bitmap</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/SCREEN_W" target="_blank"><span class="a">SCREEN_W</span></a>, <a href="http://www.allegro.cc/manual/SCREEN_H" target="_blank"><span class="a">SCREEN_H</span></a><span class="k2">)</span><span class="k2">;</span>    </td></tr><tr><td class="number">11</td><td>    <a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>page2 <span class="k3">=</span> <a href="http://www.allegro.cc/manual/create_video_bitmap" target="_blank"><span class="a">create_video_bitmap</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/SCREEN_W" target="_blank"><span class="a">SCREEN_W</span></a>, <a href="http://www.allegro.cc/manual/SCREEN_H" target="_blank"><span class="a">SCREEN_H</span></a><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">12</td><td>    <a href="http://www.allegro.cc/manual/clear_bitmap" target="_blank"><span class="a">clear_bitmap</span></a><span class="k2">(</span>page2<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">13</td><td>    </td></tr><tr><td class="number">14</td><td>    <span class="k1">int</span> x <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span></td></tr><tr><td class="number">15</td><td>    <span class="k1">while</span> <span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/keypressed" target="_blank"><span class="a">keypressed</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">16</td><td>        <a href="http://www.allegro.cc/manual/circlefill" target="_blank"><span class="a">circlefill</span></a><span class="k2">(</span>page2, x, <a href="http://www.allegro.cc/manual/SCREEN_H" target="_blank"><span class="a">SCREEN_H</span></a> <span class="k3">/</span> <span class="n">2</span>, <span class="n">64</span>, <a href="http://www.allegro.cc/manual/makecol" target="_blank"><span class="a">makecol</span></a><span class="k2">(</span><span class="n">255</span>, <span class="n">255</span>, <span class="n">255</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">17</td><td>        <a href="http://www.allegro.cc/manual/acquire_screen" target="_blank"><span class="a">acquire_screen</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">18</td><td>        <span class="k1">for</span><span class="k2">(</span><span class="k1">int</span> j <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> j <span class="k3">&lt;</span> <a href="http://www.allegro.cc/manual/SCREEN_H" target="_blank"><span class="a">SCREEN_H</span></a> <span class="k3">/</span> <span class="n">32</span><span class="k2">;</span> <span class="k3">+</span><span class="k3">+</span>j<span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">19</td><td>            <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> <a href="http://www.allegro.cc/manual/SCREEN_W" target="_blank"><span class="a">SCREEN_W</span></a> <span class="k3">/</span> <span class="n">32</span><span class="k2">;</span> <span class="k3">+</span><span class="k3">+</span>i<span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">20</td><td>                <a href="http://www.allegro.cc/manual/blit" target="_blank"><span class="a">blit</span></a><span class="k2">(</span>page2, <a href="http://www.allegro.cc/manual/screen" target="_blank"><span class="a">screen</span></a>, i <span class="k3">*</span> <span class="n">32</span>, j <span class="k3">*</span> <span class="n">32</span>, i <span class="k3">*</span> <span class="n">32</span>, j <span class="k3">*</span> <span class="n">32</span>, <span class="n">32</span>, <span class="n">32</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">21</td><td>            <span class="k2">}</span></td></tr><tr><td class="number">22</td><td>        <span class="k2">}</span></td></tr><tr><td class="number">23</td><td>        <a href="http://www.allegro.cc/manual/release_screen" target="_blank"><span class="a">release_screen</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">24</td><td>        <span class="k3">+</span><span class="k3">+</span>x<span class="k2">;</span></td></tr><tr><td class="number">25</td><td>    <span class="k2">}</span></td></tr><tr><td class="number">26</td><td>    </td></tr><tr><td class="number">27</td><td>    <a href="http://www.allegro.cc/manual/readkey" target="_blank"><span class="a">readkey</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">28</td><td>    <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span></td></tr><tr><td class="number">29</td><td><span class="k2">}</span></td></tr></tbody></table></div></div><p>

Blitting is very slow...the same code in full screen mode is so fast that I can&#39;t see the circle moving, while in windowed mode it moves very slowly.</p><p>Does anybody know something about this?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Sun, 16 Jul 2006 20:32:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>All I can imagine is it&#39;s hardware accelerating video-video in fullscreen, and not in windowed?</p><p>Maybe add some acquire/release bitmaps calls?</p><p>Marcello
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Marcello)</author>
		<pubDate>Sun, 16 Jul 2006 21:20:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Never acquire video bitmaps if you&#39;re doing vram-&gt;vram blits. You should only acquire bitmaps if you&#39;re going to do non-accelerated operations on them.</p><p>Just about the only circumstance in which you should use acquire_screen()is if you&#39;re doing a memory-&gt;vram dirty rectange system.</p><p>EDIT: in other words, drop the acquire()/release() calls.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Sun, 16 Jul 2006 21:58:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Are you trying to use page flipping?  If so, where do you flip the pages at?  Why don&#39;t you look at Shawn Hargreave&#39;s examples since he has something very similiar to this in the double buffer and page flipping examples.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Paladin)</author>
		<pubDate>Sun, 16 Jul 2006 22:03:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Even if I drop the acquire/release, the problem remains.</p><p>I am not trying to use page flipping, but buffering from vram.</p><p>I think maybe the problem is due to pixel conversion...because If I reduce the color depth to 16, then the speed is more than doubled.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Sun, 16 Jul 2006 23:45:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What&#39;s your desktop colour depth?<br />In windowed mode, the actual colour depth is the desktop colour depth. If you set anything else using set_color_depth, you will get colour conversions, which are slow.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Mon, 17 Jul 2006 00:03:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Is there a way to get the desktop color depth?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Felipe Maia)</author>
		<pubDate>Mon, 17 Jul 2006 00:15:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes.<br />Try your friend the manual.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Mon, 17 Jul 2006 00:25:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
If you put the circlefill itself outside the inner loop, does that give you a significant speed up?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Richard Phipps)</author>
		<pubDate>Mon, 17 Jul 2006 03:17:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
What&#39;s your desktop colour depth?
</p></div></div><p>

32 bpp, as it is in the code.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
If you put the circlefill itself outside the inner loop, does that give you a significant speed up?
</p></div></div><p>

The circlefill is already outside of the inner loop.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Mon, 17 Jul 2006 13:58:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">while</span> <span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/keypressed" target="_blank"><span class="a">keypressed</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span>
        <a href="http://www.allegro.cc/manual/circlefill" target="_blank"><span class="a">circlefill</span></a><span class="k2">(</span>page2, x, <a href="http://www.allegro.cc/manual/SCREEN_H" target="_blank"><span class="a">SCREEN_H</span></a> <span class="k3">/</span> <span class="n">2</span>, <span class="n">64</span>, <a href="http://www.allegro.cc/manual/makecol" target="_blank"><span class="a">makecol</span></a><span class="k2">(</span><span class="n">255</span>, <span class="n">255</span>, <span class="n">255</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
        <a href="http://www.allegro.cc/manual/acquire_screen" target="_blank"><span class="a">acquire_screen</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
        <span class="k1">for</span><span class="k2">(</span><span class="k1">int</span> j <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> j <span class="k3">&lt;</span> <a href="http://www.allegro.cc/manual/SCREEN_H" target="_blank"><span class="a">SCREEN_H</span></a> <span class="k3">/</span> <span class="n">32</span><span class="k2">;</span> <span class="k3">+</span><span class="k3">+</span>j<span class="k2">)</span> <span class="k2">{</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> <a href="http://www.allegro.cc/manual/SCREEN_W" target="_blank"><span class="a">SCREEN_W</span></a> <span class="k3">/</span> <span class="n">32</span><span class="k2">;</span> <span class="k3">+</span><span class="k3">+</span>i<span class="k2">)</span> <span class="k2">{</span>
                <a href="http://www.allegro.cc/manual/blit" target="_blank"><span class="a">blit</span></a><span class="k2">(</span>page2, <a href="http://www.allegro.cc/manual/screen" target="_blank"><span class="a">screen</span></a>, i <span class="k3">*</span> <span class="n">32</span>, j <span class="k3">*</span> <span class="n">32</span>, i <span class="k3">*</span> <span class="n">32</span>, j <span class="k3">*</span> <span class="n">32</span>, <span class="n">32</span>, <span class="n">32</span><span class="k2">)</span><span class="k2">;</span>
            <span class="k2">}</span>
        <span class="k2">}</span>
        <a href="http://www.allegro.cc/manual/release_screen" target="_blank"><span class="a">release_screen</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
        <span class="k3">+</span><span class="k3">+</span>x<span class="k2">;</span>
    <span class="k2">}</span>
</pre></div></div><p>
You are drawing the circle every frame, and drawing directly to video memory is known to be pretty slow.</p><p>If you could just blit the circle (but time the frame rate) you would have a better idea of how slow the blitting is..
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Richard Phipps)</author>
		<pubDate>Mon, 17 Jul 2006 14:05:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
You are drawing the circle every frame, and drawing directly to video memory is known to be pretty slow.
</p></div></div><p>

I don&#39;t think so. Only translucent drawing is slow on vram.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
If you could just blit the circle (but time the frame rate) you would have a better idea of how slow the blitting is..
</p></div></div><p>

The same code in full screen runs so fast you can not see the circle moving; all you see is a big white stripe.</p><p>Maybe there is conversion of pixels between RGB (which vram uses) and BGR format (which Windows uses); allegro devs could confirm this.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Mon, 17 Jul 2006 18:59:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I don&#39;t think so. Only translucent drawing is slow on vram.
</p></div></div><p>
If your hardware is accelerating some primitives like GFX_HW_LINE then you might get fast drawing. Otherwise it could be the cause of the slowness.</p><p>All I&#39;m saying is it could be worth testing to see if it is this than spending a lot of time on the blitting and gfx mode side.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Richard Phipps)</author>
		<pubDate>Mon, 17 Jul 2006 20:47:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
If your hardware is accelerating some primitives like GFX_HW_LINE then you might get fast drawing. Otherwise it could be the cause of the slowness.</p><p>All I&#39;m saying is it could be worth testing to see if it is this than spending a lot of time on the blitting and gfx mode side.
</p></div></div><p>

No, I&#39;ve already said that: if you do the test in full screen mode then it is so fast you don&#39;t see the circle moving, just a big white stripe. So it is definitely not the drawing.</p><p>If you also remove the for loop and do the blitting with one call, speed is good. The trouble is with tiled blitting.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Tue, 18 Jul 2006 00:41:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Maybe there is conversion of pixels between RGB (which vram uses) and BGR format (which Windows uses); allegro devs could confirm this.
</p></div></div><p>
If they knew about Windows programming and the innerworkings of the DirectX driver... maybe.<br />Anyway, Allegro should use the native RGB ordering used by the video mode (which is why you load bitmaps aftercalling set_gfx_mode()).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Tue, 18 Jul 2006 03:10:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
Axilmar:</p><p>Ah, I misunderstood. My apologies!</p><p>If things are that slow it sounds like the display is being converted or emulated in software somehow. Do AllegroGL programs also run slowly for you in a window?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Richard Phipps)</author>
		<pubDate>Tue, 18 Jul 2006 13:24:38 +0000</pubDate>
	</item>
</rss>
