summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/api.texi8
-rw-r--r--sdl2/render.scm51
2 files changed, 33 insertions, 26 deletions
diff --git a/doc/api.texi b/doc/api.texi
index ee26d9b..de24b07 100644
--- a/doc/api.texi
+++ b/doc/api.texi
@@ -1155,7 +1155,9 @@ current rendering target of @var{renderer}.
@deffn {Procedure} render-draw-lines renderer points
Draw a series of connected lines from @var{points} on the current
-rendering target of @var{renderer}.
+rendering target of @var{renderer}. Optionally, for best performance,
+@var{points} may instead be a bytevector packed with signed 32 bit
+integers, 2 per point (x and y).
@end deffn
@deffn {Procedure} render-draw-point renderer x y
@@ -1165,7 +1167,9 @@ of @var{renderer}.
@deffn {Procedure} render-draw-points renderer points
Draw a multiple points from @var{points} on the current rendering
-target of @var{renderer}.
+target of @var{renderer}. Optionally, for best performance,
+@var{points} may instead be a bytevector packed with signed 32 bit
+integers, 2 per point (x and y).
@end deffn
@deffn {Procedure} render-draw-rect renderer rectangle
diff --git a/sdl2/render.scm b/sdl2/render.scm
index 2320d71..0f5119c 100644
--- a/sdl2/render.scm
+++ b/sdl2/render.scm
@@ -218,35 +218,38 @@ disable it."
(hashq-set! *pointer-cache* bv ptr)
ptr)))
+(define (build-point-bv points)
+ (let ((bv (make-s32vector (* (length points) 2))))
+ (let loop ((points points)
+ (i 0))
+ (match points
+ (() bv)
+ (((x y) . rest)
+ (s32vector-set! bv (* i 2) x)
+ (s32vector-set! bv (+ (* i 1) 1) y)
+ (loop rest (+ i 1)))))))
+
(define (render-draw-lines renderer points)
"Draw lines connecting POINTS on RENDERER."
- (define (fill-bv bv l n)
- (match l
- (() bv)
- (((x y) . r)
- (s32vector-set! bv n x)
- (s32vector-set! bv (+ n 1) y)
- (fill-bv bv r (+ 2 n)))))
- (let* ((count (length points))
- (bv (fill-bv (make-s32vector (* count 2)) points 0)))
- (ffi:sdl-render-draw-lines (unwrap-renderer renderer)
- (bytevector->pointer bv)
- count)))
+ (if (bytevector? points)
+ (ffi:sdl-render-draw-lines (unwrap-renderer renderer)
+ (bytevector->pointer/cached points)
+ (/ (bytevector-length points) 8))
+ (let ((bv (build-point-bv points)))
+ (ffi:sdl-render-draw-lines (unwrap-renderer renderer)
+ (bytevector->pointer bv)
+ (length points)))))
(define (render-draw-points renderer points)
"Draw POINTS on RENDERER."
- (define (fill-bv bv l n)
- (match l
- (() bv)
- (((x y) . r)
- (s32vector-set! bv n x)
- (s32vector-set! bv (+ n 1) y)
- (fill-bv bv r (+ 2 n)))))
- (let* ((count (length points))
- (bv (fill-bv (make-s32vector (* count 2)) points 0)))
- (ffi:sdl-render-draw-points (unwrap-renderer renderer)
- (bytevector->pointer bv)
- count)))
+ (if (bytevector? points)
+ (ffi:sdl-render-draw-points (unwrap-renderer renderer)
+ (bytevector->pointer/cached points)
+ (/ (bytevector-length points) 8))
+ (let ((bv (build-point-bv points)))
+ (ffi:sdl-render-draw-points (unwrap-renderer renderer)
+ (bytevector->pointer bv)
+ (length points)))))
(define (build-rect-bv rects)
(let* ((count (length rects))