Jump to content

  • Log In with Google      Sign In   
  • Create Account


Is this the correct way of mapping a texture


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 lomateron   Members   -  Reputation: 303

Like
0Likes
Like

Posted 20 March 2013 - 10:51 AM

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, 20 March 2013 - 01:10 PM.


Sponsor:

#2 mhagain   Crossbones+   -  Reputation: 7599

Like
2Likes
Like

Posted 20 March 2013 - 02:35 PM

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).


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#3 Jason Z   Crossbones+   -  Reputation: 4859

Like
0Likes
Like

Posted 20 March 2013 - 03:16 PM

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.



#4 mhagain   Crossbones+   -  Reputation: 7599

Like
0Likes
Like

Posted 20 March 2013 - 03:43 PM

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, 20 March 2013 - 03:44 PM.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.





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