Created
April 30, 2016 22:32
-
-
Save postspectacular/685c54f27558b527a9c07f7b9d311ab3 to your computer and use it in GitHub Desktop.
Updating C particle system & rendering w/ WebGL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn attrib-buffer-view | |
[ptr stride num] | |
(js/Float32Array. (.-buffer (aget js/Particles "HEAPU8")) ptr (* stride num))) | |
(defn update-attrib-buffer | |
[gl attrib ptr stride num] | |
(.bindBuffer gl glc/array-buffer | |
(get-in (:scene @app) [:particles :attribs attrib :buffer])) | |
(.bufferData gl glc/array-buffer | |
(attrib-buffer-view ptr stride num) | |
glc/dynamic-draw)) | |
(defn update-and-draw-psys | |
[] | |
(let [{:keys [gl psys psys-update psys-count particle-ptr scene mpos]} @app] | |
(psys-update psys) | |
(update-attrib-buffer gl :position particle-ptr 9 10000) | |
(update-attrib-buffer gl :color (+ particle-ptr 24) 9 10000) | |
(doto gl | |
(gl/clear-color-and-depth-buffer (col/rgba 0 0 0.1) 1) | |
(gl/draw-with-shader | |
(-> (:particles scene) | |
(assoc :num-vertices (psys-count psys)) | |
(assoc-in [:uniforms :model] | |
(-> M44 | |
(g/rotate-x (* (mpos 1) 0.001)) | |
(g/rotate-y (* (mpos 0) 0.001)) | |
(g/scale 0.1)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment