private byte[] ToRawData(List <VertexBufferHelperAttrib> helperAttribs) { int length = 0; for (int i = 0; i < helperAttribs.Count; i++) { length += helperAttribs[i].Data.Length * (int)helperAttribs[i].Stride; } // Create a write for the raw bytes of the correct endianness. byte[] raw = new byte[length]; using (BinaryDataWriter writer = new BinaryDataWriter(new MemoryStream(raw, true))) { writer.ByteOrder = ByteOrder; for (int v = 0; v < helperAttribs[0].Data.Length; v++) { for (int i = 0; i < helperAttribs.Count; i++) { long pos = writer.Position; // Get a conversion callback transforming the Vector4F instances into raw data. Action <BinaryDataWriter, Vector4F> callback = writer.GetGX2AttribCallback(helperAttribs[i].Format); callback.Invoke(writer, helperAttribs[i].Data[v]); writer.Seek(pos + helperAttribs[i].Stride, SeekOrigin.Begin); } } } return(raw); }
/// <summary> /// Writes <see cref="Vector4U"/> instances into the current stream with the given /// <paramref name="attribFormat"/>. /// </summary> /// <param name="self">The extended <see cref="BinaryDataWriter"/>.</param> /// <param name="values">The <see cref="Vector4U"/> instances.</param> /// <param name="attribFormat">The <see cref="GX2AttribFormat"/> of the data.</param> public static void Write(this BinaryDataWriter self, IEnumerable <Vector4F> values, GX2AttribFormat attribFormat) { Action <BinaryDataWriter, Vector4F> callback = self.GetGX2AttribCallback(attribFormat); foreach (Vector4F value in values) { callback.Invoke(self, value); } }
private byte[] ToRawData(VertexBufferHelperAttrib helperAttrib) { // Create a write for the raw bytes of the correct endianness. byte[] raw = new byte[helperAttrib.Data.Length * helperAttrib.FormatSize]; using (BinaryDataWriter writer = new BinaryDataWriter(new MemoryStream(raw, true))) { writer.ByteOrder = ByteOrder; // Get a conversion callback transforming the Vector4F instances into raw data. Action <BinaryDataWriter, Vector4F> callback = writer.GetGX2AttribCallback(helperAttrib.Format); // Write the elements. foreach (Vector4F element in helperAttrib.Data) { callback.Invoke(writer, element); } } return(raw); }
/// <summary> /// Writes a <see cref="Vector4U"/> instance into the current stream with the given /// <paramref name="attribFormat"/>. /// </summary> /// <param name="self">The extended <see cref="BinaryDataWriter"/>.</param> /// <param name="value">The <see cref="Vector4F"/> instance.</param> /// <param name="attribFormat">The <see cref="GX2AttribFormat"/> of the data.</param> public static void Write(this BinaryDataWriter self, Vector4F value, GX2AttribFormat attribFormat) { self.GetGX2AttribCallback(attribFormat).Invoke(self, value); }