I have a protocol to prepare with a combining shader a texture from two other textures and saving it in RGBA8_UNORM DDS format using DX11SaveTextureToFile. Works fine. It appears to me that I don't really need the A channel and want to use RGB565_UNORM instead with the corresponding combining shader. But the outputed file can't be reopen, including with DXtexTool. The DX11CfreateShaderResourceViewFromFile return E_FAIL. I've seen that some header is added for non standard RGB format but I guess this may be handled by the loader/saver functions.
I use DX11CfreateShaderResourceViewFromFile this way:
DX11CreateShaderResourceViewFromFile(pDC11, FileName, NULL, NULL, &pSRV, NULL);
Should I add someting to consider any added header?
Answering the comment the code used for this combination
ID3D11Texture2D* pTex = NULL;
ID3D11RenderTargetView* pRTVGen = NULL;
DXGI_FORMAT RTVFormat = DXGI_FORMAT_R8G8B8A8_UNORM;//changing to B5G6R5 is my problem
pTex = CreateTexture2D(256, 256, RTVFormat, /D3D11_BIND_RENDER_TARGET);//function to create the texture that works in all my projects
pRTVGen = CreateRenderTargetView2D(pTex, RTVFormat); );//function to create the rendertarget that works in all my projects
gpCurShader = SetShader2(dwSD_GenerateMaps);
gpDC11->PSSetSamplers(0, 1, &gpSampler[cS_Linear]);
gpDC11->OMSetRenderTargets(1, &pRTVGen, NULL);
D3D11_VIEWPORT VP;
VP.Height = 256;
VP.Width = 256;
VP.TopLeftX = VP.TopLeftY = 0;
VP.MinDepth = 0;
VP.MaxDepth = 1;
gpDC11->RSSetViewports(1, &VP);
for (DWORD n = 0; n < 30; n++)
{
if (n < 10)sprintf_s(buf, "C:\\Wired\\Images\\Ripples\\ripples_000%d.bmp", n);
else sprintf_s(buf, "C:\\Wired\\Images\\Ripples\\ripples_00%d.bmp", n);
DWORD RippleIndex = AddSRVMaterial(buf, NULL, 0);
//AddSRVMaterial add the new created texture to a gppS texture list //AddSRVMaterial contains HRESULT hr = D3DX11CreateShaderResourceViewFromFileA(gpD11, File, NULL, NULL, &pSRV, NULL); pSRV is the ShaderResource created
gpDC11->PSSetShaderResources(0, 1, &gppS[RippleIndex]->pSRV);
if (n < 10)sprintf_s(buf, "C:\\Wired\\Images\\Ripples\\NNoise000%d.bmp", n);
else sprintf_s(buf, "C:\\Wired\\Images\\Ripples\\NNoise00%d.bmp", n);
DWORD NoiseIndex = AddSRVMaterial(buf, NULL, 0);//function to add the new textue to my texture list
gpDC11->PSSetShaderResources(1, 1, &gppS[NoiseIndex]->pSRV);//gppS is my texture list
RenderMeshSingle(gpMeshSceneQuad);//function to render to the texture
WCHAR wbuf[MAX_PATH];
if (n < 10)wsprintf(wbuf, L"C:\\Wired\\Images\\Ripples\\ripplesnoise_000%d.dds", n);
else wsprintf(wbuf, L"C:\\Wired\\Images\\Ripples\\ripplesnoise_00%d.dds", n);
HRESULT hr = D3DX11SaveTextureToFile(gpDC11, pTex, D3DX11_IFF_DDS, wbuf);
if (hr != S_OK)//Note hr is always S_OK even when the output file is uncorrect for DX11CreateFromFile//
{
sprintf_s(buf, "Error DXSaveTex %d\n", hr);
OutputDebugStringA(buf);
}
pRTVGen->Release();
pTex->Release();
content of
ID3D11Texture2D* CreateTexture2D(DWORD Width, DWORD Height, DXGI_FORMAT Format, UINT BindFlag)
{
ID3D11Texture2D* pTex = NULL;
D3D11_TEXTURE2D_DESC TexDesc;
ZeroMemory(&TexDesc, sizeof(TexDesc));
TexDesc.Width = Width;
TexDesc.Height = Height;
TexDesc.MipLevels = 1;
TexDesc.ArraySize = 1;
TexDesc.Format = Format;
TexDesc.SampleDesc.Count = 1;
TexDesc.SampleDesc.Quality = 0;
TexDesc.Usage = D3D11_USAGE_DEFAULT;
TexDesc.BindFlags = BindFlag;
TexDesc.CPUAccessFlags = 0;
TexDesc.MiscFlags = 0;
HRESULT hr = gpD11->CreateTexture2D(&TexDesc, NULL, &pTex);
if (FAILED(hr)) return NULL;
return pTex;
}
Content of
ID3D11RenderTargetView* CreateRenderTargetView2D(ID3D11Texture2D* pText2D, DXGI_FORMAT Format)
{
ID3D11RenderTargetView* pRTV = NULL;
D3D11_RENDER_TARGET_VIEW_DESC RTVDesc;
RTVDesc.Format = Format;
RTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
RTVDesc.Texture2D.MipSlice = 0;
HRESULT hr = gpD11->CreateRenderTargetView(pText2D, &RTVDesc, &pRTV);
if (FAILED(hr)) return NULL;
return pRTV;
}
pixel shader to fill the texture.
An ifdef is used to select RGBA8 or BGR565 formats during compilation
#ifdef SM_GENF3
float3 PS_GenRain(PS_INPUTQUAD Input): SV_TARGET
{
float3 FinalColor = float3(0,0,0);
FinalColor.rg = txRipple.Sample(samLinear, Input.Tex).rg;
FinalColor.b = txNoise.Sample(samLinear, Input.Tex).b;
return FinalColor;
};
#else
float4 PS_GenRain(PS_INPUTQUAD Input): SV_TARGET
{
float4 FinalColor = float4(0,0,0,0);
FinalColor.rg = txRipple.Sample(samLinear, Input.Tex).rg;
FinalColor.ba = txNoise.Sample(samLinear, Input.Tex).rb;
return FinalColor;
};
#endif
Result for n =0 with RGBA8