Advertisement

Data of texture

Started by January 31, 2014 03:07 PM
2 comments, last by NEvOl 11 years ago
Hi, help please, how get data of texture, i have D3D11Texture2D interface, i need get color of texels in texture(

i try so:

ID3D11Texture2D *tex;
 
D3D11_TEXTURE2D_DESC td;
 
ZeroMemory(&td, sizeof(td));
 
text->GetDesc(&td);
 
td.Usage = D3D11_USAGE_STAGING;
td.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
td.BindFlags = D3D11_BIND_SHADER_RESOURCE;
td.MipLevels = 1;
 
if(FAILED(g_pd3d11Device->CreateTexture2D(&td, NULL, &tex)))
return 0;
 
g_pd3d11DeviceContext->CopyResource(tex,text);
 
D3D11_MAPPED_SUBRESOURCE ms;
 
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;
Format= DXGI_FORMAT_R8G9B9A8_UNORM;
SampleDesc.count = 1;
SampleDesc.Quality = 0;
Usage = D3D11_USAGE_DEFAULT;
BindFlags = 8;
CPUAccessFlags = 0;
MiscFlags = 0;

but, it is no working, what is the problem ?
Advertisement

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

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

This topic is closed to new replies.

Advertisement