微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Visual Studio .CreateInputLayout 的东西

如何解决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 举报,一经查实,本站将立刻删除。