Dynamic Sized Vertex Buffer

Aug 22, 2012 at 3:01 PM

I am having trouble implementing a dynamic vertex buffer as it doesn't appear to be resizing when I alter the size of the referenced List<T>.

Here is my code.

//I create it here
this._verticesBuffer = new Vertices<T>(Vertices);
			_verticesBuffer.ResourceUsage = ResourceUsage.Dynamic;
//Vertices is a List<VertexPositionNormalTexture>

//But the following code doesn't work

Vertices.Add(new VertexPositionNormalTexture(new Vector3(0, 0, 1), Vector3.UnitZ, new Vector2()));
			Vertices.Add(new VertexPositionNormalTexture(new Vector3(0, 2, 1), Vector3.UnitZ, new Vector2()));
			Vertices.Add(new VertexPositionNormalTexture(new Vector3(2, 0, 1), Vector3.UnitZ, new Vector2()));
			Vertices.Add(new VertexPositionNormalTexture(new Vector3(2, 2, 1), Vector3.UnitZ, new Vector2()));

_verticesBuffer.SetDirty();

Are Vertex Buffers in Xen like those in D3D and the only way to resize them is to create a new one and copy the data across?

Looking over the code I cannot see why this would be as it appears to maintain a weak reference to the data source and use the CopyTo() method when SetDirty() is called.

Any help much appreciated.

Aug 22, 2012 at 4:07 PM
Edited Aug 22, 2012 at 4:08 PM

I have found at least a temporary solution to the problem.

I changed the code within Bufffer.cs for the Count variable to this

public int Count
		{
			get
			{
				if (count == -1)
					throw new ArgumentException("Count is not available until the data has been processed");
				return GetCount();
			}
		}

and it now works. I don't think this has broken anything, but it is possible. Could someone confirm whether or not this is the case and perhaps provide a solution that is less of a hack.