我想从纹理创建渲染目标视图,以用于多个目标渲染。我目前能够为后台缓冲区创建渲染目标视图 - 所有这些都可以很好地工作。此外,我能够创建纹理。但是,当我尝试从中构建视图时,我收到错误。
首先,这是代码:
D3D11_TEXTURE2D_DESC textureDesc;
ZeroMemory(&textureDesc, sizeof(textureDesc));
textureDesc.ArraySize = 1;
textureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
textureDesc.CPUAccessFlags = 0;
textureDesc.Format = DXGI_FORMAT_R32_FLOAT;
textureDesc.Height = m_renderTargetSize.Height;
textureDesc.Width = m_renderTargetSize.Width;
textureDesc.MipLevels = 1;
textureDesc.MiscFlags = 0;
textureDesc.SampleDesc.Count = 1;
textureDesc.SampleDesc.Quality = 0;
textureDesc.Usage = D3D11_USAGE_DEFAULT;
ComPtr<ID3D11Texture2D> texture;
DX::ThrowIfFailed(
m_d3dDevice->CreateTexture2D(
&textureDesc,
nullptr,
&texture
)
);
D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDescription;
ZeroMemory(&renderTargetViewDescription, sizeof(renderTargetViewDescription));
renderTargetViewDescription.Format = textureDesc.Format;
DX::ThrowIfFailed(
m_d3dDevice->CreateRenderTargetView(
texture,
&renderTargetViewDescription,
&m_renderTargetView[1]
)
);
我在调用CreateRenderTargetView
:
错误:没有合适的转换功能 “Microsoft :: WRL :: ComPtr”改为“ID3D11Resource *” 存在。
According to MSDN,ID3D11Texture2D继承自ID3D11Resource。我必须先以某种方式向上倾斜吗?
我在DirectX 11中工作,并使用vc110进行编译。
答案 0 :(得分:2)
似乎WRL的ComPtr不支持隐式转换为T *(与ATL的CComPtr不同),因此您需要使用Get方法:
DX::ThrowIfFailed(
m_d3dDevice->CreateRenderTargetView(
texture.Get(),
&renderTargetViewDescription,
&m_renderTargetView[1]
)
);