title: Direct3D11: Flipping ID3D11Texture2D
body: <p>I perform a capture of Direct3D back buffer. When I download the pixels the image frame is flipped along its vertical axis.Is it possible to "tell" D3D to flip the frame when copying resource,or when creating target <code>ID3D11Texture2D</code> ? </p>
  
  <p>Here is how I do it:</p>
  
  <p>The texture into which I copy the frame buffer is created like this:</p>
  
  <pre><code>    D3D11_TEXTURE2D_DESC description =
      {
          desc.BufferDesc.Width, desc.BufferDesc.Height, 1, 1,
          DXGI_FORMAT_R8G8B8A8_UNORM,
          { 1, 0 }, // DXGI_SAMPLE_DESC
          D3D11_USAGE_STAGING,//transder from GPU to CPU
          0, D3D11_CPU_ACCESS_READ, 0
      };
      D3D11_SUBRESOURCE_DATA data = { buffer, desc.BufferDesc.Width * PIXEL_SIZE, 0 };
       device-&gt;CreateTexture2D(&amp;description, &amp;data, &amp;pNewTexture);
  </code></pre>
  
  <p>Then on each frame I do:</p>
  
  <pre><code>     pSwapChain-&gt;GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast&lt; void** &gt;(&amp;pSurface));
       pContext-&gt;CopyResource(pNewTexture, pSurface);
       D3D11_MAPPED_SUBRESOURCE resource; 
       pContext-&gt;Map(pNewTexture, 0, D3D11_MAP_READ , 0, &amp;resource);
       //reading from resource.pData
       //...
  </code></pre>
  
  <p>PS: I don't have a control of the rendering pipeline. I hook an external app with this code.
  Also,I don't want to mess with the pixel buffer on the CPU, like reverse copy in a loop etc.. The low latency of the copy is high priority.</p>
  
  <p>UPDATE:</p>
  
  <p>I also tried this:</p>
  
  <pre><code>    D3D11_BOX box;
      box.left = 0;
      box.right = desc.BufferDesc.Width;
      box.top = desc.BufferDesc.Height;
      box.bottom = 0;
      box.front = 0;
      box.back = 1;
      pContext-&gt;CopySubresourceRegion(pNewTexture, 0, 0, 0, 0, pSurface, 0, &amp;box);
  </code></pre>
  
  <p>Which causes the frame to be empty from its content.</p>