DirectX 11- Dynamic Buffers - Marching Cubes

I am creating a voxel based terrain with a marching cubes iosSurface. The terrain is to be dynamic, in that you can add/ remove parts as you see fit.

The problem I am having is that the marching cubes algorithm when changing densities (to deform the terrain) of voxels will sometimes add and remove triangles and vertices. I ran into a problem with the memcpy function when implementing the dynamic vertex buffer in that I can't give it the actual amount of triangles before hand for the memcpy size .i.e. vertexStruct * vertexList.size().

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
	D3D11_MAPPED_SUBRESOURCE mapResource;
	ZeroMemory(&mapResource, sizeof(D3D11_MAPPED_SUBRESOURCE));

	PopulateBlock();
	AssignDensity(noiseMap, 0, 0, 0);
	CreateTriangleList();

	context->Map(m_vBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapResource);

	memcpy(mapResource.pData, &m_triangleList[0], sizeof(VertexPos) * m_triangleList.size());
// This sizeof seems to be the problem as i dont think it can handle the changingvector size.
// Does anyone know if you can have verties added and removed?

	mapResource.pData = &m_triangleList[0];

	context->Unmap(m_vBuffer, 0);


Can anyone help with potential solutions to this problem? I am new to DirectX and have never done anything with dynamic buffers before.

EDIT: Basically can you add and remove triangles using a dynamic vertex/index buffer?
Last edited on
Topic archived. No new replies allowed.