summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2018-09-06 09:27:46 -0400
committerDavid Thompson <dthompson2@worcester.edu>2018-09-06 09:27:46 -0400
commit093e07a69add1c351ba757ec4a4dc006f81b3ac2 (patch)
tree0381e859d03c93899f3d07d8fcf4a21dea791928
parent2162d706d2015b962c7a41a05670a4ea7cd6f0b8 (diff)
render: buffer: Fixed default typed buffer length calculation.
* chickadee/render/buffer.scm (num-elements): New procedure. (make-typed-buffer): Default 'length' to the correct value in elements, not bytes, when a custom length is not specified.
-rw-r--r--chickadee/render/buffer.scm17
1 files changed, 14 insertions, 3 deletions
diff --git a/chickadee/render/buffer.scm b/chickadee/render/buffer.scm
index 4363d22..9726698 100644
--- a/chickadee/render/buffer.scm
+++ b/chickadee/render/buffer.scm
@@ -242,14 +242,25 @@ vertex buffer data back to the GPU."
(* (type-size (typed-buffer-type typed-buffer))
(component-type-size (typed-buffer-component-type typed-buffer)))))
+(define (num-elements byte-length byte-offset type component-type)
+ (inexact->exact
+ (floor
+ (/ (- byte-length byte-offset)
+ (* (component-type-size component-type)
+ (type-size type))))))
+
+
(define* (make-typed-buffer #:key
(name "anonymous")
buffer
- (offset 0)
+ type
component-type
normalized?
- (length (buffer-length buffer))
- type
+ (offset 0)
+ (length (num-elements (buffer-length buffer)
+ offset
+ type
+ component-type))
max
min
sparse)