summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2021-01-20 08:23:29 -0500
committerDavid Thompson <dthompson2@worcester.edu>2021-01-20 08:23:29 -0500
commitdadc2fbd5c65ce3cd6bd666ba928e4dcd89a4c8f (patch)
treec69dc4222da4005cf2b156ef8c6bdce7c7d0206d
parentb6b1699c1ff8661d49ff2b99256b59754bc7784a (diff)
graphics: gpu: Move guardian to <gpu> structure.
-rw-r--r--chickadee.scm2
-rw-r--r--chickadee/graphics/gpu.scm40
2 files changed, 20 insertions, 22 deletions
diff --git a/chickadee.scm b/chickadee.scm
index 611674a..3b6d6fd 100644
--- a/chickadee.scm
+++ b/chickadee.scm
@@ -363,7 +363,7 @@ border is disabled, otherwise it is enabled.")
;; that were queued to play this frame start playing immediately.
(update-audio)
;; Free any GPU resources that have been GC'd.
- (gpu-reap!))
+ (gpu-reap! gpu))
(define (render-sdl-opengl alpha)
(with-viewport default-viewport
(clear-screen)
diff --git a/chickadee/graphics/gpu.scm b/chickadee/graphics/gpu.scm
index 7783fe5..c5d4702 100644
--- a/chickadee/graphics/gpu.scm
+++ b/chickadee/graphics/gpu.scm
@@ -80,27 +80,6 @@
((gpu-state-bind state) new-value)
(%gpu-state-set! state new-value)))
-;;;
-;;; GPU finalizers
-;;;
-
-(define-generic gpu-finalize)
-
-(define *gpu-guardian* (make-guardian))
-
-(define (gpu-guard obj)
- "Protect OBJ for the garbage collector until OBJ has been deleted
-from the GPU's memory."
- (*gpu-guardian* obj)
- obj)
-
-(define (gpu-reap!)
- "Delete all GPU objects that are no longer being referenced."
- (let loop ((obj (*gpu-guardian*)))
- (when obj
- (gpu-finalize obj)
- (loop (*gpu-guardian*)))))
-
;;;
;;; GPU
@@ -110,6 +89,7 @@ from the GPU's memory."
(%make-gpu gl-context
gl-version
glsl-version
+ guardian
max-texture-size
blend-mode
polygon-mode
@@ -128,6 +108,7 @@ from the GPU's memory."
(gl-context gpu-gl-context)
(gl-version gpu-gl-version)
(glsl-version gpu-glsl-version)
+ (guardian gpu-guardian)
(max-texture-size gpu-max-texture-size)
(blend-mode %gpu-blend-mode)
(polygon-mode %gpu-polygon-mode)
@@ -145,6 +126,22 @@ from the GPU's memory."
(define current-gpu (make-parameter #f))
+(define-generic gpu-finalize)
+
+(define (gpu-guard obj)
+ "Protect OBJ for the garbage collector until OBJ has been deleted
+from the GPU's memory."
+ ((gpu-guardian (current-gpu)) obj)
+ obj)
+
+(define (gpu-reap! gpu)
+ "Delete all GPU objects that are no longer being referenced."
+ (let ((guardian (gpu-guardian gpu)))
+ (let loop ((obj (guardian)))
+ (when obj
+ (gpu-finalize obj)
+ (loop (guardian))))))
+
(define (max-texture-size)
(let ((bv (make-s32vector 1)))
(gl-get-integer-v (get-p-name max-texture-size)
@@ -185,6 +182,7 @@ from the GPU's memory."
(%make-gpu gl-context
gl-version
glsl-version
+ (make-guardian)
(max-texture-size)
(make-gpu-state (module-ref blend-module 'apply-blend-mode)
'replace)