diff options
-rw-r--r-- | chickadee/render/buffer.scm | 21 |
1 files 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." |