SaveDDSTextureToFile()保存黑色纹理,而不是预期的

时间:2018-12-24 09:18:45

标签: directx-11 texture2d dxgi wic directxtk

我创建了DXGI格式DXGI_FORMAT_R32_FLOAT的红色纹理。我有一个红色像素的字节缓冲区,每个像素准备4个字节。然后使用设备上下文映射和取消映射功能复制字节缓冲区,然后创建着色器资源视图。我已经从资源视图中获取了资源,然后将其传递给SaveDDSTextureToFile()以将位图数据保存为dds文件格式。 但是,当我要将其保存在dds文件中以进行检查时,会保存相同大小的纹理,即黑色。我应该在哪里调试?

    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");

我通过以下步骤创建了红色纹理缓冲区:

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

0 个答案:

没有答案