Пример #1
0
        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);
        }