int resolution = 4096;
//Staging texture:
D3D11_TEXTURE2D_DESC desc = {};
desc.Width = resolution;
desc.Height = resolution;
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Usage = D3D11_USAGE_STAGING;
desc.BindFlags = 0;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
desc.MiscFlags = 0;
// Render target view texture
D3D11_TEXTURE2D_DESC descBack = {};
descBack.Width = resolution;
descBack.Height = resolution;
descBack.MipLevels = 1;
descBack.ArraySize = 1;
descBack.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
descBack.SampleDesc.Count = 1;
descBack.SampleDesc.Quality = 0;
descBack.Usage = D3D11_USAGE_DEFAULT;
descBack.BindFlags = D3D11_BIND_RENDER_TARGET;
descBack.CPUAccessFlags = 0;
descBack.MiscFlags = 0;
// Create textures and render target view
// Set render target view active and view rectangles
// Draw stuff
deviceCtx->CopyResource(stagingTexture, rtvTexture);
// Graphics debugger shows that render target texture contents has been copied to staging texture.
// So staging texture is not null (at least according to debugger)
// Map command
deviceCtx->Map(stagingTexture, 0, D3D11_MAP_READ, 0, &mappedResource);
// deviceCtx->Map returns S_OK.
u32* textureData = (u32*)mappedResource.pData;
for (int y = 0; y < resolution; ++y)
{
for (int x = 0; x < resolution; ++x)
{
// rowPitch bytes is (y * resolution * 4), so y * resolution should be correct?
u32 diffuse = textureData[y * resolution + x];
// diffuse is always 0, even though gpu debugger (renderdoc) show that the
// staging texture has non-zero data
}
}
I cannot understand why it is not working? Maybe I'm missing something simple.. No D3D11 debug errors or warnings at any stage.