Skip to content

Commit

Permalink
Optimise cpu particle property upload to minimal set.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinmera committed Oct 5, 2023
1 parent 6cb9475 commit db94bea
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
16 changes: 12 additions & 4 deletions renderer/cpu-particle.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -248,19 +248,27 @@
(when orientation (setf (orientation emitter) orientation))
(when vertex-array (setf (vertex-array emitter) vertex-array))
(with-all-slots-bound (emitter cpu-particle-emitter)
(let ((mat (tmat (tf emitter))))
(let ((mat (tmat (tf emitter)))
(min-prop most-positive-fixnum)
(max-prop 0))
(declare (dynamic-extent mat))
(dotimes (i (min count (length free-list)))
(let ((pos (* 8 live-particles))
(prop (vector-pop free-list)))
(when (< prop min-prop) (setf min-prop prop))
(when (< max-prop prop) (setf max-prop prop))
(%emit-particle particles properties pos prop (vrand (vec 0.5 0.5 0.5))
particle-randomness particle-lifespan-randomness mat
particle-velocity particle-rotation particle-lifespan
particle-size particle-scaling particle-full-color
vertex-data vertex-stride index-data)
(incf live-particles))))
(when (< 0 live-particles)
(update-buffer-data particle-property-buffer T :width (* live-particles (/ 24 4))))))
(incf live-particles)))
(when (< 0 live-particles)
(let ((src (first (sources particle-property-buffer))))
(setf (nth 0 (texture-source-src src)) (truncate min-prop 4))
(setf (nth 3 (texture-source-dst src)) (truncate (- (+ 24 max-prop) min-prop) 4))
(activate particle-property-buffer)
(upload-texture-source src particle-property-buffer))))))

(defmethod clear ((emitter cpu-particle-emitter))
(setf (live-particles emitter) 0)
Expand Down
3 changes: 3 additions & 0 deletions resources/texture.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@
(%gl:get-tex-image (target source) level format type (memory-region-pointer region))
(apply #'save-image region target type :width (width source) :height (height source) :pixel-type type :pixel-format format args))))

(defmethod activate ((source texture))
(gl:bind-texture (target source) (gl-name source)))

;;;; Texture spec wrangling
;; The idea of this is that, in order to maximise sharing of texture resources
;; between independent parts, we need to join (in the lattice sense) two texture
Expand Down

0 comments on commit db94bea

Please sign in to comment.