I'm trying to copy vector of DirectX::XMMATRIX elements into a Direct3D vertex shader constant buffer, but it only copies the first element (which is 4x4 float matrix, which is 64 bytes), resulting in an exception (it expects 3 elements, 192 bytes total, which vector has)
Here's a sample code:
template<typename C>
void Update(const std::vector<C>* cbuf)
{
D3D11_MAPPED_SUBRESOURCE msr = {};
GetContext()->Map(m_pConstBuffer.Get(), 0u, D3D11_MAP_WRITE_DISCARD, 0u, &msr);
memcpy(msr.pData, &cbuf[0], sizeof(C) * cbuf->size());
GetContext()->Unmap(m_pConstBuffer.Get(), 0u);
}
I also tried memcpy(msr.pData, cbuf->data(), sizeof(C) * cbuf->size()), as well as specifically stating to copy 192 bytes - and yes - sizeof(C) * cbuf->size() results in 192 - but it still copies 64 bytes of the first element
So what's wrong? Isn't the vector contiguous?