(bind-func shader_update_lights
(let ((i:i32 0)
(ca:float* (alloc 5)) ;; contant attenuation
(la:float* (alloc 5)) ;; linear attenuation
(qa:float* (alloc 5)) ;; quadratic attenuation
(sa:float* (alloc 5)) ;; spot angle
(dir:float* (alloc (* 5 4))) ;; spot dir
(tmp:float* (alloc (* 5 4))))
(dotimes (i 5)
(pset! ca i 1.0) (pset! la i 0.0) (pset! qa i 0.0))
(lambda (shader:ShaderProgram* numlights:i32 position target angle:float* power ambient diffuse specular)
(if (> numlights 5) (set! numlights 5))
(dotimes (i numlights) (pset! sa i (- 1.0 (/ (pref angle i) 180.0))))
(glUniform1i (glGetUniformLocation (id shader) "numLights") numlights)
(glUniform1fv (glGetUniformLocation (id shader) "ConstantAttenuation") numlights ca)
(glUniform1fv (glGetUniformLocation (id shader) "LinearAttenuation") numlights la)
(glUniform1fv (glGetUniformLocation (id shader) "QuadraticAttenuation") numlights qa)
(glUniform1fv (glGetUniformLocation (id shader) "SpotExponent") numlights power)
(glUniform1fv (glGetUniformLocation (id shader) "SpotAngle") numlights sa)
(glUniform4fv (glGetUniformLocation (id shader) "LightPos") numlights position)
(glUniform4fv (glGetUniformLocation (id shader) "LightAmbient") numlights ambient)
(glUniform4fv (glGetUniformLocation (id shader) "LightSpecular") numlights specular)
(glUniform4fv (glGetUniformLocation (id shader) "LightDiffuse") numlights diffuse)
(dotimes (i numlights)
(vvsub (pref-ptr target (* i 4))
(pref-ptr position (* i 4))
3
(pref-ptr tmp (* i 4)))
(vnormalise (pref-ptr tmp (* i 4))
3
(pref-ptr dir (* i 4)))
(pset! (pref-ptr dir (* i 4)) 3 0.0))
(glUniform4fv (glGetUniformLocation (id shader) "SpotDir") numlights dir)
void)))