private int SetupVertexDeclaration(VertexBufferContent result) { var offset = 0; // We always have a position channel result.VertexDeclaration.VertexElements.Add(new VertexElement(offset, VertexElementFormat.Vector3, VertexElementUsage.Position, 0)); offset += VertexElementFormat.Vector3.GetTypeSize(); // Optional channels foreach (var channel in Channels) { VertexElementFormat format; VertexElementUsage usage; // Try to determine the vertex format // TODO: Add support for additional formats as they become testable if (channel.ElementType == typeof(Vector3)) { format = VertexElementFormat.Vector3; } else if (channel.ElementType == typeof(Vector2)) { format = VertexElementFormat.Vector2; } else { throw new InvalidContentException("Unrecognized vertex content type."); } // Try to determine the vertex usage if (!VertexChannelNames.TryDecodeUsage(channel.Name, out usage)) { throw new InvalidContentException("Unknown vertex element usage."); } // Try getting the usage index var usageIndex = VertexChannelNames.DecodeUsageIndex(channel.Name); result.VertexDeclaration.VertexElements.Add(new VertexElement(offset, format, usage, usageIndex)); offset += format.GetTypeSize(); result.VertexDeclaration.VertexStride = offset; } return(offset); }
private int SetupVertexDeclaration(VertexBufferContent result) { var offset = 0; // We always have a position channel result.VertexDeclaration.VertexElements.Add(new VertexElement(offset, VertexElementFormat.Vector3, VertexElementUsage.Position, 0)); offset += VertexElementFormat.Vector3.GetSize(); // Optional channels foreach (var channel in Channels) { VertexElementFormat format; VertexElementUsage usage; // Try to determine the vertex format if (channel.ElementType == typeof(Single)) { format = VertexElementFormat.Single; } else if (channel.ElementType == typeof(Vector2)) { format = VertexElementFormat.Vector2; } else if (channel.ElementType == typeof(Vector3)) { format = VertexElementFormat.Vector3; } else if (channel.ElementType == typeof(Vector4)) { format = VertexElementFormat.Vector4; } else if (channel.ElementType == typeof(Color)) { format = VertexElementFormat.Color; } else if (channel.ElementType == typeof(Byte4)) { format = VertexElementFormat.Byte4; } else if (channel.ElementType == typeof(Short2)) { format = VertexElementFormat.Short2; } else if (channel.ElementType == typeof(Short4)) { format = VertexElementFormat.Short4; } else if (channel.ElementType == typeof(NormalizedShort2)) { format = VertexElementFormat.NormalizedShort2; } else if (channel.ElementType == typeof(NormalizedShort4)) { format = VertexElementFormat.NormalizedShort4; } else if (channel.ElementType == typeof(HalfVector2)) { format = VertexElementFormat.HalfVector2; } else if (channel.ElementType == typeof(HalfVector4)) { format = VertexElementFormat.HalfVector4; } else { throw new InvalidContentException(string.Format("Unrecognized vertex content type: '{0}'", channel.ElementType)); } // Try to determine the vertex usage if (!VertexChannelNames.TryDecodeUsage(channel.Name, out usage)) { throw new InvalidContentException(string.Format("Unknown vertex element usage for channel '{0}'", channel.Name)); } // Try getting the usage index var usageIndex = VertexChannelNames.DecodeUsageIndex(channel.Name); result.VertexDeclaration.VertexElements.Add(new VertexElement(offset, format, usage, usageIndex)); offset += format.GetSize(); result.VertexDeclaration.VertexStride = offset; } return(offset); }