(bind-func xtm_draw_model
(lambda (node:XTMModel* shader:ShaderProgram* model:float* view:float* projection:float* instances:i32 vbo:VBO*)
(gl_print_error "Error before drawing XTMModel")
(let ((i:i32 0)
(lights (xtm_get_lights))
(children (tref node 4))
(meshes (tref node 6))
(transmat:float* (tref node 1))
(m2:float* (salloc 16))
(m:float* (salloc 16)))
;; (println "instances:" instances)
(if (null? transmat)
(begin (memcpy (cast m i8*) (cast model i8*) (* 4 16)) 1)
(begin
(mtrans transmat 4 4 m2)
(mmmul m2 model m)
1))
(xtm_update_matrices shader m view projection)
;; first draw meshes
(dotimes (i (tref node 5))
(xtm_draw_mesh (pref-ptr meshes i) shader instances vbo))
(gl_print_error "Error drawing XTMMesh!")
;; then draw other children recursively
(dotimes (i (tref node 3))
(xtm_draw_model (pref-ptr children i) shader model view projection instances vbo))
(gl_print_error "Error drawing XTMModel!")
void)))