Skip to content

Commit

Permalink
Convenience to create the buffer bindings spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinmera committed Aug 30, 2023
1 parent 02ab58d commit 6518ea7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,8 @@
#:size
#:bindings
#:index-buffer
#:indexed-p)
#:indexed-p
#:compute-buffer-bindings)
;; resources/vertex-buffer.lisp
(:export
#:vertex-buffer
Expand Down
18 changes: 18 additions & 0 deletions resources/vertex-array.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,21 @@
#++
(%gl:draw-arrays (vertex-form array) 0 size)
(gl:bind-vertex-array 0)))

(defun compute-buffer-bindings (buffer fields)
(let* ((fields (loop for field in fields
collect (etypecase field
(cons field)
(integer (list field :float))
(keyword (case field
(:vec2 '(2 :float))
(:vec3 '(3 :float))
(:vec4 '(4 :float))
(T (list 1 field)))))))
(stride (loop for (size type) in fields
sum (* size (gl-type-size type)))))
(loop with offset = 0
for (size type) in fields
for i from 0
collect `(,buffer :index ,i :size ,size :offset ,offset :type ,type :stride ,stride)
do (incf offset (* size (gl-type-size type))))))

0 comments on commit 6518ea7

Please sign in to comment.