- dst = image->start();
- src = (const unsigned char *)MappedSubresource.pData;
- for (unsigned y = 0; y < Height; ++y) {
- if (Desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM) {
- memcpy(dst, src, Width * 4);
- } else if (Desc.Format == DXGI_FORMAT_R32G32B32A32_FLOAT) {
- float scale = 1.0f/255.0f;
- for (unsigned x = 0; x < Width; ++x) {
- dst[4*x + 0] = ((float *)src)[4*x + 0] * scale;
- dst[4*x + 1] = ((float *)src)[4*x + 1] * scale;
- dst[4*x + 2] = ((float *)src)[4*x + 2] * scale;
- dst[4*x + 3] = ((float *)src)[4*x + 3] * scale;
- }
- } else if (Desc.Format == DXGI_FORMAT_B8G8R8A8_UNORM) {
- for (unsigned x = 0; x < Width; ++x) {
- dst[4*x + 0] = src[4*x + 2];
- dst[4*x + 1] = src[4*x + 1];
- dst[4*x + 2] = src[4*x + 0];
- dst[4*x + 3] = src[4*x + 3];
- }
- } else {
- assert(0);
- }
- src += MappedSubresource.RowPitch;
- dst += image->stride();
+static image::Image *
+getDepthStencilViewImage(ID3D10Device *pDevice,
+ ID3D10DepthStencilView *pDepthStencilView) {
+ image::Image *image = NULL;
+ D3D10_DEPTH_STENCIL_VIEW_DESC Desc;
+ ID3D10Resource *pResource = NULL;
+ ID3D10Resource *pStagingResource = NULL;
+ UINT Width, Height, Depth;
+ UINT MipSlice;
+ UINT Subresource;
+ D3D10_MAPPED_TEXTURE3D MappedSubresource;
+ HRESULT hr;
+
+ if (!pDepthStencilView) {
+ return NULL;
+ }
+
+ pDepthStencilView->GetResource(&pResource);
+ assert(pResource);
+
+ pDepthStencilView->GetDesc(&Desc);
+
+ hr = stageResource(pDevice, pResource, &pStagingResource, &Width, &Height, &Depth);
+ if (FAILED(hr)) {
+ goto no_staging;
+ }
+
+ // TODO: Take the slice in consideration
+ switch (Desc.ViewDimension) {
+ case D3D10_DSV_DIMENSION_TEXTURE1D:
+ MipSlice = Desc.Texture1D.MipSlice;
+ break;
+ case D3D10_DSV_DIMENSION_TEXTURE1DARRAY:
+ MipSlice = Desc.Texture1DArray.MipSlice;
+ break;
+ case D3D10_DSV_DIMENSION_TEXTURE2D:
+ MipSlice = Desc.Texture2D.MipSlice;
+ MipSlice = 0;
+ break;
+ case D3D10_DSV_DIMENSION_TEXTURE2DARRAY:
+ MipSlice = Desc.Texture2DArray.MipSlice;
+ break;
+ case D3D10_DSV_DIMENSION_TEXTURE2DMS:
+ MipSlice = 0;
+ break;
+ case D3D10_DSV_DIMENSION_TEXTURE2DMSARRAY:
+ MipSlice = 0;
+ break;
+ case D3D10_SRV_DIMENSION_UNKNOWN:
+ default:
+ assert(0);
+ goto no_map;
+ }
+ Subresource = MipSlice;
+
+ Width = std::max(Width >> MipSlice, 1U);
+ Height = std::max(Height >> MipSlice, 1U);
+ Depth = std::max(Depth >> MipSlice, 1U);
+
+ hr = mapResource(pStagingResource, Subresource, D3D10_MAP_READ, 0, &MappedSubresource);
+ if (FAILED(hr)) {
+ goto no_map;