(bind-func shader_update_bones
(let ((bonesdat:float* (alloc (* 16 4 20))) ;; 16 (4x4 array) * 20 * 4 (bytes per float)
(i:i32 0))
;; default to id matrix
(dotimes (i 20) (fill_identity_matrix (pref-ptr bonesdat (* 16 i))))
(lambda (shader:ShaderProgram* mesh:XTMMesh*)
(let ((num_bones (tref mesh 12))
(bones (tref mesh 13))
(bone:XTMBone* null)
(mymat:float* (alloc 16))
(transmat:float* null))
(fill_identity_matrix mymat)
(translate_matrix mymat 2.0 2.0 2.0)
;; (dotimes (i 20) (fill_identity_matrix (pref-ptr bonesdat (* 16 i))))
(dotimes (i num_bones)
(set! bone (pref-ptr bones i))
(set! transmat (tref bone 2))
(memcpy (cast mymat i8*) (cast transmat i8*) (* 16 4))
(if (= i -1)
(begin
(rotate_matrix mymat 50.0 0.0 1.0 0.0)
(memcpy (cast (pref-ptr bonesdat (* 16 i)) i8*) (cast mymat i8*) (* 16 4)))
(memcpy (cast (pref-ptr bonesdat (* 16 i)) i8*) (cast transmat i8*) (* 16 4))))
;; update 20 bones
(glUniformMatrix4fv (glGetUniformLocation (id shader) "Bone") 20 GL_FALSE bonesdat)
(gl_print_error "Error updating bones")
void))))