(bind-func xtm_draw_mesh
(let ((vert:i32 0)
(instancesvbo:VBO* null)
(norm:i32 1)
(uvw:i32 2)
(color:i32 3))
(lambda (mesh:XTMMesh* shader:ShaderProgram* instances:i32 vbo:VBO*)
(gl_print_error "Error BEFORE drawing XTMMesh!")
;; (println mesh)
(let ((vao (tref mesh 10))
(texture (tref mesh 1))
(diffuse (tref mesh 2))
(ambient (tref mesh 3))
(specular (tref mesh 4))
(emissive (tref mesh 5))
(shininess (tref mesh 6))
(facemode (tref mesh 8)))
;; (set! shininess (dtof 100.0))
(if (not (null? ambient))
(glUniform4fv (glGetUniformLocation (id shader) "MaterialAmbient") 1 ambient))
(if (not (null? diffuse))
(glUniform4fv (glGetUniformLocation (id shader) "MaterialDiffuse") 1 diffuse))
(if (not (null? specular))
(glUniform4fv (glGetUniformLocation (id shader) "MaterialSpecular") 1 specular))
(if (not (null? specular))
(glUniform4fv (glGetUniformLocation (id shader) "MaterialEmissive") 1 emissive))
(glUniform1f (glGetUniformLocation (id shader) "MaterialShininess") shininess)
(glUniform1i (glGetUniformLocation (id shader) "instances") instances)
(glUniform1i (glGetUniformLocation (id shader) "emitVColour") XTM_EMIT_VCOLOUR)
(glUniform1i (glGetUniformLocation (id shader) "isPoints") 0)
(if (> (tref mesh 14) 0) ;; do we have any bones in our mesh!
(begin
(shader_update_bones shader mesh)))
;; (printf "texid %d\n" (id texture))
;; texture stuff
(if (> (id texture) 0)
(begin
(bind texture 1)
(glUniform1i (glGetUniformLocation (id shader) "isTextured") 1)
(glUniform1i (glGetUniformLocation (id shader) "diffuseTexture") 1))
(begin
(glUniform1i (glGetUniformLocation (id shader) "isTextured") 0)))
(gl_print_error "Error setting uniforms! in xtm_draw_mesh")
;;
(set! instancesvbo (get_vbo vao 4))
(if (and (> instances 0)
(<> (ptrtoi64 (cast instancesvbo i8*))
(ptrtoi64 (cast vbo i8*))))
(begin
(set_attribute vao vbo 4 16 36 0 #t)
(set_attribute vao vbo 8 4 36 16 #t)
(set_attribute vao vbo 9 16 36 20 #t)
))
(gl_print_error "Error setting instance attrib in xtm_draw_mesh")
;; (println "instances" instances)
(if (> instances 0)
(draw vao facemode 0 (convert (tref mesh 9)) instances)
(draw vao facemode 0 (convert (tref mesh 9))))
;; undo texture stuff
(unbind texture 1)
(gl_print_error "Error drawing XTMMesh!")
void))))