<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Primitive drawing - Allegro 4 vs 5</title>
		<link>http://www.allegro.cc/forums/view/615426</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 08 Jun 2015 19:56:49 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I am doing some experiments with Allegro 5, having previously been using Allegro 4. I&#39;m porting a program which draws 2000 unfilled circles. I&#39;m finding that it runs slower in Allegro 5 (latest stable version) - about 4ms for drawing vs 1ms in Allegro 4.</p><p>In Allegro 4 I was drawing to a memory bitmap and blitting to the screen. In Allegro 5 I am writing to the default display and calling al_flip_display.</p><p>I remember reading in the docs somewhere that the primitive functions are not well-optimised. Is there any way to speed this up? I tried drawing to an intermediate memory bitmap like in the old days and drawing that to the screen but it was incredibly slow. Should I have been locking it?</p><p>I am running on Windows 7.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Andrew Gillett)</author>
		<pubDate>Wed, 03 Jun 2015 13:41:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What frame rate are you getting? It could be that the vertical retrace is seemingly slowing you down. How does it scale to 4000, 8000, ... circles?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (beoran)</author>
		<pubDate>Wed, 03 Jun 2015 19:20:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>With no circles the render time is 0.3ms, with 4000 it is 10ms. The vsync is not included in the render timings.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Andrew Gillett)</author>
		<pubDate>Wed, 03 Jun 2015 19:44:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, you&#39;re comparing apples and oranges in a way.<br />A5 and A4 are completely different in their inner workings, as A5 is using the GPU to do most drawing. The GPU, as exposed through OpenGL and Direct3D, doesn&#39;t provide rendering of &#39;high level&#39; primitives directly (such as circles), at least not in a standard way. It basically only knows how to draw triangles (and line segments). But it can do this very fast.</p><p>So what A5&#39;s primitives functions do is basically to calculate vertices (using the CPU) which are then passed to the GPU to do the rendering by &quot;connecting&quot; the vertices using either triangles or line segments.</p><p>That means that, internaly, al_draw_filled_circle / al_draw_circle just calls al_calculate_arc and pass the resulting vertices to al_draw_prim.</p><p>I think that having too many calls to al_draw_prim is not going to be terribly fast, since it probably involves some state changes. Generally, the GPU likes to be in one state (i. e. all parameters (textures, matrices, ...) set, only receiving vertex data (position, color, texture coordinates)). You could therefore maybe speed up the process by minimizing your al_draw_prim calls (remember that these happen behind the scenes anyway). <br />You could do that by putting more/many/all your vertices in a big buffer via al_calculate_arc and drawing this in not so many/fewer/one al_draw_prim calls. Depending on your geometry, you could also use a vertex buffer to store your vertex data directly on the GPU side of things. This is only supported by A 5.1 though.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Polybios)</author>
		<pubDate>Wed, 03 Jun 2015 19:49:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>One optimization would be to create something akin to <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>, but for primitives... this would minimize the number of <span class="source-code"><a href="http://www.allegro.cc/manual/al_draw_prim"><span class="a">al_draw_prim</span></a></span> calls. Without doing something akin to that, there&#39;s not much you can do currently.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Thu, 04 Jun 2015 06:46:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That would be a good thing to have... I&#39;ve already run into similar issues.</p><p>Edit: It would only make sense if texture and vertex declaration would remain the same, wouldn&#39;t it? Maybe &quot;splitting&quot; al_draw_prim and friends into three functions (setup state, send (more) data, revert state) would also be an option? I can see that setup_state in prim_opengl.c already passes the vertex-array-pointer to OpenGL, though. So the pointer is actually part of the state... Hmm... You can already use the indexed versions... So maybe an optimization just for the high_primitives? All of the high_primitives.c drawing functions seem to use local vertex caches on the stack, so this would probably need to change. Maybe they could be made to send their vertices into an internal buffer that is drawn when full? But circles would need do draw triangle fans whereas... Well, whatever.</p><p>Other possible approaches to the OP&#39;s problem depend on what kind of circles he wants to draw.<br />If they&#39;re all the same size or if there are only a few different sizes, another possible solution would be to draw them to bitmaps (edit: one bitmap) first and then draw the bitmaps in one go with al_hold_bitmap_drawing. They could be white and drawn tinted if different colors are needed. That should be quite fast.<br />Or if their relative position doesn&#39;t change (which I doubt), they could be calculated into a big vertex array before, which is drawn in one al_draw_prim call with transformations enabled to move all of them around.<br />I doubt these are applicable though.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Polybios)</author>
		<pubDate>Thu, 04 Jun 2015 12:54:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Drawing circles is not an appropriate benchmark of what a GPU can do. If all you need is circles, buy a circle drawing card.</p><p>I&#39;m joking, but you get the point. Synthetic benchmarks are not automatically valid predictors of real-world performance. There&#39;s some <a href="http://www.amazon.com/Computer-Architecture-Fifth-Edition-Quantitative/dp/012383872X">great books</a> full of exceptions that can make a benchmark useless.</p><p>There are a <b>few</b> use cases where Allegro 4 can be faster (lots of per-pixel manipulation). But I&#39;ve recently run an Allegro 5 program where I drew thousands of 1x1 blended rectangles to draw single pixel rain and it still ran at maximum FPS; so, I&#39;m not even sure that&#39;s the case anymore unless you&#39;re doing something wrong.</p><p>Usually, people coming from Allegro 4 still have the &quot;allegro 4 mindset&quot; and don&#39;t understand that modern graphics are done much differently, and that your game should be structured to reflect that. </p><p>For example:
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/615426/1013772#target">Andrew Gillett</a> said:</div><div class="quote"><p>
 The vsync is not included in the render timings.
