According to the documentation http://msdn.microsoft.com/en-us/library/windows/desktop/ff476635(v=vs.85).aspx
ID3D11Texture2D inherits from the ID3D11Resource.
I tried the following but it gives a std:non-rtti exception.
ID3D11Texture2D *tex2d = dynamic_cast<ID3D11Texture2D*>(resource);
Since ID3D11Texture2D
is a COM interface you should use QueryInterface
to get other interfaces the object might support. Something like this:
HRESULT hr = resource->QueryInterface(IID_ID3D11Texture2D, (void **) &tex2d);
if (FAILED(hr)) {
// handle failure here.
}
Note this still can still fail if the object pointed to by resource
doesn't implement the ID3D11Texture2D
interface, that is, it's not a 2D texture resource.
Strictly speaking you should also be using QueryInterface
to "up cast" ID3D11Texture2D
interfaces to ID3D11Resource
interfaces. COM doesn't require that if an object implements a derived interface that it also implement the base interface. However up casting should work with any Direct3D COM interface.
Its unneccessary to Use Queryinterface if you know what type of Resource it is.
ID3D11Texture2D* ptx = NULL;
resource->GetResource(reinterpret_cast<ID3D11Resource**>(&ptx));
Though if the rviews contains a varity of types Query i needed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.