Sign in to follow this  
lomateron

Is this the correct way of mapping a texture

Recommended Posts

lomateron    491

I want to save a complete texture that is in GPU memory in a file.

So i am doing this:

 

D3D10_MAPPED_TEXTURE2D ddMap;

BallsTexACPU->Map(0, D3D10_MAP_READ, 0, &ddMap);
fwrite (ddMap.pData , 16*res*res , 1 , SaveStructFile );       //(res*res) the number of pixels in the texture, 16 bytes in each pixel
BallsTexACPU->Unmap(0);

 

 
BallsTexACPU is a ( ID3D10Texture2D* ) it has D3D10_USAGE_STAGING, D3D10_CPU_ACCESS_READ
 
I just want to know if
BallsTexACPU->Map(0, D3D10_MAP_READ, 0, &ddMap);
fwrite (ddMap.pData , 16*res*res , 1 , SaveStructFile );
is correct
Edited by lomateron

Share this post


Link to post
Share on other sites
mhagain    13430

It's partially correct; you will successfully get access to the texels and you will write them out to file.

 

What you write out may not be what you want, however, because you're not taking account of the RowPitch member of ddMap.  What you want instead would be something like this:

 

byte *mapped = (byte *) ddMap.pData;

for (int i = 0; i < res; i++)
{
    fwrite (mapped, res * 16, 1, SaveStructFile);
    mapped += ddMap.RowPitch;
}

 

(This is just code written off the top of my head - you may need to adjust it to get it to work).

(And don't forget to test "if (SUCCEEDED" from your Map call).

Share this post


Link to post
Share on other sites
Jason Z    6434

I second the response from mhagain - you have to take into account the row size for the texture.  Sometimes the GPU driver can store additional information at the end of each row of texels depending on its implementation.  I honestly don't recall seeing any instances of this lately, but for sure back in the D3D9 days it was frequent that there was extra data appended to each row.

Share this post


Link to post
Share on other sites
mhagain    13430

I've seen an AMD 6450 do it with a rendertarget recently, so I can confirm that it is still something you need to be on the lookout for (in the rendertarget case saving a screenshot to disk would be an example of where it would matter, which is what I suspect you may be doing here).

Edited by mhagain

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this