Guest User

Untitled

a guest
May 22nd, 2013
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defn update-spectrum [mesh]
  2.   (s/>->> [:p] [:spectrum-data]
  3.        #(if (and (:updated %2) (minim/playing? %1))
  4.           (let
  5.             [data (:data %2)
  6.              l-data (:left data)
  7.              r-data (:right data)
  8.              ; [ VARIANT-1 ] --------------------------------------
  9.              vertices (mapv (fn [x]
  10.                              ; (println "r = " x " len =" (count l-data))
  11.                              [(spec-x x (nth l-data x)) (spec-y x (nth r-data x)) 0]) (range 360)
  12.                            ;[(spec-x x x) (spec-y x (nth r-data x)) (/ (- x) 5)]) (range 1000)
  13.                            )
  14.              ; [ VARIANT-2 ] --------------------------------------
  15. ;             f (fn [x]  [(spec-x x (nth l-data x)) (spec-y x (nth r-data x)) 0])
  16. ;             vertices (reduce (fn [c d] (into c [(spec-x d (nth l-data d)) (spec-y d (nth r-data d)) 0])) [] (range 360))
  17.             ; _ (println vertices)
  18.              ; [ VARIANT-3 ] --------------------------------------
  19. ;            max-x 360
  20. ;            vertices (doall (loop [acc [] x 0]
  21. ;                       (if (< max-x x) acc
  22. ;                         (let
  23. ;                           [v [(spec-x x (nth l-data x)) (spec-y x (nth r-data x)) 0]]
  24. ;                           (recur (concat acc v) (+ x 1))))))
  25.  
  26.              ]
  27.           (update-vertex-buffer! mesh vb-type-position vertices)
  28.             (s/ag!! :spectrum-data (fn [_] {:updated false}))
  29.             (start-spectrum-data-gatherer %1)))))
  30.  
  31.  
  32. (defn update-vertex-buffer! [mesh|geom vb-type lazy-data]
  33.   (let [data (apply concat lazy-data)
  34.         ;_ (println "data =" lazy-data)
  35.         vb (vertex-buffer?? mesh|geom vb-type)
  36.         nio-buffer (.getData vb)]
  37.     (if (> (count data) (.capacity nio-buffer))
  38.       ; if the existing buffer length is shorter than data length, re-create the buffer
  39.       (let
  40.         [mesh (resolve-mesh mesh|geom)
  41.          new-buffer (create-float-buffer data)]
  42.         (vertex-buffer! mesh vb-type 3 new-buffer))
  43.       ; if the existing buffer length is enough for data, re-use the buffer
  44.       (do
  45.         (.rewind nio-buffer)
  46.         (.updateData vb (create-float-buffer data)))))
Advertisement
Add Comment
Please, Sign In to add comment