<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>al_set_target_bitmap() slows down game</title>
		<link>http://www.allegro.cc/forums/view/616223</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 28 Apr 2016 13:13:22 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi,<br />So I am in the midst of porting my game to windows, and then getting it onto greenlight on Steam and I have found that it runs incredibly slow (~10x slower) on a window laptop I am testing it on. The laptop isn&#39;t too bad, an i5 thinkpad win 7 4gb, and so should be able to handle a simple 2D board game without a problem.<br />I have narrowed the problem, causing the slowness down to a few al_set_target_bitmap() calls .<br />Even if the code is like this... (with no code between the calls)</p><p>al_set_target_bitmap (zbuffer_bmp) (where zbuffer is a bitmap the same size as the display)<br />al_set_target_backbuffer (display)</p><p>..it slows the game down massively and I am at a loss what it might be (I have already done the &quot;obvious&quot; checking for memory bitmaps, and whether vsync is on etc)</p><p>If I comment out the al_set_target_bitmap the game doesn&#39;t slow down.</p><p>Can any help or have any suggestions, thanks.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Yodhe23)</author>
		<pubDate>Mon, 25 Apr 2016 18:35:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m curious why it&#39;s causing the game to slow down but...</p><p>Do you even need either of those function calls? I don&#39;t think you do, since Allegro automacally sets the target bitmap and target backbuffer when you create a display. Is there a problem you are trying to resolve by adding those functions?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (David Couzelis)</author>
		<pubDate>Mon, 25 Apr 2016 19:09:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I was merely reducing my code to the barest minimum to determine what caused the slowing, and whittled it down to those two lines, and in particular the first one. Normally I &quot;flush&quot; the zbuffer with al_clear_to_color, before returning to the backbuffer. Then a little later on in the function, when I draw the players cards, I also draw on the zbuffer, so I can later do a (locked bitmap) al_get_pixel_color on the zbuffer to see if the cards/hand are clicked/touched.<br />But it is the al_set_target_bitmap that causes the crippling slowness. I could code/hack around the problem, but I am loathed to before I understand what I am potentially doing wrong.</p><p>(I am using 5.2 and the windows binaries for the record.)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Yodhe23)</author>
		<pubDate>Mon, 25 Apr 2016 20:54:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Can you please post more of the code that contains those two function calls? I think it&#39;s important to see any loops that are happening and where / how things are created / destroyed.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (David Couzelis)</author>
		<pubDate>Mon, 25 Apr 2016 22:16:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Try setting the ALLEGRO_NO_PRESERVE_TEXTURE flag.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Tue, 26 Apr 2016 06:06:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks the ALLEGRO_NO_RESERVE_TEXTURE did the trick, though I would like to know why it works for future reference, and would really appreciate if you can illuminate me or point me in the right direction/documentation.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Yodhe23)</author>
		<pubDate>Tue, 26 Apr 2016 14:46:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Without that flag, Allegro automatically stores a copy of the texture in system RAM. If the graphics device is reset by some means (seems to be a thing on mobile platforms I believe, but also relevant for the older version of DirectX), texture data may be lost. In such a case, Allegro would use the copy to generate the texture, so the graphics device reset is handled silently. However, for a texture that is modified every frame, this is useless and instead incurs a performance penalty, as you witnessed.</p><p>(I think that&#39;s the gist of it.)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Erin Maus)</author>
		<pubDate>Tue, 26 Apr 2016 17:32:31 +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/616223/1022063#target">Aaron Bolyard</a> said:</div><div class="quote"><p> Without that flag, Allegro automatically stores a copy of the texture in system RAM. If the graphics device is reset by some means (seems to be a thing on mobile platforms I believe, but also relevant for the older version of DirectX), texture data may be lost. In such a case, Allegro would use the copy to generate the texture, so the graphics device reset is handled silently. </p></div></div><p>Is this feature automatically enabled on all systems?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Tue, 26 Apr 2016 18:17:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>DirectX 9.0c (the last before DirectX10, and the last normally supported on Windows XP) loses textures when alt-tabbing from fullscreen.<br />If you want to keep supporting it while still using ALLEGRO_NO_RESERVE_TEXTURE, maybe there&#39;s a clever trick like, instead of setting a FULLSCREEN mode, setting a DESKTOP-SIZED BORDERLESS WINDOW.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Tue, 26 Apr 2016 18:53:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I think ALLEGRO_NO_PRESERVE_TEXTURE should be removed from Allegro (and should then be the new default, i.e. Allegro will never download textures behind your back) - it just completely breaks all programs using dynamic bitmaps. And then do something similar to iOS and Android where you can restore textures if/when needed.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Tue, 26 Apr 2016 22:58:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I just force OpenGL usage so that texture preservation becomes a non-issue. The average person won&#39;t even notice nor care, plus given Microsoft&#39;s practices with legacy DirectX support, I think this is a better approach in the long run for keeping my games working their best through newer and newer versions of Windows.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kris Asick)</author>
		<pubDate>Wed, 27 Apr 2016 02:22:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>This is really kind of a non-issue if you just use ALLEGRO_FULLSCREEN_WINDOW. :/
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Wed, 27 Apr 2016 03:52:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Is this really an issue with fullscreen only? Right now the DirectX port always has it on by default, even in windowed mode... if it&#39;s save to disable we probably should.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Wed, 27 Apr 2016 07:17:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks for enlightening me.<br />In my experience it didn&#39;t make a difference whether it I set the display flags to OpenGL or DirectX (it was one of the first things I did), they both slowed down on my two windows 7 machines.<br />I disagree that it is a non issue if you just use ALLEGRO_FULLSCREEN_WINDOW, although I conceed it is probably an expedient hack.workaround, which I have yet to try. <br />I think Elias is right about how preserving textures should be implemented.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Yodhe23)</author>
		<pubDate>Wed, 27 Apr 2016 13:07:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I feel I should clarify what I said: Forcing OpenGL you STILL need to disable Allegro&#39;s texture preservation with the appropriate flag, it&#39;s just with OpenGL rendering and full-screen stuff, when you alt-tab out and alt-tab back in, your textures should still be there, regardless of how this is set. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kris Asick)</author>
		<pubDate>Thu, 28 Apr 2016 06:23:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I think internally, OpenGL just handles everything automatically, so even if textures are destroyed by switching, OpenGL restores them itfself. Would be quite useful if D3D also did that.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (RPG Hacker)</author>
		<pubDate>Thu, 28 Apr 2016 13:13:22 +0000</pubDate>
	</item>
</rss>
