/// Writes additional data into the vertex buffer. Writing begins at the specified byte offset, and each value is spaced according to the specified stride value (in bytes).
/// </summary>
/// <remarks>
/// This method automatically grows the vertex buffer if an attempt is made to write past the buffer end. Write throws NotSupportedException
/// if the specified data type cannot be packed into a vertex buffer. For example, if data is not a valid value type.
///
/// Use this method to interleave vertex data channels into a single buffer. This can be done by passing the total vertex size as the stride and suitable smaller offsets for each channel.
/// You can also concatenate entire vertex buffers by passing the length of the vertex as the offset, 1 as the stride, and the vertex data as the data parameter.
/// </remarks>
/// <typeparam name="T">Type being written.</typeparam>
/// <param name="offset">Offset to begin writing at.</param>
/// <param name="stride">Stride of the data being written (in bytes).</param>
/// <param name="data">Enumerated collection of data.</param>
/// Writes additional data into the vertex buffer. Writing begins at the specified byte offset, and each value is spaced according to the specified stride value (in bytes).
/// </summary>
/// <remarks>
/// This method automatically grows the vertex buffer if an attempt is made to write past the buffer end. Write throws NotSupportedException
/// if the specified data type cannot be packed into a vertex buffer. For example, if data is not a valid value type.
///
/// Use this method to interleave vertex data channels into a single buffer. This can be done by passing the total vertex size as the stride and suitable smaller offsets for each channel.
/// You can also concatenate entire vertex buffers by passing the length of the vertex as the offset, 1 as the stride, and the vertex data as the data parameter.
//Make sure we don't intercopy the data if we write it. Having a bigger stride is no problem, in that case we write what we can and then skip all unused bytes to get to the next stride.
if(stride<elementSize)
thrownewArgumentOutOfRangeException("stride");
if(data==null)
thrownewArgumentNullException("data");
List<object>dataList=newList<object>();
foreach(varobjindata)
{
//obj should not be able to be null, because we tested with SizeOf if it is a ValueType.
if(!dataType.IsAssignableFrom(obj.GetType()))
thrownewArgumentException(string.Format("data contains elements that are not compatible with \"{0}\"",dataType.Name));
dataList.Add(obj);
}
//regrow the array if the data would write over the boundaries.
//Copy the data over, the content of dataList is guaranteed to be a value type by the SizeOf check earlier.
for(inti=0;i<dataList.Count;i++)
{
//We have to copy every element separately to support the first documented use case where someone passed a stride that is much bigger than the real data to write only data into the vertex buffer for
//a single vertex channel, even though the data in the vertex buffer must be arranged per vertex and not per vertex channel.