• Advertisement
Sign in to follow this  

Get Texture2DDescription from ShaderResourceView

This topic is 2079 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

In c++ you can do the following to get the dimensions of a ShaderResourceView:


void foo(ID3D11ShaderResourceView* texture)
{
ID3D11Resource* resource;
ID3D11Texture2DPtr texResource;
D3D11_TEXTURE2D_DESC desc;
texture->GetResource(&resource);
texResource.Attach(reinterpret_cast<ID3D11Texture2D*>(resource));
texResource->GetDesc(&desc);
perBatch.TextureSize = XMFLOAT2(static_cast<float>(desc.Width), static_cast<float>(desc.Height));
}


I'm trying to accomplish the same thing in SlimDX but I can't seem to figure out how. The logical way seems to be texture.Resource.Description.Width but the Direct3D11.Resource class doesn't have a Description property. Anyone know how to do this in SlimDX?

Share this post


Link to post
Share on other sites
Advertisement
The descriptions are strongly typed. As such you will find them under the derived type from Resource... i.e. Texture2D.Description

Share this post


Link to post
Share on other sites
So I do something like this?


var resource = (Texture2D)texture.Resource;
perBatch.TextureSize = new Vector2(resource.Description.Width, resource.Description.Height);

Share this post


Link to post
Share on other sites
I don't think that will work (it might, but doubtful)...

var resource = new Texture2D.FromPointer(texture.Resource.ComPointer);

should work, just remember to dispose of it when done, probably. depending on if you hold a handle to the texture in the resource view or not. (If you do, don't dispose, if you don't, do dispose). Edited by Washu

Share this post


Link to post
Share on other sites
Alright, thanks. I'd test it but I'm still in the process of converting from XNA to slimdx so I can't yet.

Share this post


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

  • Advertisement