| 1875 | } |
| 1876 | |
| 1877 | void DX11Engine::CopyBackBuffer(std::shared_ptr<Texture2>& texture) |
| 1878 | { |
| 1879 | if (!mColorBuffer) |
| 1880 | { |
| 1881 | return; |
| 1882 | } |
| 1883 | |
| 1884 | // The format and dimensions of the texture must match those of the |
| 1885 | // back buffer. |
| 1886 | D3D11_TEXTURE2D_DESC desc; |
| 1887 | mColorBuffer->GetDesc(&desc); |
| 1888 | if (!texture || |
| 1889 | texture->GetFormat() != DF_R8G8B8A8_UNORM || |
| 1890 | texture->GetWidth() != desc.Width || |
| 1891 | texture->GetHeight() != desc.Height) |
| 1892 | { |
| 1893 | texture = std::make_shared<Texture2>(DF_R8G8B8A8_UNORM, desc.Width, desc.Height); |
| 1894 | } |
| 1895 | |
| 1896 | // Copy the back buffer to the staging texture. |
| 1897 | mImmediate->CopyResource(mBackBufferStaging, mColorBuffer); |
| 1898 | |
| 1899 | // Map the staging texture and copy it to the input texture. |
| 1900 | D3D11_MAPPED_SUBRESOURCE subresource; |
| 1901 | DX11Log(mImmediate->Map(mBackBufferStaging, 0, D3D11_MAP_READ_WRITE, 0, &subresource)); |
| 1902 | uint32_t const pitch = 4 * desc.Width; |
| 1903 | uint8_t const* source = static_cast<uint8_t const*>(subresource.pData); |
| 1904 | size_t const numBytes = 4 * static_cast<size_t>(desc.Width); |
| 1905 | uint8_t* target = texture->Get<uint8_t>(); |
| 1906 | for (uint32_t i = 0; i < desc.Height; ++i) |
| 1907 | { |
| 1908 | std::memcpy(target, source, numBytes); |
| 1909 | source += subresource.RowPitch; |
| 1910 | target += pitch; |
| 1911 | } |
| 1912 | mImmediate->Unmap(mBackBufferStaging, 0); |
| 1913 | } |
| 1914 | |
| 1915 | uint64_t DX11Engine::DrawPrimitive(std::shared_ptr<VertexBuffer> const& vbuffer, |
| 1916 | std::shared_ptr<IndexBuffer> const& ibuffer, std::shared_ptr<VisualEffect> const& effect) |