summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2019-05-09 16:27:44 -0400
committerDavid Thompson <dthompson2@worcester.edu>2019-05-09 16:27:44 -0400
commit94e892ff8c227c066543fa430dc4605db506944c (patch)
tree43b7de73cee2caac7373eec99e28c72de233cb63
parent3d59d97515a8d73d8c4ea5ff6aeb8fb617ca7cda (diff)
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.
-rw-r--r--chickadee/render/buffer.scm21
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."