render: buffer: Allow specifying read/write mode when mapping buffer.
authorDavid Thompson <dthompson2@worcester.edu>
Fri, 10 May 2019 12:29:28 +0000 (08:29 -0400)
committerDavid Thompson <dthompson2@worcester.edu>
Fri, 10 May 2019 12:29:28 +0000 (08:29 -0400)
* chickadee/render/buffer.scm (map-buffer!): Add optional 'mode' argument.

chickadee/render/buffer.scm

index 4d196d9..e784456 100644 (file)
@@ -202,7 +202,7 @@ for streaming data to the GPU every frame."
   "Return #t if buffer data has been mapped from GPU."
   (if (buffer-data buffer) #t #f))
 
-(define (map-buffer! buffer)
+(define* (map-buffer! buffer #:optional (mode 'read-write))
   "Map the memory space for BUFFER from the GPU to the CPU, allowing
 the vertex buffer to be updated with new vertex data.  The
 'unmap-buffer!' procedure must be called to submit the new
@@ -215,7 +215,10 @@ vertex buffer data back to the GPU."
         ;; Orphan the buffer to avoid implicit synchronization.
         ;; See: https://www.opengl.org/wiki/Buffer_Object_Streaming#Buffer_re-specification
         (gl-buffer-data target length %null-pointer (buffer-usage-gl buffer)))
-      (let ((ptr (gl-map-buffer target (version-1-5 read-write))))
+      (let ((ptr (gl-map-buffer target (match mode
+                                         ('read-write (version-1-5 read-write))
+                                         ('read-only (version-1-5 read-only))
+                                         ('write-only (version-1-5 write-only))))))
         (set-buffer-data! buffer (pointer->bytevector ptr length))))))
 
 (define (unmap-buffer! buffer)