render: Add gpu-apply/instanced syntax.
authorDavid Thompson <dthompson2@worcester.edu>
Thu, 25 Oct 2018 12:46:53 +0000 (08:46 -0400)
committerDavid Thompson <dthompson2@worcester.edu>
Thu, 25 Oct 2018 12:46:53 +0000 (08:46 -0400)
* chickadee/render.scm (gpu-apply/instanced*, gpu-apply/instanced): New syntax.

chickadee/render.scm

index cdf0315..140ec66 100644 (file)
@@ -43,7 +43,9 @@
             with-texture
             with-projection
             gpu-apply
-            gpu-apply*))
+            gpu-apply*
+            gpu-apply/instanced*
+            gpu-apply/instanced))
 
 (define *current-viewport* null-viewport)
 (define *current-framebuffer* null-framebuffer)
              (set-uniform-value! (shader-uniform shader sname) value)
              (uniform-apply shader rest)))))))
 
-(define-syntax-rule (gpu-apply* shader vertex-array count . uniforms)
+(define-syntax-rule (gpu-prepare shader vertex-array uniforms)
   (begin
     ;; It's important that the framebuffer is set before setting the
     ;; viewport because applying a new viewport will clear the current
     (hash-for-each (lambda (name uniform)
                      (when (eq? 'sampler-2d (uniform-type uniform))
                        (set-uniform-value! uniform (uniform-value uniform))))
-                   (shader-uniforms shader))
+                   (shader-uniforms shader))))
+
+(define-syntax-rule (gpu-apply* shader vertex-array count . uniforms)
+  (begin
+    (gpu-prepare shader vertex-array uniforms)
     (render-vertices vertex-array count)))
 
 (define-syntax-rule (gpu-apply shader vertex-array uniforms ...)
   (gpu-apply* shader vertex-array #f uniforms ...))
+
+(define-syntax-rule (gpu-apply/instanced* shader vertex-array count instances .
+                                          uniforms)
+  (begin
+    (gpu-prepare shader vertex-array uniforms)
+    (render-vertices/instanced vertex-array instances count)))
+
+(define-syntax-rule (gpu-apply/instanced shader vertex-array instances
+                                         uniforms ...)
+  (gpu-apply/instanced* shader vertex-array #f instances uniforms ...))