summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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))))