| 55 | } |
| 56 | |
| 57 | HRESULT CheckRenderD3D11::ResourceToPPM(ID3D11Device *pDevice, ID3D11Resource *pResource, const char *zFileName) |
| 58 | { |
| 59 | ID3D11DeviceContext *pDeviceCtxt; |
| 60 | pDevice->GetImmediateContext(&pDeviceCtxt); |
| 61 | D3D11_RESOURCE_DIMENSION rType; |
| 62 | pResource->GetType(&rType); |
| 63 | |
| 64 | if (rType != D3D11_RESOURCE_DIMENSION_TEXTURE2D) |
| 65 | { |
| 66 | printf("SurfaceToPPM: pResource is not a 2D texture! Aborting...\n"); |
| 67 | return E_FAIL; |
| 68 | } |
| 69 | |
| 70 | ID3D11Texture2D *pSourceTexture = (ID3D11Texture2D *)pResource; |
| 71 | ID3D11Texture2D *pTargetTexture = NULL; |
| 72 | |
| 73 | D3D11_TEXTURE2D_DESC desc; |
| 74 | pSourceTexture->GetDesc(&desc); |
| 75 | desc.BindFlags = 0; |
| 76 | desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; |
| 77 | desc.Usage = D3D11_USAGE_STAGING; |
| 78 | |
| 79 | if (FAILED(pDevice->CreateTexture2D(&desc,NULL,&pTargetTexture))) |
| 80 | { |
| 81 | printf("SurfaceToPPM: Unable to create target Texture resoruce! Aborting... \n"); |
| 82 | return E_FAIL; |
| 83 | } |
| 84 | |
| 85 | pDeviceCtxt->CopyResource(pTargetTexture,pSourceTexture); |
| 86 | |
| 87 | D3D11_MAPPED_SUBRESOURCE mappedTex2D; |
| 88 | pDeviceCtxt->Map(pTargetTexture, 0, D3D11_MAP_READ,0,&mappedTex2D); |
| 89 | |
| 90 | // Need to convert from dx pitch to pitch=width |
| 91 | unsigned char *pPPMData = new unsigned char[desc.Width*desc.Height*4]; |
| 92 | |
| 93 | for (unsigned int iHeight = 0; iHeight<desc.Height; iHeight++) |
| 94 | { |
| 95 | memcpy(&(pPPMData[iHeight*desc.Width*4]),(unsigned char *)(mappedTex2D.pData)+iHeight*mappedTex2D.RowPitch,desc.Width*4); |
| 96 | } |
| 97 | |
| 98 | pDeviceCtxt->Unmap(pTargetTexture, 0); |
| 99 | |
| 100 | // Prepends the PPM header info and bumps byte data afterwards |
| 101 | sdkSavePPM4ub(zFileName, pPPMData, desc.Width, desc.Height); |
| 102 | |
| 103 | delete [] pPPMData; |
| 104 | pTargetTexture->Release(); |
| 105 | |
| 106 | return S_OK; |
| 107 | } |
| 108 | |
| 109 | bool CheckRenderD3D11::PPMvsPPM(const char *src_file, const char *ref_file, const char *exec_path, |
| 110 | const float epsilon, const float threshold) |
nothing calls this directly
no test coverage detected