Jump to content

  • Log In with Google      Sign In   
  • Create Account

Creating texture with initial subresource data not working


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Icebone1000   Members   -  Reputation: 1146

Like
0Likes
Like

Posted 24 August 2012 - 10:42 PM

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.

Sponsor:

#2 MJP   Moderators   -  Reputation: 11736

Like
1Likes
Like

Posted 25 August 2012 - 12:28 AM

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.

#3 Icebone1000   Members   -  Reputation: 1146

Like
0Likes
Like

Posted 25 August 2012 - 08:36 AM

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]?

#4 MJP   Moderators   -  Reputation: 11736

Like
1Likes
Like

Posted 25 August 2012 - 12:52 PM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS