using System; using System.Collections.Generic; using OpenTK.Graphics.OpenGL4; using Buffer = OpenTK.Graphics.OpenGL4.Buffer; namespace SM.OGL.Mesh { /// /// Contains information for meshes /// public abstract class GenericMesh : GLObject { /// protected override bool AutoCompile { get; } = true; /// public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.VertexArray; /// /// The primitive type, that determinants how the mesh is drawn. /// Default: Triangles /// public virtual PrimitiveType PrimitiveType { get; } = PrimitiveType.Triangles; /// /// Contains the vertices for the mesh. /// public virtual VBO Vertex { get; } /// /// Contains the texture coords for the mesh. /// public virtual VBO UVs { get; } /// /// Contains the normals for the mesh. /// public virtual VBO Normals { get; } /// /// Represents the bounding box. /// public virtual BoundingBox BoundingBox { get; } = new BoundingBox(); /// /// Connects the different buffer objects with ids. /// public Dictionary AttribDataIndex { get; } /// /// Stores indices for a more performance friendly method to draw objects. /// public virtual int[] Indices { get; set; } /// /// Generates the AttribDataIndex /// protected GenericMesh() { AttribDataIndex = new Dictionary() { {0, Vertex}, {1, UVs}, {2, Normals}, }; } /// protected override void Compile() { _id = GL.GenVertexArray(); GL.BindVertexArray(_id); if (AttribDataIndex == null) throw new Exception("[Critical] The model requires a attribute data index."); foreach (KeyValuePair kvp in AttribDataIndex) kvp.Value?.BindBuffer(kvp.Key); GL.BindVertexArray(0); } } }