Original Post
This is about as basic a code as it gets. Can anyone show me what I'm doing wrong? I used PIX to acquire the textures that I set to the pipeline and I have linked them below. It should be obvious which part of the picture is the resultant texture ;( Will give rep for anyone who helps me
[media]http://imageshack.us/f/830/copyresourceproblem.png/[/media]
HRESULT DirectXHandler11::CopyResourceTest()
{
ID3D11ShaderResourceView* pResultantTextureSRV = NULL;
ID3D11Texture2D* pResultantTexture = NULL;
ID3D11Texture2D* pStagingTexture = NULL;
ID3D11Texture2D* pOriginalTexture = NULL;
ID3D11ShaderResourceView* pOriginalTextureSRV = NULL;
D3D11_MAPPED_SUBRESOURCE Subresource;
D3D11_TEXTURE2D_DESC RTDESC;
ZeroMemory(&RTDESC, sizeof(D3D11_TEXTURE2D_DESC));
RTDESC.Height = 33;
RTDESC.Width = 33;
RTDESC.MipLevels = 1;
RTDESC.ArraySize = 1;
RTDESC.SampleDesc.Count = 1;
RTDESC.SampleDesc.Quality = 0;
RTDESC.Format = DXGI_FORMAT_R32_FLOAT;
RTDESC.Usage = D3D11_USAGE_DEFAULT;
RTDESC.BindFlags = D3D11_BIND_SHADER_RESOURCE;
RTDESC.CPUAccessFlags = 0;
float* pTexels = new float[33*33];
for(int i = 0; i < 33; i++)
{
for(int j = 0; j < 33; j++)
{
pTexels[(j*33)+i] = (((float)i/32.0f) + ((float)j/32.0f)) / 2;
}
}
D3D11_SUBRESOURCE_DATA InitialData;
ZeroMemory(&InitialData, sizeof(D3D11_SUBRESOURCE_DATA));
InitialData.pSysMem = pTexels;
InitialData.SysMemPitch = sizeof(float)*33;
mHR = m_pDevice->CreateTexture2D(&RTDESC, &InitialData, &pOriginalTexture);
if(SUCCEEDED(mHR))
{
mHR = m_pDevice->CreateShaderResourceView(pOriginalTexture, NULL, &pOriginalTextureSRV);
m_pDeviceContext->PSSetShaderResources(0, 1, &pOriginalTextureSRV);
}
//D3D11_TEXTURE2D_DESC RTDESC;
ZeroMemory(&RTDESC, sizeof(D3D11_TEXTURE2D_DESC));
RTDESC.Height = 33;
RTDESC.Width = 33;
RTDESC.MipLevels = 1;
RTDESC.ArraySize = 1;
RTDESC.SampleDesc.Count = 1;
RTDESC.SampleDesc.Quality = 0;
RTDESC.Format = DXGI_FORMAT_R32_FLOAT;
RTDESC.Usage = D3D11_USAGE_STAGING;
RTDESC.BindFlags = 0;
RTDESC.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
if(SUCCEEDED(mHR))
{
mHR = m_pDevice->CreateTexture2D(&RTDESC, NULL, &pStagingTexture);
//if(SUCCEEDED(mHR))
//{
// mHR = m_pDevice->CreateShaderResourceView(pStagingTexture, NULL, &pStagingTextureSRV);
//}
}
m_pDeviceContext->CopyResource(pStagingTexture, pOriginalTexture);
if(SUCCEEDED(mHR))
{
mHR = m_pDeviceContext->Map(pStagingTexture, 0, D3D11_MAP_READ, 0, &Subresource);
float* pData = (float*)Subresource.pData;
//++++++++++++++++++++++++++++++++++++++
//RECONSTRUCT THE RESULTANT TEXTURE...
//++++++++++++++++++++++++++++++++++++++
//D3D11_TEXTURE2D_DESC RTDESC;
ZeroMemory(&RTDESC, sizeof(D3D11_TEXTURE2D_DESC));
RTDESC.Height = 33;
RTDESC.Width = 33;
RTDESC.MipLevels = 1;
RTDESC.ArraySize = 1;
RTDESC.SampleDesc.Count = 1;
RTDESC.SampleDesc.Quality = 0;
RTDESC.Format = DXGI_FORMAT_R32_FLOAT;
RTDESC.Usage = D3D11_USAGE_DEFAULT;
RTDESC.BindFlags = D3D11_BIND_SHADER_RESOURCE;
RTDESC.CPUAccessFlags = 0;
//D3D11_SUBRESOURCE_DATA InitialData;
ZeroMemory(&InitialData, sizeof(D3D11_SUBRESOURCE_DATA));
InitialData.pSysMem = pData;
InitialData.SysMemPitch = sizeof(float)*33;
mHR = m_pDevice->CreateTexture2D(&RTDESC, &InitialData, &pResultantTexture);
if(SUCCEEDED(mHR))
{
mHR = m_pDevice->CreateShaderResourceView(pResultantTexture, NULL, &pResultantTextureSRV);
m_pDeviceContext->PSSetShaderResources(1, 1, &pResultantTextureSRV);
}
m_pDeviceContext->Unmap(pStagingTexture, 0);
}
//+++++++++++++++
//FIND ANY ERRORS
//+++++++++++++++
if(FAILED(mHR))
{
GeneralErrorHandler::OutputDxError(mHR, "CopyResourceTest", NULL);
GeneralErrorHandler::LogErrorToFile("CopyResourceTest", "[FAILED]", "", "ErrorLog.txt");
}
SafeDelete(pTexels);
SafeRelease(pResultantTextureSRV);
SafeRelease(pResultantTexture);
SafeRelease(pStagingTexture);
SafeRelease(pOriginalTexture);
SafeRelease(pOriginalTextureSRV);
return mHR;
}
[media]http://imageshack.us/f/830/copyresourceproblem.png/[/media]