;; where size is number of components for vertex
(bind-func set_attribute
(lambda (vao:VAO* vbo:VBO* type index size stride:GLsizei offset instance_attr:i1)
;; (if (not (aref (attribs vao) index))
(begin
(glBindVertexArray (id vao))
(gl_print_error "Error binding VAO")
(glBindBuffer GL_ARRAY_BUFFER (id vbo))
; (println 'vbo vbo)
(gl_print_error "Error binding VBO")
(let ((component_size 4)) ;; four for GL_FLOAT and GL_INT
(if (= size 16) ;; i.e. if a mat4
(begin ;; this is a pain but matrix is simply 4 * vec4
(glEnableVertexAttribArray (+ index 0)) ;; i dn't know if i need these enables
(glVertexAttribPointer (+ index 0) 4 type GL_FALSE (* stride component_size)
(pref-ptr (cast null GLvoid*) (* component_size (+ offset 0))))
(glEnableVertexAttribArray (+ index 1))
(glVertexAttribPointer (+ index 1) 4 type GL_FALSE (* stride component_size)
(pref-ptr (cast null GLvoid*) (* component_size (+ offset 4))))
(glEnableVertexAttribArray (+ index 2))
(glVertexAttribPointer (+ index 2) 4 type GL_FALSE (* stride component_size)
(pref-ptr (cast null GLvoid*) (* component_size (+ offset 8))))
(glEnableVertexAttribArray (+ index 3))
(glVertexAttribPointer (+ index 3) 4 type GL_FALSE (* stride component_size)
(pref-ptr (cast null GLvoid*) (* component_size (+ offset 12)))))
(begin
(glEnableVertexAttribArray index)
(glVertexAttribPointer index
size
type ;;(type vbo)
GL_FALSE
(* component_size stride)
(pref-ptr (cast null GLvoid*) (* component_size offset))))))
(gl_print_error "Error binding VAO attribute")
(if (= size 16)
(begin
(aset! (attribs vao) (+ index 0) #t)
(aset! (attribs vao) (+ index 1) #t)
(aset! (attribs vao) (+ index 2) #t)
(aset! (attribs vao) (+ index 3) #t)))
(if (<> size 16)
(aset! (attribs vao) index #t))
(aset! (buffers vao) index vbo)
(glBindBuffer GL_ARRAY_BUFFER 0)
(if (and instance_attr (<> size 16))
(begin (glVertexAttribDivisor index 1)
(gl_print_error "Error setting VAO attribute divisor")))
(if (and instance_attr (= size 16))
(begin (glVertexAttribDivisor (+ index 0) 1)
(glVertexAttribDivisor (+ index 1) 1)
(glVertexAttribDivisor (+ index 2) 1)
(glVertexAttribDivisor (+ index 3) 1)
(gl_print_error "Error setting VAO attribute divisor")))
(glBindVertexArray 0))
void))