summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2016-01-02 20:51:06 -0500
committerDavid Thompson <dthompson2@worcester.edu>2016-01-02 20:51:06 -0500
commit4ab013cfe28f815fe4dc28a317edb8ab11306a76 (patch)
tree44f6a44280246ee3d0babaca6a5527a9c6d467c3
parentf00ab87113842bce26f7022f8d074608c8c140df (diff)
render: sprite-batch: Unbind VAO *before* mapping buffers.
* sly/render/sprite-batch.scm (sprite-batch-flush): Don't worry about VAOs here. (with-sprite-batch): Unbind VAO before mapping vertex buffers.
-rw-r--r--sly/render/sprite-batch.scm56
1 files changed, 29 insertions, 27 deletions
diff --git a/sly/render/sprite-batch.scm b/sly/render/sprite-batch.scm
index bd008cc..7caef67 100644
--- a/sly/render/sprite-batch.scm
+++ b/sly/render/sprite-batch.scm
@@ -223,37 +223,39 @@
(define (sprite-batch-flush! batch context)
"Render the contents of BATCH and clear the cache."
(unless (zero? (sprite-batch-size batch))
- (graphics-mesh-excursion context
+ (graphics-texture-excursion context
(lambda (context)
- (set-graphics-mesh! context null-mesh)
- (graphics-texture-excursion context
+ (set-graphics-texture! context (sprite-batch-texture batch))
+ (graphics-model-view-excursion context
(lambda (context)
- (set-graphics-texture! context (sprite-batch-texture batch))
- (graphics-model-view-excursion context
+ (graphics-model-view-mul! context
+ (graphics-projection-transform context))
+ (graphics-uniform-excursion context
+ `((mvp ,(graphics-model-view-transform context))
+ (texture? ,(not (texture-null? (graphics-texture context)))))
(lambda (context)
- (graphics-model-view-mul! context
- (graphics-projection-transform context))
- (graphics-uniform-excursion context
- `((mvp ,(graphics-model-view-transform context))
- (texture? ,(not (texture-null? (graphics-texture context)))))
- (lambda (context)
- (unmap-vertex-buffer! (sprite-batch-index-buffer batch))
- (unmap-vertex-buffer! (sprite-batch-position-buffer batch))
- (unmap-vertex-buffer! (sprite-batch-texture-buffer batch))
+ (unmap-vertex-buffer! (sprite-batch-index-buffer batch))
+ (unmap-vertex-buffer! (sprite-batch-position-buffer batch))
+ (unmap-vertex-buffer! (sprite-batch-texture-buffer batch))
- (glBindVertexArray (sprite-batch-vao batch))
- (glDrawElements (begin-mode triangles)
- ;; 6 indices per sprite.
- (* (sprite-batch-size batch) 6)
- (data-type unsigned-int)
- %null-pointer)
- (glBindVertexArray 0)
+ (glBindVertexArray (sprite-batch-vao batch))
+ (glDrawElements (begin-mode triangles)
+ ;; 6 indices per sprite.
+ (* (sprite-batch-size batch) 6)
+ (data-type unsigned-int)
+ %null-pointer)
+ (glBindVertexArray 0)
- (sprite-batch-reset! batch)))))))))))
+ (sprite-batch-reset! batch)))))))))
(define-syntax-rule (with-sprite-batch batch context body ...)
- (begin
- (sprite-batch-reset! batch)
- (sprite-batch-begin! batch)
- body ...
- (sprite-batch-flush! batch context)))
+ ;; IMPORTANT! We need to make sure that the current VAO is unbound
+ ;; before we start mapping/unmapping vertex buffers. Not doing this
+ ;; created a nasty bug that took me a long time to find.
+ (graphics-mesh-excursion context
+ (lambda (context)
+ (set-graphics-mesh! context null-mesh)
+ (sprite-batch-reset! batch)
+ (sprite-batch-begin! batch)
+ body ...
+ (sprite-batch-flush! batch context))))