From dd1ccc8afc8ec0411ac636f542fd4bb8d4d242af Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 10 May 2019 08:29:28 -0400 Subject: render: buffer: Allow specifying read/write mode when mapping buffer. * chickadee/render/buffer.scm (map-buffer!): Add optional 'mode' argument. --- chickadee/render/buffer.scm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/chickadee/render/buffer.scm b/chickadee/render/buffer.scm index 4d196d9..e784456 100644 --- a/chickadee/render/buffer.scm +++ b/chickadee/render/buffer.scm @@ -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) -- cgit v1.2.3