From 94e892ff8c227c066543fa430dc4605db506944c Mon Sep 17 00:00:00 2001 From: David Thompson Date: Thu, 9 May 2019 16:27:44 -0400 Subject: render: buffer: Don't attempt to map a buffer that is already mapped. * chickadee/render/buffer (map-buffer!): Do nothing if buffer is already mapped to avoid throwing an error. --- chickadee/render/buffer.scm | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/chickadee/render/buffer.scm b/chickadee/render/buffer.scm index 5285be3..04598df 100644 --- a/chickadee/render/buffer.scm +++ b/chickadee/render/buffer.scm @@ -207,16 +207,17 @@ for streaming data to the GPU every frame." the vertex buffer to be updated with new vertex data. The 'unmap-buffer!' procedure must be called to submit the new vertex buffer data back to the GPU." - (let ((target (buffer-target-gl buffer)) - (length (buffer-length buffer)) - (usage (buffer-usage-gl buffer))) - (gpu-state-set! *buffer-state* buffer) - (when (eq? usage 'stream) - ;; 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 usage)) - (let ((ptr (gl-map-buffer target (version-1-5 read-write)))) - (set-buffer-data! buffer (pointer->bytevector ptr length))))) + (unless (buffer-mapped? buffer) ;; Don't map a buffer that is already mapped! + (let ((target (buffer-target-gl buffer)) + (length (buffer-length buffer)) + (usage (buffer-usage-gl buffer))) + (gpu-state-set! *buffer-state* buffer) + (when (eq? usage 'stream) + ;; 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 usage)) + (let ((ptr (gl-map-buffer target (version-1-5 read-write)))) + (set-buffer-data! buffer (pointer->bytevector ptr length)))))) (define (unmap-buffer! buffer) "Return the mapped vertex buffer data for BUFFER to the GPU." -- cgit v1.2.3