#region usings using System; using System.Collections.Generic; using OpenTK.Graphics.OpenGL4; #endregion namespace SM.OGL.Mesh { /// /// Contains information for meshes /// public abstract class GenericMesh : GLObject { /// /// Generates the AttribDataIndex /// protected GenericMesh() { AttribDataIndex = new Dictionary { {0, Vertex}, {1, UVs}, {2, Normals} }; } /// 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; } /// public override void Compile() { _id = GL.GenVertexArray(); GL.BindVertexArray(_id); if (AttribDataIndex == null) throw new Exception("[Critical] The model requires a attribute data index."); foreach (var kvp in AttribDataIndex) kvp.Value?.BindBuffer(kvp.Key); GL.BindVertexArray(0); } } }