问题
I have created a red colored texture of DXGI format DXGI_FORMAT_R32_FLOAT. I have a byte buffer of red color pixels where 4 byte per pixel is prepared. The byte buffer is then copied using device context map and unmap functions and after that I have created a shader resource view. I have get the resource back from resource view then passed that to SaveDDSTextureToFile() to save the bitmap data to dds file format. But when I am going to save it in dds in file to check it's saves a same sized texture which is total black. Where should I look at to debug?
D3D11_TEXTURE2D_DESC desc;
ZeroMemory(&desc, sizeof(desc));
desc.Width = static_cast<UINT>(renderTarget.width);
desc.Height = static_cast<UINT>(renderTarget.height);
desc.ArraySize = 1;
desc.Format = DXGI_FORMAT_R32_FLOAT;
desc.Usage = D3D11_USAGE_DYNAMIC;
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
desc.MipLevels = 1;
desc.SampleDesc.Count = 1;
...
SaveDDSTextureToFile(renderer->Context(), texture2D, L"D:\\RED.dds");
I have created the red texture buffer by following:
CImage m_cImage;
// create a test image
m_cImage.Create(w, -h, 8 * 4); // 8 bit * 4 channel => 32 bpp or 4 byte per pixel
auto hdc = m_cImage.GetDC();
Gdiplus::Graphics graphics(hdc);
// Create a SolidBrush object.
Gdiplus::SolidBrush redBrush(Gdiplus::Color::Red);
// Fill the rectangle.
Gdiplus::Status status = graphics.FillRectangle(&redBrush, 0, 0, w, h);
TRY_CONDITION(status == Gdiplus::Status::Ok);
....
// Then saved the m_cImage.GetBits() to bmp file using Gdiplus::Bitmap
// and my expected texture is found
来源:https://stackoverflow.com/questions/53911432/saveddstexturetofile-saves-a-black-texture-instead-the-expected