Interface VertexBufferHelper.IWriter<TDest>
public interface VertexBufferHelper.IWriter<TDest>
Type Parameters
TDest
Examples
Writing directly to mesh color:
Model.Meshes[0].Draw.VertexBuffers[0].AsReadable(Services, out VertexBufferHelper helper, out int count);
// Write to colors if that semantic already exist in the buffer, otherwise returns false
helper.Write<ColorSemantic, Vector4, MultColor>(new MultColor(){ Color = Color.Gray });
// Upload changes to the GPU
Model.Meshes[0].Draw.VertexBuffers[0].Buffer.Recreate(helper.DataOuter);
private struct MultColor : VertexBufferHelper.IWriter<Vector4>
{
public Color Color;
public unsafe void Write<TConverter, TSource>(byte* sourcePointer, int elementCount, int stride)
where TConverter : IConverter<TSource, Vector4>, IConverter<Vector4, TSource>
where TSource : unmanaged
{
for (byte* end = sourcePointer + elementCount * stride; sourcePointer < end; sourcePointer += stride)
{
TConverter.Convert(*(TSource*)sourcePointer, out var val);
val *= (Vector4)Color;
TConverter.Convert(val, out *(TSource*)sourcePointer);
}
}
}
Methods
Write<TConverter, TSource>(byte*, int, int)
void Write<TConverter, TSource>(byte* sourcePointer, int elementCount, int stride) where TConverter : IConverter<TSource, TDest>, IConverter<TDest, TSource> where TSource : unmanaged
Parameters
sourcePointerbyte*Points to the first element in the vertex buffer, read it as a TSource* to retrieve its value
elementCountintThe amount of vertices. This is not equivalent to the size of the vertex buffer, or the size in bytes taken by individual vertices
strideintThe size in bytes taken by individual vertices, add it to
sourcePointerto point to the next element
Type Parameters
TConverterA helper to convert between
TSourceandTDestproperlyTSourceThe source type this vertex buffer was built with, for example Vector2 or Byte4, use
TConverterto convert it into aTDest.
Examples
Writing directly to mesh color:
Model.Meshes[0].Draw.VertexBuffers[0].AsReadable(Services, out VertexBufferHelper helper, out int count);
// Write to colors if that semantic already exist in the buffer, otherwise returns false
helper.Write<ColorSemantic, Vector4, MultColor>(new MultColor(){ Color = Color.Gray });
// Upload changes to the GPU
Model.Meshes[0].Draw.VertexBuffers[0].Buffer.Recreate(helper.DataOuter);
private struct MultColor : VertexBufferHelper.IWriter<Vector4>
{
public Color Color;
public unsafe void Write<TConverter, TSource>(byte* sourcePointer, int elementCount, int stride)
where TConverter : IConverter<TSource, Vector4>, IConverter<Vector4, TSource>
where TSource : unmanaged
{
for (byte* end = sourcePointer + elementCount * stride; sourcePointer < end; sourcePointer += stride)
{
TConverter.Convert(*(TSource*)sourcePointer, out var val);
val *= (Vector4)Color;
TConverter.Convert(val, out *(TSource*)sourcePointer);
}
}
}