I want to include the drawing of other vectors of vertices in the following code, in a number of places it seems easy enough to simply add or multiply size()s of the two vectors, for instance in the first check. But then it gets a bit fuzzy simply because of a lack of understanding.
Should I add them together to create a bigger buffer description and copy everything together? Or should I do it all separately?
Basically how would I extend this code to include more vectors of vertices?
if (temporary2DVerts.size() > 0)
{
// create the vertex buffer and store the pointer into pBuffer, which is created globally
D3D10_BUFFER_DESC bd;
bd.Usage = D3D10_USAGE_DYNAMIC;
bd.ByteWidth = sizeof(VERTEX) * temporary2DVerts.size();// this breaks the create buffer line : temp2DVerts.size();
bd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
bd.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
bd.MiscFlags = 0;
device->CreateBuffer(&bd, NULL, &pBuffer);
void* pVoid; // the void pointer
pBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, &pVoid); // map the vertex buffer
memcpy(pVoid, &temporary2DVerts[0], sizeof(temporary2DVerts[0]) * temporary2DVerts.size());
pBuffer->Unmap();
// select which input layout we are using
device->IASetInputLayout(screenVertexLayout);
// select which primtive type we are using
device->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_LINELIST);
// select which vertex buffer to display
UINT stride = sizeof(VERTEX);
UINT offset = 0;
device->IASetVertexBuffers(0, 1, &pBuffer, &stride, &offset);
// apply the appropriate pass
screenPass->Apply(0);
// draw the vertex buffer to the back buffer
device->Draw(temporary2DVerts.size(), 0);
temporary2DVerts.clear();
}
EDIT - just to be clearer - there are 4 vectors of vertices. two that don't change and two that constantly change. permanent 2D and permanent 3D and a temporary version of both. This is so the permanent ones can just be loaded in and are always drawn, and the temporary ones only get drawn for a frame. This way I can create moving lines for debugging, like line of sight cones etc.
EDIT - the naive approach would be to duplicate this code 4 times for each vector, but surely there is a better way? I don't think this is a hard thing to do, but trying to do it has exposed a basic gap in my knowledge about what some of these lines of code do. should I just populate one big list from all the vectors and push that through?
some need to be drawn with different passes, and some don't need to be changed each frame. for example, the permanent ones can just stay on the gpu. right?
