Permalink
Browse files

Fix type size calculations and vertex object types

  • Loading branch information...
Shinmera committed Oct 16, 2018
1 parent 4ec5704 commit 044fa11d4c25d1681b4df9240ba35ced1c48f385
Showing with 13 additions and 12 deletions.
  1. +3 −3 geometry.lisp
  2. +3 −3 resources/buffer-object.lisp
  3. +1 −1 resources/vertex-buffer.lisp
  4. +6 −5 toolkit.lisp
View
@@ -184,10 +184,10 @@
;; Construct the buffers and specs
(let* ((vbo (make-instance 'vertex-buffer :buffer-data buffer :buffer-type :array-buffer
:data-usage data-usage :element-type :float
:size (* total-size #.(cffi:foreign-type-size :float))))
:size (* total-size #.(gl-type-size :float))))
(ebo (make-instance 'vertex-buffer :buffer-data (faces mesh) :buffer-type :element-array-buffer
:data-usage data-usage :element-type :uint
:size (* total-size #.(cffi:foreign-type-size :uint))))
:data-usage data-usage :element-type :unsigned-int
:size (* total-size #.(gl-type-size :unsigned-int))))
(specs (loop with stride = (reduce #'+ sizes)
for offset = 0 then (+ offset size)
for size in sizes
@@ -55,9 +55,9 @@
(etypecase data
(single-float :float)
(double-float :double)
(T :integer))))
(T :int))))
(buffer-start (or buffer-start 0))
(buffer-end (+ buffer-start (cffi:foreign-type-size (element-type buffer)))))
(buffer-end (+ buffer-start (gl-type-size (element-type buffer)))))
(cffi:with-foreign-object (data element-type 1)
(setf (cffi:mem-ref data element-type) (gl-coerce data element-type))
(update-buffer-data buffer data :buffer-start buffer-start :buffer-end buffer-end))))
@@ -105,7 +105,7 @@
(defmethod update-buffer-data ((buffer buffer-object) (buffer-data vector) &key (data-start 0) (data-end (length buffer-data)) buffer-start buffer-end element-type)
(let* ((element-type (or element-type (array-element-type buffer-data)))
(element-size (cffi:foreign-type-size element-type))
(element-size (gl-type-size element-type))
(buffer-start (when buffer-start (* buffer-start element-size)))
(buffer-end (when buffer-end (* buffer-end element-size))))
(cond ((static-vector-p buffer-data)
@@ -26,4 +26,4 @@
(let ((buffer-data (buffer-data buffer)))
(when (and (not (size buffer)) (vectorp buffer-data))
(setf (size buffer) (* (length buffer-data)
(cffi:foreign-type-size (element-type buffer)))))))
(gl-type-size (element-type buffer)))))))
View
@@ -370,16 +370,16 @@
(defun gl-type-size (type)
(ecase type
(:boolean 1)
((:ubyte :byte) 8)
((:ushort :short) 16)
((:uint :int) 32)
((:ubyte :unsigned-byte :byte) 8)
((:ushort :unsigned-short :short) 16)
((:uint :unsigned-int :int) 32)
(:fixed 32)
((:uint64 :int64) 64)
(:sizei 32)
(:enum 32)
((:intptr :sizeiptr :sync) #+x86 32 #+x86-64 64)
(:bitfield 32)
(:half 16)
((:half :half-float) 16)
((:float :clampf) 32)
((:double :clampd) 64)))
@@ -589,7 +589,8 @@
:tess-control-shader :tess-evaluation-shader)
(define-enum-check vertex-buffer-element-type
:double :float :int :uint :char)
:byte :unsigned-byte :short :unsigned-short :int :unsigned-int
:half-float :float :double :fixed)
(define-enum-check buffer-object-type
:array-buffer :atomic-counter-buffer

0 comments on commit 044fa11

Please sign in to comment.