render: sprite: Add draw-sprite-batch* procedure.
authorDavid Thompson <dthompson2@worcester.edu>
Thu, 23 May 2019 02:04:14 +0000 (22:04 -0400)
committerDavid Thompson <dthompson2@worcester.edu>
Thu, 23 May 2019 02:04:14 +0000 (22:04 -0400)
* chickadee/render/sprite.scm (draw-sprite-batch*): New procedure.
  (draw-sprite-batch): Rewrite in terms of 'draw-sprite-batch*'.

chickadee/render/sprite.scm

index bbdc4fa..b6a8232 100644 (file)
@@ -38,6 +38,7 @@
             sprite-batch-clear!
             sprite-batch-add*
             sprite-batch-add!
+            draw-sprite-batch*
             draw-sprite-batch
 
             with-batched-sprites
@@ -406,15 +407,35 @@ void main (void) {
 }
 ")))
 
-(define* (draw-sprite-batch batch #:key (blend-mode 'alpha))
-  "Render the contents of BATCH."
-  (sprite-batch-flush! batch)
-  (with-blend-mode blend-mode
-    (with-texture 0 (sprite-batch-texture batch)
-      (gpu-apply* (force batched-sprite-shader)
-                  (sprite-batch-vertex-array batch)
-                  (* (sprite-batch-size batch) 6)
-                  #:mvp (current-projection)))))
+(define draw-sprite-batch*
+  (let ((mvp (make-null-matrix4)))
+    (lambda* (batch matrix #:key (blend-mode 'alpha))
+      "Render the contents of BATCH."
+      (sprite-batch-flush! batch)
+      (matrix4-mult! mvp matrix (current-projection))
+      (with-blend-mode blend-mode
+        (with-texture 0 (sprite-batch-texture batch)
+          (gpu-apply* (force batched-sprite-shader)
+                      (sprite-batch-vertex-array batch)
+                      (* (sprite-batch-size batch) 6)
+                      #:mvp mvp))))))
+
+(define draw-sprite-batch
+  (let ((matrix (make-null-matrix4)))
+    (lambda* (batch
+              #:key
+              (position %null-vec2)
+              (origin %null-vec2)
+              (scale %default-scale)
+              (rotation 0.0)
+              (blend-mode 'alpha))
+      "Render the contents of BATCH."
+      (matrix4-2d-transform! matrix
+                             #:origin origin
+                             #:position position
+                             #:rotation rotation
+                             #:scale scale)
+      (draw-sprite-batch* batch matrix #:blend-mode blend-mode))))
 
 \f
 ;;;