I follow the book "Introduction to 3D Game Programming with DIRECTX 11" to load several textures and its mipmaps, then copy into a texture array. But there is a problem with mipmaps. I am not sure the reason so now I want to check each mipmap of each loaded texture 2D by saving each mipmap to a file, but I do not know how to do that.
The following source code is used to load 2D textures and its mipmap (automatically generated by GPU):
D3DX11_IMAGE_LOAD_INFO loadInfo;
loadInfo.Width = 1024;
loadInfo.Height = 1024;
loadInfo.Depth = 0;
loadInfo.FirstMipLevel = 0;
loadInfo.MipLevels = 0;
loadInfo.Usage = D3D11_USAGE_STAGING;
loadInfo.BindFlags = 0;
loadInfo.CpuAccessFlags = D3D10_CPU_ACCESS_WRITE | D3D10_CPU_ACCESS_READ;
loadInfo.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;
loadInfo.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
loadInfo.Filter = D3DX11_FILTER_NONE;
loadInfo.MipFilter = D3DX11_FILTER_NONE;
loadInfo.pSrcInfo = 0;
vector<string> m_sTextureNames;
m_sTextureNames.push_back("MovingBox/metalcrate-L.jpg");
UINT iNumOfMaterials = (UINT)m_sTextureNames.size();
g_pTexture2Ds.resize(iNumOfMaterials);
for (UINT i = 0; i<iNumOfMaterials; i++)
{
if (m_sTextureNames[i].compare("") != 0)
{
V(D3DX11CreateTextureFromFileA(pd3dDevice, m_sTextureNames[i].c_str(),
&loadInfo, 0, (ID3D11Resource**)&g_pTexture2Ds[i], 0));
}
}
Is there anyone know to save a mipmap of a 2D texture to a file?