Hey all, I have a few questions about mapping a dynamic vertex buffer in DirectX11
I currently have this struct that represents a Quad. This will hold the vertices of the quad, the texture, etc. I also have a Vector that will hold all of the Quads that should be drawn
struct Quad
{
Vertex vertices[4];
};
std::vector<Quad> drawData;
How can I map all of the data in the drawData Vector to my Vertex buffer?
I have this but it will only draw one Quad (It keeps overwriting the data placed)
D3D11_MAPPED_SUBRESOURCE mapResource;
ZeroMemory(&mapResource, sizeof(mapResource));
batchContext->Map(vertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapResource);
for(std::vector<Quad>::iterator i = drawData.begin(); i != drawData.end(); i++)
{
memcpy(mapResource.pData, (*i).vertices, sizeof((*i).vertices));
}
batchContext->Unmap(vertexBuffer, 0);
How can I do something like
D3D11_MAPPED_SUBRESOURCE mapResource;
ZeroMemory(&mapResource, sizeof(mapResource));
int quadOffset = 0;
batchContext->Map(vertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapResource);
for(std::vector<Quad>::iterator i = drawData.begin(); i != drawData.end(); i++)
{
//Add the Quad onto mapResource/vertex buffer. Place it at the offset mark
memcpy(mapResource.pData + quadOffset, (*i).vertices, sizeof((*i).vertices));
//Add on 4 because 4 vertices to quad
quadOffset += 4;
}
batchContext->Unmap(vertexBuffer, 0);