;; when working with OpenGL
;; extempore's mmul is pre mutipled (not post as in GLSL)
;; so the same matrix mul is post in GLSL and pre in XTM (i.e. here!)
(bind-func shader_update_matrices
(lambda (shader:ShaderProgram* m v p)
(let ((mv (salloc 48))
(mvp (pref-ptr mv 16))
(mn (pref-ptr mv 32)))
;;(mmul m 4 4 v 4 4 mv) ;; final mv set
(mmmul m v mv) ;; final mv set
(mtrans mv 4 4 mn) ;; using mn as a temporary here!!
(minverse mn 4 mvp) ;; using mvp as a temporary
(mat4_to_mat3 mvp mn) ;; final mn set
;;(mmul mv 4 4 p 4 4 mvp) ;; final mvp set
(mmmul mv p mvp)
(glUniformMatrix4fv (glGetUniformLocation (id shader) "ModelMatrix") 1 GL_FALSE m)
(glUniformMatrix4fv (glGetUniformLocation (id shader) "ViewMatrix") 1 GL_FALSE v)
(glUniformMatrix4fv (glGetUniformLocation (id shader) "ProjectionMatrix") 1 GL_FALSE p)
(glUniformMatrix3fv (glGetUniformLocation (id shader) "NormalMatrix") 1 GL_FALSE mn)
(glUniformMatrix4fv (glGetUniformLocation (id shader) "ModelViewMatrix") 1 GL_FALSE mv)
(glUniformMatrix4fv (glGetUniformLocation (id shader) "ModelViewProjectionMatrix") 1 GL_FALSE mvp)
void)))