diff options
Diffstat (limited to 'sly/render/texture.scm')
-rw-r--r-- | sly/render/texture.scm | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/sly/render/texture.scm b/sly/render/texture.scm index bb7f88c..2e77b0f 100644 --- a/sly/render/texture.scm +++ b/sly/render/texture.scm @@ -31,8 +31,9 @@ #:use-module (gl contrib packed-struct) #:use-module (sdl2 image) #:use-module (sdl2 surface) - #:use-module (sly render color) + #:use-module (sly guardian) #:use-module (sly utils) + #:use-module (sly render color) #:use-module (sly math vector) #:use-module (sly wrappers gl) #:export (make-texture @@ -90,9 +91,7 @@ a texture object (if this texture only represents a region of another texture) or #f. WIDTH and HEIGHT are the texture dimensions in pixels. S1, T1, S2, and T2 are the OpenGL texture coordinates representing the area of the texture that will be rendered." - (let ((texture (%make-texture id parent width height s1 t1 s2 t2))) - (texture-guardian texture) - texture)) + (guard (%make-texture id parent width height s1 t1 s2 t2))) (define (make-texture-region texture x y width height) "Creates new texture region object. TEXTURE is the region's parent @@ -109,13 +108,12 @@ that will be rendered, in pixels." (/ (+ x width) w) (/ (+ y height) h)))) -;; Use a guardian and an after GC hook that ensures that OpenGL -;; textures are deleted when texture objects are GC'd. -(define-guardian texture-guardian - (lambda (texture) - ;; Do not reap texture regions - (unless (texture-region? texture) - (gl-delete-texture (texture-id texture))))) +(define (free-texture texture) + ;; Do not reap texture regions. + (unless (texture-region? texture) + (gl-delete-texture (texture-id texture)))) + +(register-finalizer texture? free-texture) (define* (bytevector->texture pixels width height min-filter mag-filter #:optional (format (pixel-format rgba))) |