I am having an issue modifying a vertex buffer once I have sent it to the GPU. I know I need to Map() and Unmap() the vertex buffer but I do not understand what is required to set the vertex buffer description in order to allow this. My current setup works but as you will read below it does not function perfectly.
My current code for setting up the vertex buffer is below. When I run my program with this code I receive some debug input from DX10:
D3D10: ERROR: ID3D10Device::IASetVertexBuffers: A Buffer trying to be bound to slot 0 did not have the appropriate bind flag set at creation time to allow the Buffer to be bound as a VertexBuffer. [ STATE_SETTING ERROR #238: IASETVERTEXBUFFERS_INVALIDBUFFER ]
Setup code:
D3D10_BUFFER_DESC bd;
bd.Usage =/* D3D10_USAGE_DEFAULT;*/D3D10_USAGE_DYNAMIC;
bd.ByteWidth = sizeof(VertexPositionColor) * bb_numVertices;
bd.BindFlags = D3D10_BIND_CONSTANT_BUFFER;//D3D10_BIND_VERTEX_BUFFER;
bd.CPUAccessFlags = /*0;*/D3D10_CPU_ACCESS_WRITE;
bd.MiscFlags = 0;
D3D10_SUBRESOURCE_DATA InitData;
InitData.pSysMem = vertices;
hr = Device->CreateBuffer(&bd, &InitData, &bb_VertexBuffer);
Modification code:
VertexPositionColor *pData = NULL;
if(SUCCEEDED(bb_VertexBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, reinterpret_cast<void**>(&pData))))
{
memcpy(pData, vertices, sizeof(VertexPositionColor) * bb_numVertices);
bb_VertexBuffer->Unmap();
}
I originally through the bind flag should be the commented out code but when I run that hr gives me E_INVALIDARG.
Thank you for all your help.