summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chickadee/graphics.scm12
-rw-r--r--chickadee/graphics/buffer.scm35
-rw-r--r--chickadee/graphics/sprite.scm1
3 files changed, 27 insertions, 21 deletions
diff --git a/chickadee/graphics.scm b/chickadee/graphics.scm
index a41739e..1a2917f 100644
--- a/chickadee/graphics.scm
+++ b/chickadee/graphics.scm
@@ -182,20 +182,20 @@
(set-uniform-value! shader uniform (uniform-value uniform))))
shader)))
-(define-syntax-rule (gpu-apply* shader vertex-array count . uniforms)
+(define-syntax-rule (gpu-apply* shader vertex-array offset count . uniforms)
(begin
(gpu-prepare shader vertex-array uniforms)
- (render-vertices vertex-array count)))
+ (render-vertices vertex-array #:count count #:offset offset)))
(define-syntax-rule (gpu-apply shader vertex-array uniforms ...)
- (gpu-apply* shader vertex-array #f uniforms ...))
+ (gpu-apply* shader vertex-array #f 0 uniforms ...))
-(define-syntax-rule (gpu-apply/instanced* shader vertex-array count instances .
+(define-syntax-rule (gpu-apply/instanced* shader vertex-array offset count instances .
uniforms)
(begin
(gpu-prepare shader vertex-array uniforms)
- (render-vertices/instanced vertex-array instances count)))
+ (render-vertices/instanced vertex-array instances #:count count #:offset offset)))
(define-syntax-rule (gpu-apply/instanced shader vertex-array instances
uniforms ...)
- (gpu-apply/instanced* shader vertex-array #f instances uniforms ...))
+ (gpu-apply/instanced* shader vertex-array #f 0 instances uniforms ...))
diff --git a/chickadee/graphics/buffer.scm b/chickadee/graphics/buffer.scm
index cfb541f..9e5a791 100644
--- a/chickadee/graphics/buffer.scm
+++ b/chickadee/graphics/buffer.scm
@@ -571,7 +571,7 @@ argument may be overridden. The following values are supported:
((index . buffer-view)
(apply-buffer-view buffer-view index)))
attributes)
- (apply-buffer-view indices)
+ (when indices (apply-buffer-view indices))
(set-gpu-vertex-array! (current-gpu) null-vertex-array)
array))
@@ -585,21 +585,26 @@ argument may be overridden. The following values are supported:
('triangle-strip (begin-mode triangle-strip))
('triangle-fan (begin-mode triangle-fan))))
-(define* (render-vertices array #:optional count)
+(define* (render-vertices array #:key count (offset 0))
(set-gpu-vertex-array! (current-gpu) array)
(let ((indices (vertex-array-indices array)))
- (gl-draw-elements (vertex-array-mode-gl array)
- (or count
- (buffer-view-length indices))
- (buffer-view-type-gl indices)
- %null-pointer)))
-
-(define* (render-vertices/instanced array instances #:optional count)
+ (if indices
+ (gl-draw-elements (vertex-array-mode-gl array)
+ (or count
+ (buffer-view-length indices))
+ (buffer-view-type-gl indices)
+ %null-pointer)
+ (gl-draw-arrays (vertex-array-mode-gl array) offset count))))
+
+(define* (render-vertices/instanced array instances #:key count (offset 0))
(set-gpu-vertex-array! (current-gpu) array)
(let ((indices (vertex-array-indices array)))
- (gl-draw-elements-instanced (vertex-array-mode-gl array)
- (or count
- (buffer-view-length indices))
- (buffer-view-type-gl indices)
- %null-pointer
- instances)))
+ (when indices
+ (gl-draw-elements-instanced (vertex-array-mode-gl array)
+ (or count
+ (buffer-view-length indices))
+ (buffer-view-type-gl indices)
+ %null-pointer
+ instances)
+ (gl-draw-arrays-instanced (vertex-array-mode-gl array)
+ offset count instances))))
diff --git a/chickadee/graphics/sprite.scm b/chickadee/graphics/sprite.scm
index 5fc3203..7c36623 100644
--- a/chickadee/graphics/sprite.scm
+++ b/chickadee/graphics/sprite.scm
@@ -460,6 +460,7 @@ void main (void) {
(with-texture 0 (sprite-batch-texture batch)
(gpu-apply* (force batched-sprite-shader)
(sprite-batch-vertex-array batch)
+ 0
(* (sprite-batch-size batch) 6)
#:mvp mvp))))))