#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() { Attributes = new MeshAttributeList() { {0, "vertex", Vertex}, {1, "uv", UVs}, {2, "normal", 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; protected set; } = PrimitiveType.Triangles; /// /// Contains the vertices for the mesh. /// public virtual VBO Vertex { get; protected set; } /// /// Contains the texture coords for the mesh. /// public virtual VBO UVs { get; protected set; } /// /// Contains the normals for the mesh. /// public virtual VBO Normals { get; protected set; } /// /// Represents the bounding box. /// public virtual BoundingBox BoundingBox { get; } = new BoundingBox(); /// /// Connects the different buffer objects with ids. /// public MeshAttributeList Attributes { 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 (Attributes == null) throw new Exception("[Critical] The model requires attributes."); foreach (var kvp in Attributes) kvp.ConnectedVBO?.BindBuffer(kvp.Index); GL.BindVertexArray(0); } } }