🎉 Add first impl of wasm-friendly for Shape data structure

This commit is contained in:
Andrey Antukh 2024-10-24 18:35:57 +02:00
parent e7d7291947
commit 043c23899a
7 changed files with 300 additions and 78 deletions

View file

@ -17,7 +17,8 @@
(defonce ^:dynamic internal-module #js {})
(defonce ^:dynamic internal-gpu-state #js {})
(defn draw-objects [objects zoom vbox]
(defn draw-objects
[objects zoom vbox]
(let [draw-rect (unchecked-get internal-module "_draw_rect")
translate (unchecked-get internal-module "_translate")
reset-canvas (unchecked-get internal-module "_reset_canvas")
@ -35,17 +36,24 @@
(translate gpu-state (- x) (- y)))
(run! (fn [shape]
;; (js/console.log "render-shape" (.-buffer shape))
(let [selrect (dm/get-prop shape :selrect)
x1 (dm/get-prop selrect :x1)
y1 (dm/get-prop selrect :y1)
x2 (dm/get-prop selrect :x2)
y2 (dm/get-prop selrect :y2)]
;; (prn (:id shape) selrect)
(draw-rect gpu-state x1 y1 x2 y2)))
(vals objects))
(flush gpu-state)))))
(def canvas-options
(defn cancel-draw
[sem]
(when (some? sem)
(js/cancelAnimationFrame sem)))
(def ^:private canvas-options
#js {:antialias true
:depth true
:stencil true