DDS saving but not a BMP
mister-404 opened this issue · 2 comments
The below function successfully receives a texture ptr from Unity and saves the file to a DDS but cannot make a BMP version.
void SavePNG(void* textHandle) {
using namespace DirectX;
using namespace Microsoft::WRL;
IUnityGraphicsD3D11* d3d = s_UnityInterfaces->Get<IUnityGraphicsD3D11>();
auto m_Device = d3d->GetDevice();
ID3D11DeviceContext* ctx = NULL;
m_Device->GetImmediateContext(&ctx);
ID3D11Texture2D* camText = (ID3D11Texture2D*)textHandle;
D3D11_TEXTURE2D_DESC descrip;
camText->GetDesc(&descrip);
HRESULT hr = SaveDDSTextureToFile(ctx, (ID3D11Resource*)textHandle,
L"C:\\Users\\main\\Desktop\\HMM.dds");
hr = SaveWICTextureToFile(ctx, (ID3D11Resource*)textHandle,
GUID_ContainerFormatBmp, L"C:\\Users\\main\\Desktop\\HMM.bmp");
_com_error err(hr);
LPCTSTR errMsg = err.ErrorMessage();
//write to a text file to confirm that the texture data from unity got here
std::ofstream outFile("C:\\Users\\main\\Desktop\\Report.txt");
outFile << "TextureHandle: " << textHandle << std::endl;
outFile << "Width from descrip: " << descrip.Width << std::endl;
outFile << "Height from descrip: " << descrip.Height << std::endl;
outFile << "HRESULT: " << hr << std::endl;
outFile << "Err Message: " << errMsg << std::endl;
outFile << "Color Format: " << descrip.Format << std::endl;
outFile.close();
ctx->Release();
}
That report file is thus:-
TextureHandle: 00000251E7279A38
Width from descrip: 1920
Height from descrip: 1080
HRESULT: -2147024846
Err Message: 000002520D9A3AE0
Color Format: 9
It says here that I can't upload a DDS file so I've included a PNG conversion that I made using Paint.NET here:-
Some pointers on where I'm going wrong would be awesome. I'm really eager to learn as much about DX11 as possible and I'm having so much fun with it.
Thanks a bunch!
DXGI color format 9 is DXGI_FORMAT_R16G16B16A16_TYPELESS
. This is not a format that maps to a native Windows Imaging Component (WIC) pixel format. DDS can read/write all DXGI formats, but standard image formats cannot.
Thanks ever so much!
I'm going to attempt to copy the pixel values into a new texture with a new colour format that bitmaps agree with.
I really appreciate your time.