From b06604c6ec1bee068169f632441c93a31f917702 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Thu, 25 Oct 2018 08:46:53 -0400 Subject: render: Add gpu-apply/instanced syntax. * chickadee/render.scm (gpu-apply/instanced*, gpu-apply/instanced): New syntax. --- chickadee/render.scm | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/chickadee/render.scm b/chickadee/render.scm index cdf0315..140ec66 100644 --- a/chickadee/render.scm +++ b/chickadee/render.scm @@ -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) @@ -152,7 +154,7 @@ (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 @@ -170,8 +172,22 @@ (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 ...)) -- cgit v1.2.3