Get Texture2DDescription from ShaderResourceView

Started by
4 comments, last by Telanor 11 years, 11 months ago
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?
Advertisement
The descriptions are strongly typed. As such you will find them under the derived type from Resource... i.e. Texture2D.Description

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

So I do something like this?


var resource = (Texture2D)texture.Resource;
perBatch.TextureSize = new Vector2(resource.Description.Width, resource.Description.Height);
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).

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

Casting will work just fine. There's no need to use the FromPointer method, which is intended only for interop with external libraries.
Mike Popoloski | Journal | SlimDX
Alright, thanks. I'd test it but I'm still in the process of converting from XNA to slimdx so I can't yet.

This topic is closed to new replies.

Advertisement