本文介绍了下铸ID3D11Texture2D的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据文档



ID3D11Texture2D继承来自ID3D11Resource。



我尝试了以下操作,但它给出了std:non-rtti异常。

  ID3D11Texture2D * tex2d = dynamic_cast< ID3D11Texture2D *>(资源); 


解决方案

由于 ID3D11Texture2D 是COM接口,应使用 QueryInterface 获取该对象可能支持的其他接口。像这样的东西:
if(FAILED(hr)){
//在这里处理失败。
}

请注意,如果<$ c $指向的对象仍然无法通过此操作c> resource 没有实现 ID3D11Texture2D 接口,也就是说,它不是2D纹理资源。



严格来说,您还应该使用 QueryInterface 来转换 ID3D11Texture2D 接口到 ID3D11Resource 接口。 COM不需要,如果一个对象实现一个派生的接口,它也将实现基本的接口。但是,向上转换应可与任何Direct3D COM接口一起使用。


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.

这篇关于下铸ID3D11Texture2D的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-04 23:46