Visual Studio .CreateInputLayout 的东西

问题描述

InputLayout::InputLayout(Graphics& gfx,const std::vector<D3D11_INPUT_ELEMENT_DESC>&layout,ID3DBlob* pVertexByteCode) : pInputLayout(&layout)
{
    INFOMAN(gfx);

    GFX_THROW_INFO(GetDevice(gfx)->CreateInputLayout(
        layout.data(),(UINT)layout.size(),pVertexByteCode->GetBufferPointer(),pVertexByteCode->GetBufferSize(),pInputLayout.GetAddressOf()));
}

问题是在编译这段代码后我得到:

1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\winrt\wrl\client.h(252,45): error C2440: 'initializing': cannot convert from 'U *' to 'ID3D11InputLayout *'
1>        with
1>        [
1>            U=const std::vector<D3D11_INPUT_ELEMENT_DESC,std::allocator<D3D11_INPUT_ELEMENT_DESC>>
1>        ] (compiling source file InputLayout.cpp)
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\winrt\wrl\client.h(252,45): message : Types pointed to are unrelated; conversion requires reinterpret_cast,C-style cast or function-style cast (compiling source file InputLayout.cpp)
1>D:\visual studio\prog\Gameprojdirect3d\GameprojectDirect3D\GameprojectDirect3D\InputLayout.cpp(10): message : see reference to function template instantiation 'Microsoft::WRL::ComPtr<ID3D11InputLayout>::ComPtr<const std::vector<D3D11_INPUT_ELEMENT_DESC,std::allocator<D3D11_INPUT_ELEMENT_DESC>>>(U *) noexcept' being compiled
1>        with
1>        [
1>            U=const std::vector<D3D11_INPUT_ELEMENT_DESC,std::allocator<D3D11_INPUT_ELEMENT_DESC>>
1>        ]
1>D:\visual studio\prog\Gameprojdirect3d\GameprojectDirect3D\GameprojectDirect3D\InputLayout.cpp(9): message : see reference to function template instantiation 'Microsoft::WRL::ComPtr<ID3D11InputLayout>::ComPtr<const std::vector<D3D11_INPUT_ELEMENT_DESC,std::allocator<D3D11_INPUT_ELEMENT_DESC>>
1>        ]

错误出现在 CreateInputLayout 的第一个参数处,在我看来是向量类型导致它(不知何故)所以我创建了一个数组,但它没有用

InputLayout::InputLayout(Graphics& gfx,ID3DBlob* pVertexByteCode) : pInputLayout(&layout)
{
    INFOMAN(gfx);
    const D3D11_INPUT_ELEMENT_DESC ied[] =
    {
        {"Position",0u,dxgi_FORMAT_R32G32B32_FLOAT,D3D11_INPUT_PER_VERTEX_DATA,0}
    };
    GFX_THROW_INFO(GetDevice(gfx)->CreateInputLayout(
        ied,pInputLayout.GetAddressOf()));
}

这会导致同样的错误。 我很困惑,因为它在其他具有类似语法的文件中工作

wrl::ComPtr<ID3D11InputLayout> pInputLayout;
const D3D11_INPUT_ELEMENT_DESC ied[] = 
{ 
    {"Position",0},{"Color",dxgi_FORMAT_R8G8B8A8_UnorM,12u,0}
};
GFX_THROW_INFO(pDevice->CreateInputLayout(ied,(UINT)std::size(ied),pBlob->GetBufferPointer(),pBlob->GetBufferSize(),&pInputLayout));

注意:GetDevice(gfx) 返回 ID3D11Device*,它是主要的图形设备,而 pInputLayout(在之前的代码中)来自不同的类

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)