public unsafe void Bind(Shader shader) { GL.BindBuffer(BufferTarget.ArrayBuffer, bufferHandle); if (!uploaded) { uploaded = true; if (safe) { GL.BufferData <TVertex>(BufferTarget.ArrayBuffer, (IntPtr)(vertexFormat.size * vertices.Length), vertices, BufferUsageHint.StaticDraw); } else { GL.BufferData(BufferTarget.ArrayBuffer, Size, (IntPtr)data, BufferUsageHint.StaticDraw); } } if (!createdArrays) { // create new vertex array object GL.GenVertexArrays(1, out vertexArrayHandle); GL.BindVertexArray(vertexArrayHandle); // set all attributes List <VertexAttribute> attrs = new List <VertexAttribute>(); foreach (var attribute in vertexFormat.Attributes) { var attrib = new VertexAttribute(attribute.Name, VertexFormat.NumberOfElementsInType(attribute.Type), VertexFormat.BaseType(attribute.Type), vertexFormat.size, attribute.Offset, (attribute.Type == Attribute.AType.UBYTE4) ?true:false); // Normalize if not float. attrib.Set(shader); } createdArrays = true; } else { GL.BindVertexArray(vertexArrayHandle); } }
public Mesh(TVertex[] vertices) { this.vertexFormat = vertices[0].GetVertexFormat(); this.vertices = vertices; }