Skip to content

Commit

Permalink
[webgl] update color uniform handling and minor other refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Oct 1, 2015
1 parent e47ef62 commit 94b495d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
29 changes: 15 additions & 14 deletions geom-webgl/src/animator.org
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,23 @@
(.-mozRequestAnimationFrame js/window)
(.-msRequestAnimationFrame js/window)
(.-oRequestAnimationFrame js/window)))

(defn now
[] (or
(.now js/performance)
(.webkitNow js/performance)
(.mozNow js/performance)
(.msNow js/performance)
(.oNow js/performance)))

(defn animate
[f & [element]]
[]
(or
(.now js/performance)
(.webkitNow js/performance)
(.mozNow js/performance)
(.msNow js/performance)
(.oNow js/performance)))

(defn animate
[f & [element]]
(let [t0 (.getTime (js/Date.))
t (atom [0 0])
f' (fn animate* []
(if (f (reset! t [(* (- (.getTime (js/Date.)) t0) 0.001) (inc (@t 1))]))
(if element
t (volatile! [0 0])
f' (fn animate* []
(if (f (vreset! t [(* (- (.getTime (js/Date.)) t0) 0.001) (inc (@t 1))]))
(if element
(animframe-provider animate* element)
(animframe-provider animate*))))]
(f')))
Expand Down
10 changes: 5 additions & 5 deletions geom-webgl/src/demo.org
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,10 @@ rotation / transformation).
(gl/as-webgl-buffer-spec {})
(buf/make-attribute-buffers-in-spec gl gl/static-draw)
(assoc :shader shader :uniforms uniforms))
state (atom {:mpos (g/centroid view-rect) :update-ray true})
update-pos #(swap! state assoc
:mpos (vec2 (.-clientX %) (.-clientY %))
:update-ray true)]
state (volatile! {:mpos (g/centroid view-rect) :update-ray true})
update-pos #(vswap! state assoc
:mpos (vec2 (.-clientX %) (.-clientY %))
:update-ray true)]
(.addEventListener js/window "mousemove" update-pos)
(.addEventListener js/window "touchmove" #(do (.preventDefault %) (update-pos (aget (.-touches %) 0))))
(anim/animate
Expand All @@ -413,7 +413,7 @@ rotation / transformation).
(let [p (-> (vec3 (:mpos @state) 0)
(mat/unproject-point (g/invert (g/* (:proj uniforms) view)) view-rect)
(raycast eye ground back))]
(swap! state assoc :isec p :update-ray false) p)
(vswap! state assoc :isec p :update-ray false) p)
(:isec @state))]
(gl/set-viewport gl view-rect)
(gl/clear-color-buffer gl 0.52 0.5 0.5 1)
Expand Down
4 changes: 2 additions & 2 deletions geom-webgl/src/shaders.org
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Special cases:
(= :vec3 type)
(fn [x]
(if (number? x)
(.call setter gl loc (u-cast (subvec (color/int->rgba x) 0 3)))
(.call setter gl loc (-> x col/int24 col/as-rgba col/unwrap (subvec 0 3) u-cast))
(.call setter gl loc (if (arrays/typed-array? x) x (u-cast x)))))
:else
(fn [x]
Expand Down Expand Up @@ -350,7 +350,7 @@ Currently the following options are supported:
[thi.ng.geom.webgl.core :as gl]
[thi.ng.geom.webgl.utils :as glu]
[thi.ng.typedarrays.core :as arrays]
[thi.ng.color.core :as color]
[thi.ng.color.core :as col]
[thi.ng.common.error :as err]
[clojure.string :as str]))

Expand Down

0 comments on commit 94b495d

Please sign in to comment.