I want to get access to a texture's pixel color data on the CPU. When trying to map the texture, I get E_INVALIDARG in return from ID3D11DeviceContext::Map.
ID3D11ShaderResourceView* resourceView; //represents my texture, already loaded up //... //Getting the resources of the texture view... ID3D11Resource* res = nullptr; ID3D11Texture2D* tex = nullptr; resourceView->GetResource(&res); res->QueryInterface(&tex); D3D11_TEXTURE2D_DESC desc; tex->GetDesc(&desc); //Correct data gets filled out D3D11_RESOURCE_DIMENSION dim; res->GetType(&dim); //value gets set as Texture2D which it should D3D11_MAPPED_SUBRESOURCE mappedResource; HRESULT h; h = context->Map(tex,0,D3D11_MAP_READ,0,&mappedResource); //This always fails h = context->Map(res,0,D3D11_MAP_READ,0,&mappedResource); //This also fails
The idea is that I keep only shaderResourceViews for my textures, because that is all I needed until now, and get the relevant resources here.
I tried mapping as WRITE_DISCARD also, but to no success. I am really confused, because I never had any problem with mapping constant buffers and vertex buffers. I seem to be certainly missing something?
By the way, I am using Wic Texture loader and DDS Texture loader for the DirectXTex toolkit, and tried this code for png, dds textures, with and without mip-maps.