• Advertisement
Sign in to follow this  

DX10 - How do i CreateTextureFromFile, for reading and writing

This topic is 2309 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, what i want to do is open a texture to read, and create an empty texture to write to. I've been messing with D3DX10CreateTextureFromFile but it doesn't give me a valid ID3D10Resource* if i use D3DX10_IMAGE_LOAD_INFO, ZeroMemory'd or set. Im having trouble mapping a newly created, empty texture too. I'd like to have the empty texture and read and write, so i can check if a pixel is about to be overwritten, but i don't have much knowledge of CpuAccesFlags and BindFlags and Usage stuff. If someone could write up some example code from Declaring/Initialising to Mapping the textures that would be great. The reason why i need to do this, and not in a shader, is because i need to write to specific pixels rather than the current one the pixel shader's up to. Thankyou!

Share this post

Link to post
Share on other sites
You can map-write only to :

1) Dynamic Texture (discard everything)
2) Staging Texture (local memory texture)

You can map-read only from :

1) Staging Texture (local memory texture)

If you need to update a default texture use CopySubresourceRegion using a staging texture as mappable.

Share this post

Link to post
Share on other sites
For the texture i want to read from, i currently have this:
ID3D10Resource* m_pDiffuseMap;

ZeroMemory( &loadInfo, sizeof(D3DX10_IMAGE_LOAD_INFO) );
loadInfo.Usage = D3D10_USAGE_DYNAMIC;
loadInfo.CpuAccessFlags = D3D10_CPU_ACCESS_READ;
D3DX10CreateTextureFromFile( md3dDevice, "./Textures/diffuse.jpg", &loadInfo, 0, &m_pDiffuseMap, 0 );

ID3D10Texture2D *pDiffuseTexture = (ID3D10Texture2D*)m_pDiffuseMap;

D3D10_MAPPED_TEXTURE2D mappedDiffuseTex;
pDiffuseTexture->Map( D3D10CalcSubresource(0, 0, 1), D3D10_MAP_READ, 0, &mappedDiffuseTex );

For the texture i want to write to, i have this:
ID3D10Texture2D* m_pResultTexture;
D3D10_TEXTURE2D_DESC m_ResultDesc;

m_ResultDesc.Width = 256;
m_ResultDesc.Height = 256;
m_ResultDesc.MipLevels = m_ResultDesc.ArraySize = 1;
m_ResultDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;//DXGI_FORMAT_R32G32B32A32_FLOAT;
m_ResultDesc.SampleDesc.Count = 1;
m_ResultDesc.Usage = D3D10_USAGE_DYNAMIC;
m_ResultDesc.BindFlags = 0;
m_ResultDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;

md3dDevice->CreateTexture2D( &m_ResultDesc, 0, &m_pResultTexture );

D3D10_MAPPED_TEXTURE2D mappedResultTex;
m_pResultTexture->Map( D3D10CalcSubresource(0, 0, 1), D3D10_MAP_WRITE_DISCARD, 0, &mappedResultTex );

The loadInfo part of reading seems to make things not good.

and the writing to, launches an error when its mapped.
I dont really get what the SDK says but i think im doing it similar

Share this post

Link to post
Share on other sites
You're trying to use D3D10_USAGE_DYNAMIC with D3D10_CPU_ACCESS_READ, which are not compatible, as feal87 already mentioned in his reply.

Share this post

Link to post
Share on other sites
I have same problem.

So how to solve it?

I am a newer, so many things I don't really know.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement