render: buffer: Fix pointer argument to glVertexAttribPointer.
authorDavid Thompson <dthompson2@worcester.edu>
Thu, 6 Sep 2018 13:34:46 +0000 (09:34 -0400)
committerDavid Thompson <dthompson2@worcester.edu>
Thu, 6 Sep 2018 13:34:46 +0000 (09:34 -0400)
This one was a doozy.  Took me days to figure out why something wasn't
rendering properly and this was the culprit!  The last argument, the
"pointer" argument, to glVertexAttribPointer is supposed to point to
the byte offset to start reading data from the VBO.  I thought this
meant that I could pass a pointer to an integer that contained the
offset.  WRONG!  The pointer value itself must encode that offset.
You can see in the diff that I knew this code didn't work when the
offset was 0, but somehow a null pointer worked and I just made that
case work while leaving every other offset broken.  The more I know!

* chickadee/render/buffer.scm (apply-typed-buffer): Pass a pointer
  whose address is the byte offset of the buffer, rather than a
  pointer whose dereferenced value is an integer representing the byte
  offset.

chickadee/render/buffer.scm

index 48362f0..686197c 100644 (file)
@@ -353,10 +353,7 @@ be specified for the buffer."
                               (typed-buffer-type-gl typed-buffer)
                               (typed-buffer-normalized? typed-buffer)
                               (typed-buffer-stride typed-buffer)
-                              (let ((offset (typed-buffer-offset typed-buffer)))
-                                (if (zero? offset)
-                                    %null-pointer
-                                    (bytevector->pointer (s32vector offset)))))))
+                              (make-pointer (typed-buffer-offset typed-buffer)))))
 
 ;; TODO: Handle 4-byte alignment rule for the types that need it.
 (define (typed-buffer->vector typed-buffer)