Creating texture with initial subresource data not working

Started by
2 comments, last by MJP 11 years, 8 months ago
Im trying to create a texture with a ray casted scene array of a Color3 struct of mine:
Color3{
float r, g, b;
}
The values are in the [0,1] range.

Heres what Im trying:

ID3D11Texture2D * CreateTextureFromRayTracedScene( ID3D11Device *pDXDevice_p){
if( m_pScene == NULL ) return NULL;
D3D11_TEXTURE2D_DESC desc;
memset(&desc, 0, sizeof(D3D11_TEXTURE2D_DESC));
desc.Format = DXGI_FORMAT::DXGI_FORMAT_R32G32B32_FLOAT;
desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
desc.Usage = D3D11_USAGE_DYNAMIC;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
desc.Width = (UINT)m_pScene->m_res[0];
desc.Height = (UINT)m_pScene->m_res[1];
desc.SampleDesc.Count = 1;
desc.MipLevels = 1;
desc.ArraySize = 1;
D3D11_SUBRESOURCE_DATA texData;
texData.SysMemSlicePitch = 0;
texData.SysMemPitch = desc.Width * 4 * 3;// 32 bits(4 bytes) per channel, 3 channels.
texData.pSysMem = m_pTracedSceneIMG;

ID3D11Texture2D *pTex2D;
HRESULT hr = pDXDevice_p->CreateTexture2D( &desc, &texData, &pTex2D );
if( hr != S_OK ){
switch(hr){
case D3DERR_INVALIDCALL:
m_logger<<"D3DERR_INVALIDCALL creating texture"<<SZ_NEWLINE;
break;
case E_INVALIDARG:
m_logger<<"E_INVALIDARG creating texture"<<SZ_NEWLINE;
break;
case S_FALSE:
m_logger<<"S_FALSE creating texture"<<SZ_NEWLINE;
break;
case E_FAIL:
m_logger<<"E_FAIL creating texture"<<SZ_NEWLINE;
break;
}
return NULL;
}
return pTex2D;
}

Than I call:

ID3D11Texture2D *pTex = myRayTracer.CreateTextureFromRayTracedScene(AppFrame.GetDXDeviceReference());
D3DX11SaveTextureToFile( AppFrame.GetDXDeviceConextReference(), pTex, D3DX11_IFF_DDS, TEXT("rayTIMG.dds"));
pTex->Release();


Im trying with dds because with png notting is created, with dds a file is created, but my nvidia dds visualizer show it as 0x0 size, so, something is wrong here, and I dont know what is.
m_pTracedSceneIMG is for sure not empty, its an Color3[400x400] array, desc.width and height are also 400..
Gotta be a logical problem that Im not seeing.
Advertisement
For DX10 they extended the DDS file format, and the D3DX functions will save using the newer format. Unfortunately, almost nobody supports the new format. So it's likely that your Nvidia viewer is just reading it incorrectly.
What format do I use to save to a png? theres no R8G8B8..
R32G32B32_UINT saves an image, but setting it on [0, 255] or [0,1] is not working, Im trying this img:

Color3 img[] =
{{128, 128, 128},{128, 128, 128},{128, 0, 0},{128, 0, 0},
{128, 128, 128},{128, 128, 128},{128, 0, 0},{128, 0, 0},
{128, 0, 0},{128, 0, 0},{128, 128, 128},{128, 128, 128},
{128, 0, 0},{128, 0, 0},{128, 128, 128},{128, 128, 128}};

(tried with .5f instead of 128 too)
Its always showing white and red, instead of gray.
Can I do this without transforming the current array that is in the range [0,1]?
You'll only be able to save that DXGI format as a .DDS. If you just want to view it there's a viewer included in DirectXTex that can handle the new DDS format. You can also just capture with PIX and look at the texture in there.

This topic is closed to new replies.

Advertisement