What do you mean by copying depth buffer content to a "normal texture"?
A depth buffer is a texture2d with specific setup and a depthStencilView. (I assume you are using d3d10/11 from your post.)
Yes, sorry... what I intended to say is to copy a depth buffer's contents into a non-depth-buffer.
(and yes, I'm using Dx11)
You can still have a shader resource view to sample the texture in your shaders. Or are you trying to do something different?
Basically, I want to read in the CPU the contents of the DepthBuffer, something like this:
// Create texture: DepthStencil | 2xMultiSampled | USAGE_DEFAULT
descDepth.Width = 800;
descDepth.Height = 600;
descDepth.MipLevels = 1;
descDepth.ArraySize = 1;
descDepth.Format = DXGI_FORMAT_D32_FLOAT;
descDepth.SampleDesc.Count = 2;
descDepth.SampleDesc.Quality = 0;
descDepth.Usage = D3D11_USAGE_DEFAULT;
descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL;
descDepth.CPUAccessFlags = 0;
descDepth.MiscFlags = 0;
ID3D11Texture2D* pDepthStencil = nullptr;
m_pDevice->CreateTexture2D( &descDepth, NULL, &pDepthStencil );
// Create texture: R32 | SingleSampled | USAGE_DEFAULT
descDepth.SampleDesc.Count = 1;
descDepth.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
descDepth.Format = DXGI_FORMAT_R32_FLOAT;
ID3D11Texture2D* pTemp1 = nullptr;
m_pDevice->CreateTexture2D( &descDepth, NULL, &pTemp1 );
// Create texture: R32 | SingleSampled | USAGE_STAGING
descDepth.BindFlags = 0;
descDepth.Usage = D3D11_USAGE_STAGING;
descDepth.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
ID3D11Texture2D* pCPUReadable = nullptr;
m_pDevice->CreateTexture2D( &descDepth, NULL, &pCPUReadable );
// RENDER SOMETHING
// Src must be multisampled, Dst must be singlesampled and USAGE_DEFAULT
m_pDevice->ResolveSubresource( pTemp1, 0, pDepthStencil, 0, DXGI_FORMAT_R32_FLOAT );
// Both, Src & Dst, must be singlesampled or multisampled, must be compatible formats, have same Multisampling count and Qlty
m_pDevice->CopyResource( pCPUReadable, pTemp1 );
m_pDevice->Map( pCPUReadable, 0, D3D11_MAP_READ, 0, &MappedResource );
However, no matter what MappedResource.pData is always 0000000000000000000000000000000000000000000000000000000000000000......
If ever you want to do something funkier, you can always copy the depth buffer in a shader by sampling it using it's shader resource view, and outputing to a rendertarget with your reinterpreted depth data.
I'm trying to keep away from copying it in a shader as much as possible, in theory this should be working, but if there is no way to do it without using the shader then yes, I think I will have to do it that way.
I would just try it and find out
, I tryed but it doesn't send any error (the destination only keeps as 0's)
Any ideas of what could I be missing?