static VertexLayout ReadVertexLayout(MemoryReader reader) { var layout = new VertexLayout(); layout.Begin(); var attributeCount = reader.Read <byte>(); var stride = reader.Read <ushort>(); for (int i = 0; i < attributeCount; i++) { var e = reader.Read <VertexElement>(); var usage = attributeUsageMap[e.Attrib]; layout.Add(usage, e.Count, attributeTypeMap[e.AttribType], e.Normalized != 0, e.AsInt != 0); if (layout.GetOffset(usage) != e.Offset) { throw new InvalidOperationException("Invalid mesh data; vertex attribute offset mismatch."); } } layout.End(); if (layout.Stride != stride) { throw new InvalidOperationException("Invalid mesh data; vertex layout stride mismatch."); } return(layout); }
public static VertexLayout ReadVertexLayout(this UnmanagedMemoryAccessor reader, ref int index) { var layout = new VertexLayout(); layout.Begin(); var attributeCount = reader.ReadByte(ref index); var stride = reader.ReadUInt16(ref index); for (int i = 0; i < attributeCount; i++) { var offset = reader.ReadUInt16(ref index); var attrib = reader.ReadUInt16(ref index); var count = reader.ReadByte(ref index); var attribType = reader.ReadUInt16(ref index); var normalized = reader.ReadBool(ref index); var asInt = reader.ReadBool(ref index); var usage = attributeUsageMap[attrib]; layout.Add(usage, count, attributeTypeMap[attribType], normalized, asInt); if (layout.GetOffset(usage) != offset) { throw new InvalidOperationException("Invalid mesh data; vertex attribute offset mismatch."); } } layout.End(); if (layout.Stride != stride) { throw new InvalidOperationException("Invalid mesh data; vertex layout stride mismatch."); } return(layout); }