summaryrefslogtreecommitdiff
path: root/sdl2
diff options
context:
space:
mode:
Diffstat (limited to 'sdl2')
-rw-r--r--sdl2/render.scm51
1 files changed, 27 insertions, 24 deletions
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))