From 749adfc4101d11784bf8207c2f6cbe6b8638dd13 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Thu, 6 Sep 2018 09:34:46 -0400 Subject: render: buffer: Fix pointer argument to glVertexAttribPointer. 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 | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/chickadee/render/buffer.scm b/chickadee/render/buffer.scm index 48362f0..686197c 100644 --- a/chickadee/render/buffer.scm +++ b/chickadee/render/buffer.scm @@ -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) -- cgit v1.2.3