Jump to content
  • Advertisement
Sign in to follow this  

Data of texture

This topic is 2089 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, help please, how get data of texture, i have D3D11Texture2D interface, i need get color of texels in texture(

Share this post

Link to post
Share on other sites

i try so:

ID3D11Texture2D *tex;
ZeroMemory(&td, sizeof(td));
td.Usage = D3D11_USAGE_STAGING;
td.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
td.MipLevels = 1;
if(FAILED(g_pd3d11Device->CreateTexture2D(&td, NULL, &tex)))
return 0;
g_pd3d11DeviceContext->Map(tex, 0, D3D11_MAP_READ, 0, &ms);
int *buff = new int[td.Width * td.Height];
buff = (int*)ms.pData;
where text it is interface ID3D11Texture2D.
having D3D11_TEXTURE2D_DESC:
width = 400;

height = 400;
MipLevels = 9;
ArraySize = 1;
SampleDesc.count = 1;
SampleDesc.Quality = 0;
BindFlags = 8;
CPUAccessFlags = 0;
MiscFlags = 0;

but, it is no working, what is the problem ?
Edited by NEvOl

Share this post

Link to post
Share on other sites

You're on the right track, however, what exactly isn't working? Does it crash, silently fail, etc?


  1. I'm not sure if it's possible to use D3D11_BIND_SHADER_RESOURCE flag with D3D11_USAGE_STAGING, try to set bind flags to 0.
  2. You have different number of mip levels, it might be unable to copy data because of that (I've failed to find info on MSDN).
  3. 400x400 texture isn't power of 2, therefore it's most likely bigger than (td.Width * td.Height), use D3D11_MAPPED_SUBRESOURCE::RowPitch value for "width".
Edited by Zaoshi Kaba

Share this post

Link to post
Share on other sites

i try copy data in buff, There are only zeros(
I try set D3D11_BIND_SHADER_RESOURCE but then tex is not create

Edited by NEvOl

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!