using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; namespace CalamityMod.Graphics.Primitives { /// /// A custom vertex type with a position using Vector2 instead of Vector4, as Terraria is only a 2D game. /// /// This represents a vertex that will be rendered by the GPU. public readonly struct VertexPosition2DColorTexture : IVertexType { /// /// The position of the vertex. /// public readonly Vector2 Position; /// /// The color of the vertex. /// public readonly Color Color; /// /// The texture-coordinate of the vertex. /// /// /// The Z component isn't actually related to 3D, it holds the width of the vertex at the given point, since arbitrary data cannot be saved on a per-vertex basis and needs to be contained within some pre-defined format. /// public readonly Vector3 TextureCoordinates; /// /// The vertex declaration. This declares the layout and size of the data in the vertex shader. /// public VertexDeclaration VertexDeclaration => VertexDeclaration2D; public static readonly VertexDeclaration VertexDeclaration2D = new(new VertexElement[] { new(0, VertexElementFormat.Vector2, VertexElementUsage.Position, 0), new(8, VertexElementFormat.Color, VertexElementUsage.Color, 0), new(12, VertexElementFormat.Vector3, VertexElementUsage.TextureCoordinate, 0) }); public VertexPosition2DColorTexture(Vector2 position, Color color, Vector2 textureCoordinates, float widthCorrectionFactor) { Position = position; Color = color; TextureCoordinates = new(textureCoordinates, widthCorrectionFactor); } } }