</p></div></div><p>
Just because you didn&#39;t ask for it, doesn&#39;t mean it&#39;s not on. Drivers can both assume a default if you didn&#39;t ask, and override it if you did ask.</p><p>Secondly, your drawing routines may be slower initially, but do they linearly grow in time? It&#39;s entirely possible your modern graphics have a higher initial overhead, but scale much better. Try higher numbers of circles. What happens to both the A4 and A5 versions?</p><p>Let&#39;s be clear: It&#39;s entirely <b>possible</b> you&#39;re spot on and there&#39;s something wrong or broken in A5 making it slower. But in most cases, it&#39;s a user doing things wrong.</p><p>So:<br /> - Please list your hardware<br /> - Please post the minimal amount of code that replicates the issue, formatted in &lt; code&gt; tags
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Chris Katko)</author>
		<pubDate>Thu, 04 Jun 2015 16:59:15 +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/615426/1013784#target">Polybios</a> said:</div><div class="quote"><p> So maybe an optimization just for the high_primitives? All of the high_primitives.c drawing functions seem to use local vertex caches on the stack, so this would probably need to change. Maybe they could be made to send their vertices into an internal buffer that is drawn when full? But circles would need do draw triangle fans whereas... Well, whatever.</p></div></div><p>Yes, it&#39;s for high primitives only. There&#39;d be a new thread-local or perhaps display-local vertex buffer just like with bitmaps. Everything would be drawn using indexed triangle lists.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Thu, 04 Jun 2015 20:19:36 +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/615426/1013786#target">SiegeLord</a> said:</div><div class="quote"><p>Everything would be drawn using indexed triangle lists.</p></div></div><p>I could really use some code like that, but for 3D shapes <img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" /> take a line, and make some triangles out of it to make a line you can see from all sides, and store it in the same vbo as other shapes...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Thu, 04 Jun 2015 22:24:21 +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/615426/1013788#target">Thomas Fjellstrom</a> said:</div><div class="quote"><p>
and make some triangles out of it to make a line you can see from all sides, and store it in the same vbo as other shapes...
</p></div></div><p>
Wouldn&#39;t that be fairly easy with bill-boarded sprites / triangles? (Always facing the screen.)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Chris Katko)</author>
		<pubDate>Thu, 04 Jun 2015 22:26:42 +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/615426/1013789#target">Chris Katko</a> said:</div><div class="quote"><p>Wouldn&#39;t that be fairly easy with bill-boarded sprites / triangles? (Always facing the screen.)</p></div></div><p>Yeah, I suppose. I&#39;d have to regenerate them every frame to do that though.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Thu, 04 Jun 2015 22:29:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>In my model viewer I didn&#39;t have any problem with lines being obscured. They respected the z buffer afaics. Of course they&#39;re ultra thin though.</p><p>And as far as A4 vs A5 goes, you have to understand the fundamental differences between them in order to make full use of their capabilities.</p><p>If you&#39;re making 50,000 circles with each calling al_draw_prim, that will take much longer than batching up all your geometry into a vertex buffer of some sort and drawing it with a single al_draw_prim. It should be much faster. So try precalculating all your vertices and adding them into a vector or something and then draw them all at once.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Thu, 04 Jun 2015 22:37:09 +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/615426/1013791#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>In my model viewer I didn&#39;t have any problem with lines being obscured. They respected the z buffer afaics. Of course they&#39;re ultra thin though.</p></div></div><p>If you have culling turned on properly, if you go behind a poly, it will disappear completely. So you either need to regen it to face the camera, or make four, so it shows up from the four cardinal directions. could do a cross shape or a box. One use for it is to show the &quot;block&quot; or object you&#39;re looking at by drawing a wire frame around it. or draw chunk boundaries, or other debugging aids. And I&#39;d like to share a single VBO for all of the different primitive shapes I&#39;d like to draw (cubes, wire frames, lines, etc).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Thu, 04 Jun 2015 22:44: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/615426/1013792#target">Thomas Fjellstrom</a> said:</div><div class="quote"><p>
