Jump to content

  • Log In with Google      Sign In   
  • Create Account


Accessing the data inside a texture from C++


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
2 replies to this topic

#1 drowsyn   Members   -  Reputation: 142

Like
0Likes
Like

Posted 26 February 2012 - 09:07 AM

Is there a way to read the raw data inside a ID3D11Texture2D? I want to build a set of vertices and normals from a heightmap texture, but can't figure out how to actually get access to the color data. My assumption was that Map would be the solution, but for whatever reason I can't get it to work (there's no errors, which makes it all the more annoying). Am I approaching this wrong, or am I just screwing up somewhere?

// Load the texture
D3DX11_IMAGE_LOAD_INFO loadInfo;
loadInfo.MipLevels = 1;
loadInfo.Usage = D3D11_USAGE_STAGING;
loadInfo.CpuAccessFlags = D3D11_CPU_ACCESS_READ;

hr = D3DX11CreateTextureFromFile(g_D3DDevice, L"heightmap8x8.bmp", &loadInfo, NULL, (ID3D11Resource**)(&g_HeightmapTex), NULL);
if (FAILED(hr))
	 return hr;

// Try to access it's data
D3D11_MAPPED_SUBRESOURCE subres;
hr = g_D3DDeviceContext->Map(g_HeightmapTex, 0, D3D11_MAP_READ, NULL, &subres);
if (FAILED(hr))
	 return hr;
// do something with the data
g_D3DDeviceContext->Unmap(g_HeightmapTex, 0);

I can use the texture in a shader so it shouldn't be an issue of it not loading properly. I played around with the Usage and CpuAccessFlags, but I'm fairly certain that this is the way they should be set up if I want to just read the texture. As I said, I'm not getting any access errors (or any errors period), the application just exits quietly shortly after starting. PIX isn't helping me either.

Hopefully someone can smash me in the head with the Bat of Knowledge. Thanks in advance!


Sponsor:

#2 drowsyn   Members   -  Reputation: 142

Like
0Likes
Like

Posted 26 February 2012 - 11:56 AM

I guess writing about the problem can be helpful. I figured out that I have to assign 0 to loadInfo.BindFlags for a read-only Mapping (that's not the correct term, surely?)

I do wish Visual Studio gave me a hint though!


#3 MJP   Moderators   -  Reputation: 8829

Like
0Likes
Like

Posted 26 February 2012 - 02:41 PM

0 is the only valid value for the bind flags of a staging texture. If you enable the DEBUG flag on the device and link to the debug version of D3DX, the you should get an error message.




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