// Vertex Attrib List //
// Storing all the vertex attributes in a big editable list //
static LinkedList<Integer> vertexAttribArray = new LinkedList<Integer>();
static int attribNum; // the non 0-based (Makes for looping correct) number of attributes
static int stride; // the distance between each elements of the attributes listin bytes
public static void addVertexAttrib(int VectorType) {
// Basically ; 4 , 3 , 2 , 1
vertexAttribArray.add(VectorType);
//Adds the size of the attrib to the stride
stride += VectorType * 4;
attribNum += 1;
}
public static void enableVertexAttribs() {
int offset = 0; // the offset from the beginning in bytes
for (int i = 0; i < attribNum; i++) {
//Size of the current attribute (is it a Vector2f OR 3f OR 4f ?)
int size = vertexAttribArray.get(i);
/* For testing
System.out.println(new StringBuilder().append("index : ").append(i).append(" | size : ").append(size).append(" | stride : ").append(stride - size * 4).append(" | offset : ").append(offset));*/
glEnableVertexAttribArray(i); //the distance - the current vertex attribute size ;
glVertexAttribPointer(i, size, GL_FLOAT, false, stride - size * 4, offset);
offset += size * 4;
}
}
public static void disableVertexAttribs() {
for (int i = 0; i < attribNum; i++) {
glDisableVertexAttribArray(i);
}
}