title: Direct2D Depth Buffer
body: <p>I need to draw a list of shapes and I am using Direct2D. I get the list of shapes from a file. The list is sorted and the order of the elements inside the file represents the order these shapes will be drawn. So, if for example the file specifies two rectangle in the same position and with the same sizes, only the second one will be visible (since the first will be overwritten).</p>
  
  <p>Given my list of shapes I proceede to its drawing in the following way:</p>
  
  <pre><code>list&lt;Shape&gt; shapes;
  
  for (const auto&amp; shape : shapes)
     shape.draw();
  </code></pre>
  
  <p>It is straightforward to see that if I have two shapes I cannot invert the order of the drawing operations, and this means that I must be sure that <code>shape2</code> will be always drawn after <code>shape1</code> and so on. Follows that I can not use multiple threads to draw my shapes, and this is a huge disadvantage in terms of performances.</p>
  
  <p>I read that Direct3D supports the depth buffer (or z-buffer), which specifies for each pixel its z-coordinate, such that only the "visible" pixels (the onces closer to the viewer) will be drawn, <strong>regardless of the order in which the shapes are drawn</strong>. And I have the depth information of each shape when I read the file.</p>
  
  <p>Is there a way to use the depth buffer in Direct2D, or a similar technique which allows me the use of multiple threads to draw my shapes?</p>