summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2022-07-06 20:25:30 +0200
committerDavid Thompson <dthompson2@worcester.edu>2022-07-06 15:51:36 -0400
commit697a403617b97b4ce333132dae89cb009f6b6e3b (patch)
tree44708086f19b7ebf8e07e328c0b5348a80b277d9
parent3f5fc49d9885ea88a4271d2d074e3e6192bce1ef (diff)
Add SDL_UpdateTexture binding.
-rw-r--r--doc/api.texi8
-rw-r--r--sdl2/bindings.scm3
-rw-r--r--sdl2/render.scm16
3 files changed, 27 insertions, 0 deletions
diff --git a/doc/api.texi b/doc/api.texi
index 204db9e..8e0fe73 100644
--- a/doc/api.texi
+++ b/doc/api.texi
@@ -1242,6 +1242,14 @@ Convert @var{surface} to a texture suitable for @var{renderer}.
Free the memory used by @var{texture}.
@end deffn
+@deffn {Procedure} update-texture texture rect pixels pitch
+Update the subsection of @var{texture} defined by @var{rect} with new
+pixel data in the @var{pixels} bytevector. @var{pitch} represents the
+number of bytes in a row of pixel data, including any padding between
+rows. This is a fairly slow process: Better to use the lock/unlock
+mechanism in streaming textures.
+@end deffn
+
@deffn {Procedure} texture-color-mod texture
Get color mod of @var{texture} as a list of the integers.
@end deffn
diff --git a/sdl2/bindings.scm b/sdl2/bindings.scm
index 5a63636..897a0dc 100644
--- a/sdl2/bindings.scm
+++ b/sdl2/bindings.scm
@@ -327,6 +327,9 @@ RETURN-TYPE and accept arguments of ARG-TYPES."
(define-foreign sdl-set-texture-blend-mode
int "SDL_SetTextureBlendMode" (list '* int))
+(define-foreign sdl-update-texture
+ int "SDL_UpdateTexture" (list '* '* '* int))
+
(define-foreign sdl-set-render-draw-blend-mode
int "SDL_SetRenderDrawBlendMode" (list '* int))
diff --git a/sdl2/render.scm b/sdl2/render.scm
index 5c3b9b0..94e115a 100644
--- a/sdl2/render.scm
+++ b/sdl2/render.scm
@@ -66,6 +66,7 @@
set-texture-alpha-mod!
make-texture
+ update-texture
delete-texture!
surface->texture
query-texture))
@@ -332,6 +333,21 @@ created with 'texture')"
(sdl-error "make-texture" "Failed to create texture")
(wrap-texture ptr))))
+(define (update-texture texture rect pixels pitch)
+ "Update the subsection of TEXTURE defined by RECT with new pixel
+data in the PIXELS bytevector. PITCH represents the number of bytes
+in a row of pixel data, including any padding between rows. This is a
+fairly slow process: Better to use the lock/unlock mechanism in
+streaming textures."
+ (let ((ret (ffi:sdl-update-texture
+ (unwrap-texture texture)
+ ((@@ (sdl2 rect) unwrap-rect) rect)
+ (bytevector->pointer pixels)
+ pitch)))
+ (if (> 0 ret)
+ (sdl-error "update-texture" "failed to update texture")
+ ret)))
+
(define (surface->texture renderer surface)
"Convert SURFACE to a texture suitable for RENDERER."
(let ((ptr (ffi:sdl-create-texture-from-surface