Mapping dynamic buffers in Direct3D11 in Windows Store apps
Posted
by
Donnie
on Game Development
See other posts from Game Development
or by Donnie
Published on 2012-11-29T05:08:02Z
Indexed on
2012/11/29
5:21 UTC
Read the original article
Hit count: 314
I'm trying to make instanced geometry in Direct3D11, and the ID3D11DeviceContext1->Map()
call is failing with the very helpful error of "Invalid Parameter" when I'm attempting to update the instance buffer.
The buffer is declared as a member variable:
Microsoft::WRL::ComPtr<ID3D11Buffer> m_instanceBuffer;
Then I create it (which succeeds):
D3D11_BUFFER_DESC instanceDesc;
ZeroMemory(&instanceDesc, sizeof(D3D11_BUFFER_DESC));
instanceDesc.Usage = D3D11_USAGE_DYNAMIC;
instanceDesc.ByteWidth = sizeof(InstanceData) * MAX_INSTANCE_COUNT;
instanceDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
instanceDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
instanceDesc.MiscFlags = 0;
instanceDesc.StructureByteStride = 0;
DX::ThrowIfFailed(d3dDevice->CreateBuffer(&instanceDesc, NULL, &m_instanceBuffer));
However, when I try to map it:
D3D11_MAPPED_SUBRESOURCE inst;
DX::ThrowIfFailed(d3dContext->Map(m_instanceBuffer.Get(), 0, D3D11_MAP_WRITE, 0, &inst));
The map call fails with E_INVALIDARG
. Nothing is NULL
incorrectly, and this being one of my first D3D apps I'm currently stumped on what to do next to track it down. I'm thinking I must be creating the buffer incorrectly, but I can't see how. Any input would be appreciated.
© Game Development or respective owner