If you have culling turned on properly
</p></div></div><p>
How do I do this? I want to test it out in my viewer. I thought hairlines didn&#39;t have any kind of facing?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Thu, 04 Jun 2015 22:53:32 +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/615426/1013792#target">Thomas Fjellstrom</a> said:</div><div class="quote"><p>
So you either need to regen it to face the camera, or make four, so it shows up from the four cardinal directions
</p></div></div><p>
I wonder how distance comes into play. You want distance so that a line has depth (think parallax effect looking down a very long spring), but you don&#39;t want the <i>volume</i> of the line to change, do you? Because at a distance, it&#39;ll disappear.</p><p>I guess it depends what you mean when you say you want &quot;a line&quot; in 3-D.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Chris Katko)</author>
		<pubDate>Thu, 04 Jun 2015 23:03:25 +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/615426/1013793#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>I thought hairlines didn&#39;t have any kind of facing?</p></div></div><p>How do you draw hairlines with triangles? <img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Thu, 04 Jun 2015 23:11:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I was using al_draw_prim with ALLEGRO_PRIM_LINE_LIST. I wasn&#39;t drawing triangles, but I guess that&#39;s what we are talking about here. It might work for you though, to draw lines instead of triangles. But you want an actual poly shape though, right? You could draw a triangular prism - that&#39;s only 5 faces, or a rectangular prism, with 6 faces.</p><p>Edit - we can discuss this on IRC if you like, instead of spamming this thread with OT stuff.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Thu, 04 Jun 2015 23:16:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ve been doing 3D drawing with al_draw_indexed_prim and it works nicely, but even better performance would be nice. Something like al_hold_prim_drawing and a per-destination bitmap vbo buffer would be great... <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /> But yes, we&#39;re going off topic.  </p><p>For the circle problem <span class="source-code"><a href="http://www.allegro.cc/manual/al_draw_indexed_prim"><span class="a">al_draw_indexed_prim</span></a><span class="k2">(</span><span class="k2">)</span></span> is a good solution, if you regenerate the point lists every time. You&#39;ll have to calculate the circle points yourself but you can easily color and texture the result.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (beoran)</author>
		<pubDate>Fri, 05 Jun 2015 01:00:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> Chris Katko</p></div></div><p>Let me be more clear about my question. I am working on a game in Allegro 4, whose graphics are drawn purely using primitives. I&#39;m aware that the world has moved on from pixel-based drawing but I&#39;m curious to find out if the performance of my game in Allegro 5 will be better, worse or the same. I never said there was anything wrong or broken about AL5, although the docs admit that primitive drawing is not well-optimised. I could carry on using Allegro 4 but there is an issue with it which on my machine causes the mouse to become ultra-laggy in the debugger, making debugging almost impossible (discussed on this forum earlier this year).</p><p>When I said the vsync is not included in the render timings, I meant that I am using QueryPerformanceCounter in Windows to measure the time taken to make all the draw calls. The call to al_flip_display is outside this timed section.</p><p>For my current project, small filled rectangles are more important than circles, so I have updated my test program to draw those instead. The performance is comparable to how it was before.</p><p>AL5:<br />5,000: 14.3ms<br />10,000: 25.9ms<br />20,000: 47ms</p><p>AL4:<br />5,000: 3ms<br />10,000: 3.7ms<br />20,000: 4.8ms</p><p>I will look into the suggestions that people have made on this thread.</p><p>My hardware is Intel Core i3-3220, with Intel HD onboard graphics.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Andrew Gillett)</author>
		<pubDate>Fri, 05 Jun 2015 14:22:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If it&#39;s rectangles, why not try to cheat and stretch/blit a bitmap with a border in it? Blitting of bitmaps is well optimized in Allegro5 <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (beoran)</author>
		<pubDate>Fri, 05 Jun 2015 16:46:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Just tried drawing rectangles with a single call to al_draw_prim, draw time for 20,000 is 10ms.</p><p>EDIT: After some optimisation, got it down to 6.5ms.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Andrew Gillett)</author>
		<pubDate>Fri, 05 Jun 2015 17:12:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>A blit is likely to be even faster <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Fri, 05 Jun 2015 21:55:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Do you mean with al_draw_bitmap? Draw time was 25ms for 20,000.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Andrew Gillett)</author>
		<pubDate>Mon, 08 Jun 2015 15:42:28 +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/615426/1013841#target">Andrew Gillett</a> said:</div><div class="quote"><p>Do you mean with al_draw_bitmap? Draw time was 25ms for 20,000.</p></div></div><p>Now turn on held drawing via <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> <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /> and batch drawing that use the same textures together. either sort by texture, or use atlasing to put all images in the same larger texture.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Mon, 08 Jun 2015 18:41:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>With al_hold_bitmap_drawing, draw is 6.5ms - same as using a single al_draw_prim call.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Andrew Gillett)</author>
		<pubDate>Mon, 08 Jun 2015 19:27: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/615426/1013843#target">Andrew Gillett</a> said:</div><div class="quote"><p>With al_hold_bitmap_drawing, draw is 6.5ms - same as using a single al_draw_prim call.</p></div></div><p>Yeah, that&#39;s kind of expected, as it turns into the same/similar code behind the scenes.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Mon, 08 Jun 2015 19:56:49 +0000</pubDate>
	</item>
</rss>
