经过几天的输入结构和错误,我终于找到了使用 memcpy 的方法
您可以使用此技术将几乎任何类型的对象或原始数据类型交错到 char 数组中
DirectX::XMFLOAT2 vertices[4] =
{
DirectX::XMFLOAT2(0.5f,0.5f)
,DirectX::XMFLOAT2(-0.5f,0.5f)
,DirectX::XMFLOAT2(-0.5f,-0.5f)
,DirectX::XMFLOAT2(0.5f,-0.5f)
};
DirectX::XMINT3 colors[4] =
{
DirectX::XMINT3(1,0,0)
,DirectX::XMINT3(0,1,0)
,DirectX::XMINT3(1,0,1)
,DirectX::XMINT3(1,1,0)
};
char data[sizeof(DirectX::XMFLOAT2) * 4 + sizeof(DirectX::XMINT3) * 4];
char* ptr = data;
DirectX::XMFLOAT2* vertex = vertices;
DirectX::XMINT3* color = colors;
for (int i = 0; i < 4; i++)
{
memcpy(ptr, vertex, sizeof(DirectX::XMFLOAT2)); //Copy & increment char pointer and vertex pointer
ptr += sizeof(DirectX::XMFLOAT2);
vertex += 1;
memcpy(ptr, color, sizeof(DirectX::XMINT3)); //Copy & increment char pointer and color pointer
ptr += sizeof(DirectX::XMINT3);
color += 1;
}
对此解决方案的任何建议或编辑都将被广泛接受
至于 alignbyteOffset 我们可以使用 D3D11_APPEND_ALIGNED_ELEMENT 而不必担心